Ejemplo n.º 1
0
 def test_update_returns_error_from_invalid_email(self):
     player_id = self.player.get_id()
     update_url = '/players/{}'.format(player_id)
     email = get_incremental_email(player_id).replace('.', '')
     player_data = {
         'email': email
     }
     response = self.put(update_url, data=player_data)
     self.assertEqual(422, response.status_code)
     errors = json.loads(response.data)
     self.assertIsNotNone(errors.get('errors'))
     self.assertIsNotNone(errors.get('errors').get('email'))
     self.assertIsNotNone(errors.get('inputs'))
     self.assertEqual(player_id, errors.get('inputs').get('id'))
     self.assertEqual('', errors.get('inputs').get('username'))
     self.assertIsNone(errors.get('inputs').get('password'))
     self.assertEqual(email, errors.get('inputs').get('email'))
     self.assertEqual('', errors.get('inputs').get('avatar_url'))
Ejemplo n.º 2
0
 def test_update_returns_error_from_email_not_unique(self):
     player_id = self.player.get_id()
     player_number = 1 if player_id == 2 else 2
     update_url = '/players/{}'.format(player_id)
     email = get_incremental_email(player_number)
     player_data = {
         'email': email
     }
     response = self.put(update_url, data=player_data)
     self.assertEqual(422, response.status_code)
     errors = json.loads(response.data)
     self.assertIsNotNone(errors.get('errors'))
     self.assertIsNotNone(errors.get('errors').get('IntegrityError'))
     self.assertIsNotNone(errors.get('inputs'))
     self.assertEqual(player_id, errors.get('inputs').get('id'))
     self.assertEqual('', errors.get('inputs').get('username'))
     self.assertIsNone(errors.get('inputs').get('password'))
     self.assertEqual(email, errors.get('inputs').get('email'))
     self.assertEqual('', errors.get('inputs').get('avatar_url'))
Ejemplo n.º 3
0
 def test_create_returns_error_from_missing_username(self):
     player_id = self.NUM_PLAYERS + 1
     create_url = '/players'
     email = get_incremental_email(player_id)
     player_data = {
         'password': self.PLAYER_PASSWORD,
         'confirm': self.PLAYER_PASSWORD,
         'email': email
     }
     response = self.post(create_url, data=player_data)
     self.assertEqual(422, response.status_code)
     errors = json.loads(response.data)
     self.assertIsNotNone(errors.get('errors'))
     self.assertIsNotNone(errors.get('errors').get('username'))
     self.assertIsNotNone(errors.get('inputs'))
     self.assertEqual('', errors.get('inputs').get('username'))
     self.assertIsNone(errors.get('inputs').get('password'))
     self.assertIsNone(errors.get('inputs').get('confirm'))
     self.assertEqual(email, errors.get('inputs').get('email'))
     self.assertEqual('', errors.get('inputs').get('avatar_url'))
Ejemplo n.º 4
0
 def test_create_returns_error_from_email_not_unique(self):
     player_id = self.NUM_PLAYERS + 1
     player_number = 1 if self.player.get_id() == 2 else 2
     create_url = '/players'
     username = get_incremental_username(player_id)
     email = get_incremental_email(player_number)
     player_data = {
         'username': username,
         'password': self.PLAYER_PASSWORD,
         'confirm': self.PLAYER_PASSWORD,
         'email': email
     }
     response = self.post(create_url, data=player_data)
     self.assertEqual(422, response.status_code)
     errors = json.loads(response.data)
     self.assertIsNotNone(errors.get('errors'))
     self.assertIsNotNone(errors.get('errors').get('IntegrityError'))
     self.assertIsNotNone(errors.get('inputs'))
     self.assertEqual(username, errors.get('inputs').get('username'))
     self.assertIsNone(errors.get('inputs').get('password'))
     self.assertIsNone(errors.get('inputs').get('confirm'))
     self.assertEqual(email, errors.get('inputs').get('email'))
     self.assertEqual('', errors.get('inputs').get('avatar_url'))
