Skip to content

Commit

Permalink
add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
len0rd committed Jun 18, 2019
1 parent 270c1a3 commit 2b0e131
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
1 change: 1 addition & 0 deletions scripts/InteropClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def post_telemetry(self, telemetry):
json_params = json.dumps(params)
headers = {'Cookie': self.GLOBALCOOKIE, "Content-Type":"application/json"}
response = self.send_request('POST', '/api/telemetry', json_params, headers)
return response

def post_target(self, target):
params = target.dict_out()
Expand Down
69 changes: 52 additions & 17 deletions scripts/test/interop_client_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import math
from InteropClient import InteropClient
from ClientObjects import Target
from ClientObjects import Target, Telemetry

class TestServerConnection(unittest.TestCase):
def test(self):
Expand All @@ -14,36 +15,70 @@ def test(self):
self.assertTrue(client.is_connected())

class TestPostTarget(unittest.TestCase):
def testManual(self):
# see how it works with all lower values
manualTarget = Target('STANDARD', 39.1234, -111.5555, 'NE', 'CIRCLE','BLUE', 'C', 'BLACK', None, False)

def verifyGoodTargetPost(self, target): #TODO: VALID??
client = InteropClient('localhost', sleep_sec=0.0)
self.assertIsNotNone(client)
self.assertTrue(client.is_connected())

raised = False
result = -1
try:
result = client.post_target(manualTarget)
result = client.post_target(target)
except:
raised = True
self.assertFalse(raised)
self.assertGreater(result, -1)

def testAuto(self):
# see how it works with all caps values
def testManualStandard(self):
"""
submit standard manual target
"""
manualTarget = Target('STANDARD', 39.1234, -111.5555, 'NE', 'CIRCLE','BLUE', 'C', 'BLACK', None, False)
self.verifyGoodTargetPost(manualTarget)


def testAutoStandard(self):
"""
submit standard autonomous target
"""
autoTarget = Target('STANDARD', 40.1111, -111.6666, 'NE', 'CIRCLE','PURPLE', 'A', 'BLACK', None, True)
self.verifyGoodTargetPost(autoTarget)

def testManualEmergent(self):
"""
submit manual emergent target
"""
targ = Target('EMERGENT', 40.222, -111.6778, '', '','', '', '', 'A description of an emergent target', False)
self.verifyGoodTargetPost(targ)

def testAutoEmergent(self):
"""
submit autonomous emergent target (will this ever actually happen??)
"""
targ = Target('EMERGENT', 40.222, -111.6778, '', '','', '', '', 'A description of an emergent target but autonomous', True)
self.verifyGoodTargetPost(targ)

def testManualOffAxis(self):
"""
submit manual off_axis target
"""
targ = Target('OFF_AXIS', 42.333, -111.6778, 'W', 'SEMICIRCLE','BROWN', 'F', 'YELLOW', None, False)
self.verifyGoodTargetPost(targ)

def testAutoOffAxis(self):
"""
submit autonomous emergent target
"""
targ = Target('OFF_AXIS', 41.222, -113.6778, 'SW', 'SQUARE','BLUE', 'X', 'WHITE', None, True)
self.verifyGoodTargetPost(targ)

class TestPostTelem(unittest.TestCase):
def testPost(self):
telem = Telemetry(40.111, -111.8888, 1234.1, .5 * math.pi)
client = InteropClient('localhost', sleep_sec=0.0)
self.assertIsNotNone(client)
self.assertTrue(client.is_connected())

raised = False
result = -1
try:
result = client.post_target(autoTarget)
except:
raised = True
self.assertFalse(raised)
self.assertGreater(result, -1)

resp = client.post_telemetry(telem)
self.assertIsNotNone(resp)
self.assertEqual(resp.status_code, 200) # verify good response

0 comments on commit 2b0e131

Please sign in to comment.