def setUp(self): super(RequestTestsBase, self).setUp() create_test_map() self.account_1 = self.accounts_factory.create_account() self.account_2 = self.accounts_factory.create_account() self.client = client.Client() self.game_info_url_1 = game_info_url(account_id=self.account_1.id) self.game_info_url_2 = game_info_url(account_id=self.account_2.id) self.game_info_url_no_id = game_info_url() self.request_login(self.account_1.email)
def setUp(self): super(RequestTestsBase, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111') self.account_1_id = account_id self.account_1 = AccountPrototype.get_by_id(account_id) result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111') self.account_2_id = account_id self.account_2 = AccountPrototype.get_by_id(account_id) self.client = client.Client() self.game_info_url_1 = game_info_url(account_id=self.account_1.id) self.game_info_url_2 = game_info_url(account_id=self.account_2.id) self.game_info_url_no_id = game_info_url() self.request_login('*****@*****.**')
def test_client_turns_passed_to_data_receiver(self): with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.cached_ui_info_for_hero', mock.Mock(return_value={'actual_on_turn': 666})) as cached_ui_info_for_hero: self.check_ajax_ok(self.request_ajax_json(game_info_url(client_turns=[1, 2, 3 ,4]))) self.assertEqual(cached_ui_info_for_hero.call_args_list, [mock.call(account_id=self.account_1.id, recache_if_required=True, patch_turns=[1, 2, 3, 4], for_last_turn=False)])
def test_client_turns_passed_to_data_receiver(self): with mock.patch('the_tale.game.heroes.objects.Hero.cached_ui_info_for_hero', mock.Mock(return_value={'actual_on_turn': 666})) as cached_ui_info_for_hero: self.check_ajax_ok(self.request_ajax_json(game_info_url(client_turns=[1, 2, 3 ,4]))) self.assertEqual(cached_ui_info_for_hero.call_args_list, [mock.call(account_id=self.account_1.id, recache_if_required=True, patch_turns=[1, 2, 3, 4], for_last_turn=False)])
def test_client_turns(self): self.check_ajax_error(self.request_ajax_json(game_info_url(client_turns=['dds'])), 'client_turns.wrong_format') self.check_ajax_error(self.request_ajax_json(game_info_url(client_turns=['1', ''])), 'client_turns.wrong_format') self.check_ajax_ok(self.request_ajax_json(game_info_url(client_turns=['1']))) self.check_ajax_ok(self.request_ajax_json(game_info_url(client_turns=['1, 2, 3 ,4']))) self.check_ajax_ok(self.request_ajax_json(game_info_url(client_turns=[1, 2, 3 ,4]))) self.check_ajax_ok(self.request_ajax_json(game_info_url(client_turns=['1',' 2',' 3 ','4'])))
def test_wrong_account_id(self): response = self.request_ajax_json(game_info_url(account_id='sdsd')) self.check_ajax_error(response, 'account.wrong_format')
def test_account_not_exists(self): response = self.request_ajax_json(game_info_url(account_id=666)) self.check_ajax_error(response, 'account.wrong_value')
def game_info_url(account=None, client_turns=None): return jinja2.Markup( logic.game_info_url( account_id=account.id if account is not None else None, client_turns=client_turns))
def game_info_url(account=None, client_turns=None): return jinja2.Markup(logic.game_info_url(account_id=account.id if account is not None else None, client_turns=client_turns))