Ejemplo n.º 5
0
    def test_update_updates_player(self):
        update_url = '/players/{}'.format(self.player.get_id())
        player_number = self.player.get_id() * 100
        username = get_incremental_username(player_number)
        email = get_incremental_email(player_number)
        password = '******'.format(player_number)
        avatar_url = get_incremental_avatar_url(player_number)
        player_data = {
            'username': username,
            'password': password,
            'confirm': password,
            'email': email,
            'avatar_url': avatar_url,
            'is_active': False
        }
        response = self.put(update_url, data=player_data)
        self.assertEqual(200, response.status_code)
        player = json.loads(response.data)
        self.assertIsNotNone(player.get('id'))
        self.assertIsNotNone(player.get('date_created'))
        self.assertIsNotNone(player.get('date_modified'))
        self.assertEqual(username, player.get('username'))
        self.assertEqual(email, player.get('email'))
        self.assertIsNone(player.get('password'))
        self.assertEqual(avatar_url, player.get('avatar_url'))
        self.assertEqual(False, player.get('is_active'))

        # Make sure the player was actually updated in the database
        saved_player = PlayersService.get_instance().get(int(player.get('id')))
        self.assertEqual(saved_player.get_id(), player.get('id'))
        self.assertEqual(Player.dump_datetime(saved_player.get_date_created()), player.get('date_created'))
        self.assertEqual(Player.dump_datetime(saved_player.get_date_modified()), player.get('date_modified'))
        self.assertEqual(saved_player.get_username(), player.get('username'))
        self.assertEqual(saved_player.get_email(), player.get('email'))
        self.assertEqual(saved_player.get_avatar_url(), player.get('avatar_url'))
        self.assertEqual(saved_player.get_is_active(), player.get('is_active'))
Ejemplo n.º 6
0
    def test_create_returns_created_status(self):
        player_id = self.NUM_PLAYERS + 1
        create_url = '/players'
        username = get_incremental_username(player_id)
        email = get_incremental_email(player_id)
        avatar_url = get_incremental_avatar_url(player_id)
        player_data = {
            'username': username,
            'password': self.PLAYER_PASSWORD,
            'confirm': self.PLAYER_PASSWORD,
            'email': email,
            'avatar_url': avatar_url
        }
        response = self.post(create_url, data=player_data)
        self.assertEqual(201, response.status_code)
        player = json.loads(response.data)
        self.assertIsNotNone(player.get('id'))
        self.assertIsNotNone(player.get('date_created'))
        self.assertIsNotNone(player.get('date_modified'))
        self.assertEqual(username, player.get('username'))
        self.assertEqual(email, player.get('email'))
        self.assertIsNone(player.get('password'))
        self.assertEqual(avatar_url, player.get('avatar_url'))
        self.assertEqual(True, player.get('is_active'))
        self.assertIsNotNone(player.get('auth_token'))

        # Make sure the player was actually saved to the database
        saved_player = PlayersService.get_instance().get(int(player.get('id')))
        self.assertEqual(saved_player.get_id(), player.get('id'))
        self.assertEqual(Player.dump_datetime(saved_player.get_date_created()), player.get('date_created'))
        self.assertEqual(Player.dump_datetime(saved_player.get_date_modified()), player.get('date_modified'))
        self.assertEqual(saved_player.get_username(), player.get('username'))
        self.assertEqual(saved_player.get_email(), player.get('email'))
        self.assertEqual(saved_player.get_avatar_url(), player.get('avatar_url'))
        self.assertEqual(saved_player.get_is_active(), player.get('is_active'))
        self.assertEqual(saved_player.get_auth_token(), player.get('auth_token'))
Ejemplo n.º 7
0
 def test_create_returns_error_from_invalid_avatar_url(self):
     player_id = self.NUM_PLAYERS + 1
     create_url = '/players'
     username = get_incremental_username(player_id)
     email = get_incremental_email(player_id)
     avatar_url = get_incremental_avatar_url(player_id).replace('.', '')
     player_data = {
         'username': username,
         'password': self.PLAYER_PASSWORD,
         'confirm': self.PLAYER_PASSWORD,
         'email': email,
         'avatar_url': avatar_url
     }
     response = self.post(create_url, data=player_data)
     self.assertEqual(422, response.status_code)
     errors = json.loads(response.data)
     self.assertIsNotNone(errors.get('errors'))
     self.assertIsNotNone(errors.get('errors').get('avatar_url'))
     self.assertIsNotNone(errors.get('inputs'))
     self.assertEqual(username, errors.get('inputs').get('username'))
     self.assertIsNone(errors.get('inputs').get('password'))
     self.assertIsNone(errors.get('inputs').get('confirm'))
     self.assertEqual(email, errors.get('inputs').get('email'))
     self.assertEqual(avatar_url, errors.get('inputs').get('avatar_url'))