Example #1
0
 def test_join_new_session(self):
     """
     a requests is assigned a newly created session
     """
     db = FakeBackend()
     controller = ConnectFourController(db)
     session = C4Session(id='blablabla', board='', player_1='joe')
     db.set_backend(None)
     resp = controller.join(None, {'username': ['moe']}, None)
     self.assertEqual(db.saved[0].player_1, 'moe')
     self.assertEqual(201, resp.status_code)
     # since the session is new, a new id is assigned, so we have to assert on individual fields
     self.assertEqual('Session created', resp.content['msg'])
     self.assertEqual(1, resp.content['player'])
     # since the uuid is random, we can't assert on its value.
     # however, and auto generated id should be an uuid, which is a 36 characters long string
     self.assertEqual(36, len(resp.content['session']))
Example #2
0
 def test_join_previous_session_same_user(self):
     """
     join with a request made with a user that already has an open session
     """
     db = FakeBackend()
     controller = ConnectFourController(db)
     session = C4Session(id='123', player_1='joe')
     db.set_backend([session])
     resp = controller.join(None, {'username': ['joe']}, None)
     self.assertEqual(len(db.saved), 0)
     self.assertEqual(200, resp.status_code)
     self.assertEqual(
         {
             'msg': 'Existing Session found',
             'session': '123',
             'player': 1
         }, resp.content)
Example #3
0
 def test_join_previous_session(self):
     """
     a request is assigned a previously created session that was open
     """
     db = FakeBackend()
     controller = ConnectFourController(db)
     session = C4Session(id='blablabla', board='', player_1='joe')
     db.set_backend([session])
     resp = controller.join(None, {'username': ['moe']}, None)
     self.assertEqual(db.saved[0].player_2, 'moe')
     self.assertEqual(209, resp.status_code)
     self.assertEqual(
         {
             'msg': 'Joined session',
             'session': 'blablabla',
             'player': 2
         }, resp.content)