Skip to content

Commit

Permalink
added test for the CC3000 chip based on llibcurl and pyCurl
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoschwartz committed May 11, 2014
1 parent 4dd8b72 commit 34c909e
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions test/cc3000_test.py
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()

0 comments on commit 34c909e

Please sign in to comment.