forked from marcoschwartz/aREST
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test for the CC3000 chip based on llibcurl and pyCurl
- Loading branch information
1 parent
4dd8b72
commit 34c909e
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Test for the aREST library using the CC3000 chip | ||
|
||
# Imports | ||
import pycurl | ||
import time | ||
import json | ||
import unittest | ||
import StringIO | ||
|
||
# Target | ||
target = 'arduino.local' | ||
|
||
# Function to make cURL call | ||
def curl_call(target, command): | ||
|
||
buf = StringIO.StringIO() | ||
|
||
c = pycurl.Curl() | ||
c.setopt(c.URL, target + command) | ||
c.setopt(c.WRITEFUNCTION, buf.write) | ||
c.perform() | ||
|
||
return buf.getvalue() | ||
|
||
# Test | ||
class TestSequenceFunctions(unittest.TestCase): | ||
|
||
# Mode basic test | ||
def test_mode(self): | ||
|
||
# Input | ||
answer = json.loads(curl_call(target,"/mode/6/i")) | ||
self.assertEqual(answer['message'],"Setting pin D6 to input") | ||
|
||
# Output | ||
answer = json.loads(curl_call(target,"/mode/6/o")) | ||
self.assertEqual(answer['message'],"Setting pin D6 to output") | ||
|
||
# Digital write basic test | ||
def test_digital_write(self): | ||
|
||
# HIGH | ||
answer = json.loads(curl_call(target,"/digital/6/1")) | ||
self.assertEqual(answer['message'],"Pin D6 set to 1") | ||
|
||
# LOW | ||
answer = json.loads(curl_call(target,"/digital/6/0")) | ||
self.assertEqual(answer['message'],"Pin D6 set to 0") | ||
|
||
# Digital read basic test | ||
def test_digital_read(self): | ||
|
||
# Set to LOW | ||
answer = json.loads(curl_call(target,"/digital/6/0")) | ||
|
||
# Read | ||
answer = json.loads(curl_call(target,"/digital/6")) | ||
self.assertEqual(answer['return_value'],0) | ||
|
||
# Analog write basic test | ||
def test_analog_write(self): | ||
|
||
# Set to 100 | ||
answer = json.loads(curl_call(target,"/analog/6/100")) | ||
self.assertEqual(answer['message'],"Pin D6 set to 100") | ||
|
||
# Set to 0 | ||
answer = json.loads(curl_call(target,"/analog/6/0")) | ||
self.assertEqual(answer['message'],"Pin D6 set to 0") | ||
|
||
# Analog read basic test | ||
def test_analog_read(self): | ||
|
||
# Read | ||
answer = json.loads(curl_call(target,"/analog/6")) | ||
self.assertGreaterEqual(answer['return_value'],0) | ||
self.assertLessEqual(answer['return_value'],1023) | ||
|
||
# Digital write + check test | ||
def test_digital_check(self): | ||
|
||
# Set to Output | ||
answer = json.loads(curl_call(target,"/mode/6/o")) | ||
|
||
# Set to HIGH | ||
answer = json.loads(curl_call(target,"/digital/6/1")) | ||
|
||
# Read | ||
answer = json.loads(curl_call(target,"/digital/6")) | ||
self.assertEqual(answer['return_value'],1) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |