def test_use(self): for direction in (-1, 1): tt_api_impacts.debug_clear_service() card = self.CARD.effect.create_card(type=self.CARD, available_for_auction=True, direction=direction) result, step, postsave_actions = self.CARD.effect.use( **self.use_attributes(hero=self.hero, storage=self.storage, value=self.place_1.id, card=card)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) impacts = politic_power_logic.get_last_power_impacts(limit=100) self.assertEqual(len(impacts), 1) self.assertEqual(impacts[0].amount, direction * self.CARD.effect.modificator) self.assertTrue(impacts[0].type.is_INNER_CIRCLE) self.assertTrue(impacts[0].target_type.is_PLACE) self.assertEqual(impacts[0].target_id, self.place_1.id) self.assertTrue(impacts[0].actor_type.is_HERO) self.assertEqual(impacts[0].actor_id, self.hero.id)
def setUp(self): super(BaseTestRequests, self).setUp() self.place1, self.place2, self.place3 = create_test_map() self.account1 = self.accounts_factory.create_account() # self.account1.prolong_premium(30) self.account1._model.created_at -= datetime.timedelta(days=bills_settings.MINIMUM_BILL_OWNER_AGE) self.account1.save() self.account2 = self.accounts_factory.create_account() # self.account2.prolong_premium(30) self.account2._model.created_at -= datetime.timedelta(days=bills_settings.MINIMUM_BILL_OWNER_AGE) self.account2.save() self.client = client.Client() self.request_login(self.account1.email) from the_tale.forum.models import Category, SubCategory forum_category = Category.objects.create(caption='Category-1', slug='category-1') SubCategory.objects.create(caption=bills_settings.FORUM_CATEGORY_UID + '-caption', uid=bills_settings.FORUM_CATEGORY_UID, category=forum_category) tt_api_impacts.debug_clear_service()
def test_can_not_vote(self): tt_api_impacts.debug_clear_service() heroes_logic.save_hero(self.hero) self.check_ajax_error(self.client.post(url('game:bills:vote', self.bill.id, type=VOTE_TYPE.FOR.value), {}), 'bills.vote.can_not_vote') self.check_bill_votes(self.bill.id, 1, 0)
def setUp(self): super().setUp() tt_api_impacts.debug_clear_service() self.storage = TestPowerStorage(targets_ids=[10, 20, 30, 40, 50]) logic.add_power_impacts([ tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=1, person_id=10, amount=100), tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=2, person_id=20, amount=200), tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE, hero_id=1, person_id=30, amount=-300), tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=3, person_id=40, amount=-400), tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE, hero_id=4, person_id=50, amount=500) ])
def setUp(self): super().setUp() tt_api_impacts.debug_clear_service() logic.add_power_impacts([ tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=1, person_id=10, amount=100), tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE, hero_id=2, person_id=20, amount=200), tt_api_impacts.PowerImpact.hero_2_place( type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE, hero_id=1, place_id=30, amount=300), tt_api_impacts.PowerImpact.hero_2_place( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=3, place_id=40, amount=400) ])
def setUp(self): super().setUp() self.place_1, self.place_2, self.place_3 = create_test_map() tt_api_impacts.debug_clear_service() self.job = jobs_logic.create_job(logic.PlaceJob)
def setUp(self): super().setUp() self.places = game_logic.create_test_map() self.persons = [place.persons for place in self.places] tt_api_impacts.debug_clear_service()
def setUp(self): super().setUp() self.place_1, self.place_2, self.place_3 = game_logic.create_test_map() self.job = logic.create_job(FakeJob) tt_api_impacts.debug_clear_service()
def test_can_not_voted(self): tt_api_impacts.debug_clear_service() # one vote automaticaly created for bill author bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1')) self.create_bills(1, self.account1, 'Caption-a1-%d', bill_data) bill = Bill.objects.all()[0] self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 0),))
def setUp(self): super(PersonJobTests, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() self.person = self.place_1.persons[0] tt_api_impacts.debug_clear_service() self.job = jobs_logic.create_job(logic.PersonJob)
def setUp(self): super(HistoryTests, self).setUp() self.place_1, self.place_2, self.place_3 = game_logic.create_test_map() self.person_1 = self.place_1.persons[0] self.person_2 = self.place_2.persons[0] self.account_1_id = self.accounts_factory.create_account().id self.account_2_id = self.accounts_factory.create_account().id tt_api_impacts.debug_clear_service()
def setUp(self): super().setUp() self.place_1, self.place_2, self.place_3 = create_test_map() self.account_1 = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account_1) self.hero = self.storage.accounts_to_heroes[self.account_1.id] tt_api_impacts.debug_clear_service()
def test_can_not_vote(self): tt_api_impacts.debug_clear_service() heroes_logic.save_hero(self.hero) bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1')) self.create_bills(1, self.account2, 'Caption-a1-%d', bill_data) bill = Bill.objects.all()[0] self.account1.prolong_premium(30) self.account1.save() self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 1),))
def setUp(self): super().setUp() tt_api_impacts.debug_clear_service() impacts = [] self.hero_id = 111 self.person_id = 666 self.place_id = 777 impacts = [ tt_api_impacts.PowerImpact( type=tt_api_impacts.IMPACT_TYPE.JOB, actor_type=tt_api_impacts.OBJECT_TYPE.HERO, actor_id=self.hero_id, target_type=tt_api_impacts.OBJECT_TYPE.JOB_PERSON_POSITIVE, target_id=self.person_id, amount=1000), tt_api_impacts.PowerImpact( type=tt_api_impacts.IMPACT_TYPE.JOB, actor_type=tt_api_impacts.OBJECT_TYPE.HERO, actor_id=self.hero_id, target_type=tt_api_impacts.OBJECT_TYPE.JOB_PERSON_NEGATIVE, target_id=self.person_id, amount=2000), tt_api_impacts.PowerImpact( type=tt_api_impacts.IMPACT_TYPE.JOB, actor_type=tt_api_impacts.OBJECT_TYPE.HERO, actor_id=self.hero_id, target_type=tt_api_impacts.OBJECT_TYPE.JOB_PLACE_POSITIVE, target_id=self.place_id, amount=3000), tt_api_impacts.PowerImpact( type=tt_api_impacts.IMPACT_TYPE.JOB, actor_type=tt_api_impacts.OBJECT_TYPE.HERO, actor_id=self.hero_id, target_type=tt_api_impacts.OBJECT_TYPE.JOB_PLACE_NEGATIVE, target_id=self.place_id, amount=4000) ] foreign_impacts = copy.deepcopy(impacts) for impact in foreign_impacts: impact.target_id += 1 impact.amount = random.randint(1, 10000) logic.add_power_impacts(impacts) logic.add_power_impacts(foreign_impacts)
def setUp(self): super().setUp() tt_api_impacts.debug_clear_service() self.person_impacts = [] self.place_impacts = [] test_size = conf.settings.PLACE_INNER_CIRCLE_SIZE + conf.settings.PERSON_INNER_CIRCLE_SIZE self.person_id = 666 self.place_id = 777 for i in range(test_size): self.person_impacts.append( tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=100 + i, person_id=self.person_id, amount=1000 + i)) self.person_impacts.append( tt_api_impacts.PowerImpact.hero_2_person( type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE, hero_id=200 + i, person_id=self.person_id, amount=2000 + i)) for i in range(test_size): self.place_impacts.append( tt_api_impacts.PowerImpact.hero_2_place( type=tt_api_impacts.IMPACT_TYPE.INNER_CIRCLE, hero_id=300 + i, place_id=self.place_id, amount=3000 + i)) self.place_impacts.append( tt_api_impacts.PowerImpact.hero_2_place( type=tt_api_impacts.IMPACT_TYPE.OUTER_CIRCLE, hero_id=400 + i, place_id=self.place_id, amount=4000 + i)) logic.add_power_impacts(self.person_impacts) logic.add_power_impacts(self.place_impacts)
def test_sync__no_power(self): tt_api_impacts.debug_clear_service() self.storage.sync() self.assertEqual(self.storage.turn, 0) self.assertEqual(self.storage._inner_power, { 10: 0, 20: 0, 30: 0, 40: 0, 50: 0 }) self.assertEqual(self.storage._outer_power, { 10: 0, 20: 0, 30: 0, 40: 0, 50: 0 })
def test_impact(self): tt_api_impacts.debug_clear_service() while not self.hero.next_spending.is_IMPACT: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money self.storage.process_turn() impacts = politic_power_logic.get_last_power_impacts(limit=100) self.assertTrue(len(impacts) == 0) self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_impact, money - self.hero.money) self.storage._test_save()
def check_apply(self): tt_api_impacts.debug_clear_service() VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR) data = self.bill.user_form_initials data['approved'] = True form = self.bill.data.get_moderator_form_update(data) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.assertTrue(self.bill.apply()) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) impacts = politic_power_logic.get_last_power_impacts(limit=100) return impacts
def test_impact__can_change_power(self): tt_api_impacts.debug_clear_service() while not self.hero.next_spending.is_IMPACT: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money with mock.patch('the_tale.game.heroes.objects.Hero.can_change_person_power', lambda self, person: True): self.storage.process_turn() impacts = politic_power_logic.get_last_power_impacts(limit=100) self.assertTrue(len(impacts) == 2) self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_impact, money - self.hero.money) self.storage._test_save()
def setUp(self): super().setUp() tt_api_impacts.debug_clear_service() self.impacts = [] for type in tt_api_impacts.IMPACT_TYPE.records: self.impacts.append( tt_api_impacts.PowerImpact.hero_2_person( type=type, hero_id=random.randint(1, 100), person_id=random.randint(1, 100), amount=random.randint(1, 100))) self.impacts.append( tt_api_impacts.PowerImpact.hero_2_place( type=type, hero_id=random.randint(1, 100), place_id=random.randint(1, 100), amount=random.randint(1, 100))) with mock.patch('the_tale.game.turn.number', lambda: random.randint(1, 10000)): for impact in self.impacts: logic.add_power_impacts([impact])
def setUp(self): super().setUp() tt_api_impacts.debug_clear_service()
def setUp(self): super().setUp() self.places = game_logic.create_test_map() tt_api_impacts.debug_clear_service()
def setUp(self): super(BillPrototypeTests, self).setUp() self.hero = heroes_logic.load_hero(account_id=self.account2.id) tt_api_impacts.debug_clear_service()