Skip to content

Commit

Permalink
Merge pull request #391 from nabaztag2018/w23-add-more-tests
Browse files Browse the repository at this point in the history
Add interactive mode exit tests
  • Loading branch information
nabaztag2018 authored Jun 13, 2022
2 parents 1f39f2c + dc6c482 commit d575cec
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions nabd/tests/nabd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,66 @@ def test_shutdown_api_method(self):
finally:
s1.close()

def test_interactive_close_socket(self):
s1 = self.service_socket()
s2 = self.service_socket()
try:
packet = s1.readline() # state packet
packet = s2.readline() # state packet
s1.write(b'{"type":"mode","mode":"interactive"}\r\n')
packet = s1.readline() # response packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "response")
self.assertEqual(packet_j["status"], "ok")
packet = s1.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "interactive")
packet = s2.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "interactive")
s1.close()
packet = s2.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "idle")
finally:
s1.close()
s2.close()

def test_interactive_idle(self):
s1 = self.service_socket()
s2 = self.service_socket()
try:
packet = s1.readline() # state packet
packet = s2.readline() # state packet
s1.write(b'{"type":"mode","mode":"interactive"}\r\n')
packet = s1.readline() # response packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "response")
self.assertEqual(packet_j["status"], "ok")
packet = s1.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "interactive")
packet = s2.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "interactive")
s1.write(b'{"type":"mode","mode":"idle"}\r\n')
packet = s1.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "idle")
packet = s2.readline() # new state packet
packet_j = json.loads(packet.decode("utf8"))
self.assertEqual(packet_j["type"], "state")
self.assertEqual(packet_j["state"], "idle")
finally:
s1.close()
s2.close()


@pytest.mark.django_db(transaction=True)
class TestRfid(TestNabdBase):
Expand Down

0 comments on commit d575cec

Please sign in to comment.