def test_get_minimum_created_time_of_active_bills(self): self.assertEqual(self.bill.created_at, BillPrototype.get_minimum_created_time_of_active_bills()) self.bill.remove(initiator=self.account1) # not there are no anothe bills an get_minimum_created_time_of_active_bills return now() self.assertTrue(self.bill.created_at < BillPrototype.get_minimum_created_time_of_active_bills())
def setUp(self): super(BillDeclineResourceExchangeTests, self).setUp() self.resource_1, self.resource_2 = choose_exchange_resources() self.declined_bill_data = PlaceResourceExchange( place_1_id=self.place1.id, place_2_id=self.place2.id, resource_1=self.resource_1, resource_2=self.resource_2 ) self.declined_bill = BillPrototype.create( owner=self.account1, caption="declined-bill-caption", rationale="declined-bill-rationale", chronicle_on_accepted="chronicle-on-accepted", bill=self.declined_bill_data, ) data = self.declined_bill.user_form_initials data["approved"] = True declined_form = self.declined_bill.data.get_moderator_form_update(data) self.assertTrue(declined_form.is_valid()) self.declined_bill.update_by_moderator(declined_form) self.declined_bill.apply() self.bill_data = BillDecline(declined_bill_id=self.declined_bill.id) self.bill = BillPrototype.create( self.account1, "bill-caption", "bill-rationale", self.bill_data, chronicle_on_accepted="chronicle-on-accepted", )
def test_update(self): declined_bill_2 = BillPrototype.create( self.account1, "declined-bill-caption", "declined-bill-rationale", self.declined_bill_data, chronicle_on_accepted="chronicle-on-accepted-2", ) data = declined_bill_2.user_form_initials data["approved"] = True declined_form = declined_bill_2.data.get_moderator_form_update(data) self.assertTrue(declined_form.is_valid()) declined_bill_2.update_by_moderator(declined_form) declined_bill_2.apply() form = self.bill.data.get_user_form_update( post={ "caption": "new-caption", "rationale": "new-rationale", "chronicle_on_accepted": "chronicle-on-accepted-3", "declined_bill": declined_bill_2.id, } ) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.declined_bill_id, declined_bill_2.id)
def test_apply(self): VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR) old_storage_version = places_storage.resource_exchanges._version self.assertEqual(len(places_storage.resource_exchanges.all()), 1) 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()) self.assertNotEqual(old_storage_version, places_storage.resource_exchanges._version) self.assertEqual(len(places_storage.resource_exchanges.all()), 0) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) declined_bill = BillPrototype.get_by_id(self.declined_bill.id) self.assertTrue(declined_bill.state.is_ACCEPTED) self.assertTrue(declined_bill.is_declined) self.assertTrue(declined_bill.declined_by.id, bill.id)
def test_reapply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) old_storage_version = resource_exchange_storage._version self.assertEqual(len(resource_exchange_storage.all()), 1) form = BillDecline.ModeratorForm({'approved': True}) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.assertTrue(self.bill.apply()) self.bill.state = BILL_STATE.VOTING self.bill.save() with mock.patch('the_tale.game.bills.prototypes.BillPrototype.decline') as skipped_decline: self.assertTrue(self.bill.apply()) self.assertEqual(skipped_decline.call_count, 0) self.assertNotEqual(old_storage_version, resource_exchange_storage._version) self.assertEqual(len(resource_exchange_storage.all()), 0) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) declined_bill = BillPrototype.get_by_id(self.declined_bill.id) self.assertTrue(declined_bill.state.is_ACCEPTED) self.assertTrue(declined_bill.is_declined) self.assertTrue(declined_bill.declined_by.id, bill.id)
def test_reapply(self): VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR) old_storage_version = places_storage.resource_exchanges._version self.assertEqual(len(places_storage.resource_exchanges.all()), 1) 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()) self.bill.state = relations.BILL_STATE.VOTING self.bill.save() with mock.patch("the_tale.game.bills.prototypes.BillPrototype.decline") as skipped_decline: self.assertTrue(self.bill.apply()) self.assertEqual(skipped_decline.call_count, 0) self.assertNotEqual(old_storage_version, places_storage.resource_exchanges._version) self.assertEqual(len(places_storage.resource_exchanges.all()), 0) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) declined_bill = BillPrototype.get_by_id(self.declined_bill.id) self.assertTrue(declined_bill.state.is_ACCEPTED) self.assertTrue(declined_bill.is_declined) self.assertTrue(declined_bill.declined_by.id, bill.id)
def create_bill_decline__exchange(self): resource_1, resource_2 = choose_exchange_resources() declined_bill_data = bills.PlaceResourceExchange( place_1_id=self.place_1.id, place_2_id=self.place_2.id, resource_1=resource_1, resource_2=resource_2 ) declined_bill = BillPrototype.create( self.account, "declined-bill-caption", "declined-bill-rationale", declined_bill_data, chronicle_on_accepted="chronicle-on-accepted", ) declined_form = bills.PlaceResourceExchange.ModeratorForm({"approved": True}) self.assertTrue(declined_form.is_valid()) declined_bill.update_by_moderator(declined_form) declined_bill.apply() bill_data = bills.BillDecline(declined_bill_id=declined_bill.id) bill = BillPrototype.create( self.account, "bill-caption", "bill-rationale", bill_data, chronicle_on_accepted="chronicle-on-accepted" ) return bill, declined_bill
def test_accepted_bills_count(self): for state in relations.BILL_STATE.records: bill = self.create_bill(self.account1) bill.state = state bill.save() for state in relations.BILL_STATE.records: bill = self.create_bill(self.account2) bill.state = state bill.save() self.assertEqual(BillPrototype.accepted_bills_count(self.account1.id), 1) self.assertEqual(BillPrototype.accepted_bills_count(self.account2.id), 1) self.assertEqual(BillPrototype.accepted_bills_count(self.account3.id), 0)
def setUp(self): super(GetApplicableBillsTest, self).setUp() self.bill_data = PlaceDescripton(place_id=self.place1.id, description='description') self.bill_1 = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') self.bill_2 = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') self.bill_3 = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') BillPrototype._model_class.objects.all().update(updated_at=datetime.datetime.now() - datetime.timedelta(seconds=bills_settings.BILL_LIVE_TIME), approved_by_moderator=True) self.bill_1.reload() self.bill_2.reload() self.bill_3.reload()
def create_bill_decline__conversion(self): conversion_1, conversion_2 = choose_conversions() declined_bill_data = bills.PlaceResourceConversion(place_id=self.place_1.id, conversion=conversion_1) declined_bill = BillPrototype.create(self.account, 'declined-bill-caption', 'declined-bill-rationale', declined_bill_data, chronicle_on_accepted='chronicle-on-accepted') declined_form = bills.PlaceResourceConversion.ModeratorForm({'approved': True}) self.assertTrue(declined_form.is_valid()) declined_bill.update_by_moderator(declined_form) declined_bill.apply() bill_data = bills.BillDecline(declined_bill_id=declined_bill.id) bill = BillPrototype.create(self.account, 'bill-caption', 'bill-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') return bill, declined_bill
def test_user_form_validation__wrong_bill(self): bill_data = PlaceDescripton(place_id=self.place1.id, description="new description") bill = BillPrototype.create( self.account1, "bill-1-caption", "bill-1-rationale", bill_data, chronicle_on_accepted="chronicle-on-accepted", ) data = bill.user_form_initials data["approved"] = True form = bill.data.get_moderator_form_update(data) self.assertTrue(form.is_valid()) bill.update_by_moderator(form) self.assertTrue(bill.apply()) form = self.bill.data.get_user_form_update( post={ "caption": "caption", "rationale": "rationale", "chronicle_on_accepted": "chronicle-on-accepted-3", "declined_bill": bill.id, } ) self.assertFalse(form.is_valid())
def test_update(self): self.person_2_2.politic_power.change_power( self.person_2_2, hero_id=self.account.id, has_in_preferences=True, power=100 ) persons_logic.create_social_connection( connection_type=persons_relations.SOCIAL_CONNECTION_TYPE.PARTNER, person_1=self.person_2_2, person_2=self.person_3_1, ) data = { "caption": "new-caption", "rationale": "new-rationale", "chronicle_on_accepted": "new-chronicle-on-accepted", "person_1": self.person_2_2.id, "person_2": self.person_3_1.id, } form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.person_1_id, self.person_2_2.id) self.assertEqual(self.bill.data.person_2_id, self.person_3_1.id) self.assertEqual(self.bill.data.place_1_id, self.place2.id) self.assertEqual(self.bill.data.place_2_id, self.place3.id) self.assertEqual(self.bill.data.old_place_1_name, self.place2.utg_name) self.assertEqual(self.bill.data.old_place_2_name, self.place3.utg_name)
def setUp(self): super(PersonRemoveSocialConnectionTests, self).setUp() self.person_1_1 = self.place1.persons[0] self.person_2_1, self.person_2_2 = self.place2.persons[0:2] self.person_3_1 = self.place3.persons[0] self.account = self.accounts_factory.create_account() persons_logic.create_social_connection( connection_type=persons_relations.SOCIAL_CONNECTION_TYPE.PARTNER, person_1=self.person_1_1, person_2=self.person_2_1, ) self.bill_data = PersonRemoveSocialConnection(person_1_id=self.person_1_1.id, person_2_id=self.person_2_1.id) self.bill = BillPrototype.create( self.account1, "bill-1-caption", "bill-1-rationale", self.bill_data, chronicle_on_accepted="chronicle-on-accepted", ) self.person_1_1.politic_power.change_power( self.person_1_1, hero_id=self.account.id, has_in_preferences=True, power=100 )
def test_duplicate_apply(self): self.assertEqual(Building.objects.all().count(), 0) VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) noun = names.generator.get_test_name('building-name') data = linguistics_helpers.get_word_post_data(noun, prefix='name') data.update({'approved': True}) form = BuildingCreate.ModeratorForm(data) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.assertTrue(self.bill.apply()) dup_noun = names.generator.get_test_name('dup-building-name') data = linguistics_helpers.get_word_post_data(dup_noun, prefix='name') data.update({'approved': True}) form = BuildingCreate.ModeratorForm(data) bill = BillPrototype.get_by_id(self.bill.id) bill.state = BILL_STATE.VOTING bill.save() self.assertTrue(form.is_valid()) bill.update_by_moderator(form) self.assertTrue(bill.apply()) self.assertEqual(Building.objects.all().count(), 1) self.assertEqual(BuildingPrototype._db_get_object(0).utg_name, noun) self.assertNotEqual(BuildingPrototype._db_get_object(0).utg_name, dup_noun)
def test_apply(self): self.assertEqual(Building.objects.all().count(), 0) VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR) noun = names.generator().get_test_name('r-building-name') data = self.bill.user_form_initials data.update(linguistics_helpers.get_word_post_data(noun, prefix='name')) 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) self.assertEqual(Building.objects.all().count(), 1) building = places_storage.buildings.all()[0] self.assertEqual(building.person.id, self.person_1.id) self.assertEqual(building.place.id, self.place1.id) self.assertEqual(building.utg_name, noun)
def test_update(self): self.person_2_2.politic_power.change_power(self.person_2_2, hero_id=self.account.id, has_in_preferences=True, power=100) data = {'caption': 'new-caption', 'rationale': 'new-rationale', 'chronicle_on_accepted': 'new-chronicle-on-accepted', 'person_1': self.person_2_2.id, 'person_2': self.person_3_1.id, 'connection_type': persons_relations.SOCIAL_CONNECTION_TYPE.CONCURRENT} form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.person_1_id, self.person_2_2.id) self.assertEqual(self.bill.data.person_2_id, self.person_3_1.id) self.assertTrue(self.bill.data.connection_type.is_CONCURRENT) self.assertEqual(self.bill.data.place_1_id, self.place2.id) self.assertEqual(self.bill.data.place_2_id, self.place3.id) self.assertEqual(self.bill.data.old_place_1_name, self.place2.utg_name) self.assertEqual(self.bill.data.old_place_2_name, self.place3.utg_name)
def test_apply_without_person(self): self.assertEqual(Building.objects.all().count(), 0) VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) noun = names.generator.get_test_name('building-name') data = linguistics_helpers.get_word_post_data(noun, prefix='name') data.update({'approved': True}) form = BuildingCreate.ModeratorForm(data) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.person_1.move_out_game() self.assertTrue(self.bill.apply()) bill = BillPrototype.get_by_id(self.bill.id) bill.state = BILL_STATE.VOTING bill.save() self.assertTrue(bill.apply()) self.assertEqual(Building.objects.all().count(), 0)
def test_apply(self): self.assertEqual(Building.objects.all().count(), 0) VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) noun = names.generator.get_test_name('r-building-name') data = linguistics_helpers.get_word_post_data(noun, prefix='name') data.update({'approved': True}) form = BuildingCreate.ModeratorForm(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) self.assertEqual(Building.objects.all().count(), 1) building = buildings_storage.all()[0] self.assertEqual(building.person.id, self.person_1.id) self.assertEqual(building.place.id, self.place1.id) self.assertEqual(building.utg_name, noun)
def test_update(self): form = self.bill.data.get_user_form_update(post={'caption': 'new-caption', 'rationale': 'new-rationale', 'chronicle_on_accepted': 'chronicle-on-accepted-2', 'place_1': self.place2.id, 'place_2': self.place1.id, 'resource_1': self.resource_2, 'resource_2': self.resource_1}) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.place_1_id, self.place2.id) self.assertEqual(self.bill.data.place_2_id, self.place1.id) self.assertEqual(self.bill.data.resource_1, self.resource_2) self.assertEqual(self.bill.data.resource_2, self.resource_1) self.assertEqual(self.bill.data.old_place_1_name_forms, self.place2.utg_name) self.assertEqual(self.bill.data.old_place_2_name_forms, self.place1.utg_name) self.assertEqual(self.bill.data.place_1.id, self.place2.id) self.assertEqual(self.bill.data.place_2.id, self.place1.id) self.assertEqual(self.bill.data.old_place_1_name, self.place2.utg_name.normal_form()) self.assertEqual(self.bill.data.old_place_2_name, self.place1.utg_name.normal_form()) self.assertFalse(self.bill.data.place_2_name_changed) self.assertFalse(self.bill.data.place_1_name_changed)
def test_get_exchanges_for_bill_id__exists(self): from the_tale.forum.models import Category, SubCategory from the_tale.game.bills.conf import bills_settings from the_tale.game.bills import bills from the_tale.game.bills.prototypes import BillPrototype account = self.accounts_factory.create_account() 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) bill_data = bills.PlaceRenaming(place_id=self.place_1.id, name_forms=names.generator().get_test_name('new_name')) bill = BillPrototype.create(account, 'bill-caption', 'bill-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') ResourceExchangePrototype.create(place_1=self.place_1, place_2=self.place_2, resource_1=self.resource_1, resource_2=self.resource_2, bill=None) exchange_2 = ResourceExchangePrototype.create(place_1=self.place_1, place_2=self.place_3, resource_1=self.resource_1, resource_2=self.resource_2, bill=bill) ResourceExchangePrototype.create(place_1=self.place_2, place_2=self.place_3, resource_1=self.resource_1, resource_2=self.resource_2, bill=None) self.assertEqual(exchange_2.id, storage.resource_exchanges.get_exchange_for_bill_id(bill.id).id)
def test_not_enough_voices_percents(self): current_time = TimePrototype.get_current_time() current_time.increment_turn() current_time.increment_turn() VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.REFRAINED) self.assertEqual(Post.objects.all().count(), 1) with self.check_not_changed(lambda: self.place1.attrs.stability): with mock.patch('the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method') as cmd_run_account_method: self.assertFalse(self.bill.apply()) self.assertEqual(cmd_run_account_method.call_count, 0) self.assertTrue(self.bill.state.is_REJECTED) self.assertEqual(Post.objects.all().count(), 2) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_REJECTED) places_storage.places.sync(force=True) self.place1.refresh_attributes() self.assertEqual(bill.applyed_at_turn, current_time.turn_number) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
def setUp(self): super(PersonRemoveTests, self).setUp() self.person1 = sorted(self.place1.persons, key=lambda p: -p.total_politic_power_fraction)[0] self.person2 = sorted(self.place2.persons, key=lambda p: -p.total_politic_power_fraction)[-1] self.bill_data = PersonRemove(person_id=self.person1.id, old_place_name_forms=self.place1.utg_name) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def setUp(self): super(PersonChronicleTests, self).setUp() self.person1 = sorted(self.place1.persons, key=lambda p: -p.power)[0] self.person2 = sorted(self.place2.persons, key=lambda p: -p.power)[-1] self.bill_data = PersonChronicle(person_id=self.person1.id, old_place_name_forms=self.place1.utg_name, power_bonus=relations.POWER_BONUS_CHANGES.UP) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def setUp(self): super(BuildingCreateTests, self).setUp() self.person_1 = sorted(self.place1.persons, key=lambda p: -p.power)[0] self.person_2 = sorted(self.place2.persons, key=lambda p: -p.power)[-1] self.bill_data = BuildingCreate(person_id=self.person_1.id, old_place_name_forms=self.place1.utg_name, utg_name=names.generator.get_test_name(u'building-name')) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def setUp(self): super(BillPlaceChangeModifierTests, self).setUp() bill_data = bills.PlaceModifier(place_id=self.place1.id, modifier_id=TradeCenter.get_id(), modifier_name=TradeCenter.TYPE.text, old_modifier_name=None) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.PlaceModifier.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def setUp(self): super(BillPlaceChronicleTests, self).setUp() bill_data = bills.PlaceChronicle(place_id=self.place1.id, old_name_forms=self.place1.utg_name, power_bonus=bills_relations.POWER_BONUS_CHANGES.DOWN) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.PersonChronicle.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def setUp(self): super(BillPlaceDescriptionTests, self).setUp() bill_data = bills.PlaceDescripton(place_id=self.place1.id, description='new description') self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.PlaceDescripton.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def setUp(self): super(BillPersonRemoveTests, self).setUp() bill_data = bills.PersonRemove(person_id=self.place1.persons[0].id, old_place_name_forms=self.place1.utg_name) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.PersonRemove.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def test_wrong_state(self): for state in relations.BILL_STATE.records: if state.is_VOTING: continue self.bill_1.state = state self.bill_1.save() self.assertEqual(set(BillPrototype.get_applicable_bills_ids()), set((self.bill_2.id, self.bill_3.id)))
def setUp(self): super(TestPrototypeApply, self).setUp() bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator.get_test_name('new_name_1')) self.bill = BillPrototype.create(self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') self.bill.approved_by_moderator = True self.bill.save()
def setUp(self): super(PersonChronicleTests, self).setUp() self.person1 = sorted(self.place1.persons, key=lambda p: -p.total_politic_power_fraction)[0] self.person2 = sorted( self.place2.persons, key=lambda p: -p.total_politic_power_fraction)[-1] self.bill_data = PersonChronicle( person_id=self.person1.id, old_place_name_forms=self.place1.utg_name, power_bonus=relations.POWER_BONUS_CHANGES.UP) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def test_update(self): form = self.bill.data.get_user_form_update( post={ 'caption': 'new-caption', 'rationale': 'new-rationale', 'place': self.place_2.id, 'chronicle_on_accepted': 'chronicle-on-accepted', 'new_modifier': CraftCenter.get_id() }) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.place_id, self.place_2.id) self.assertEqual(self.bill.data.modifier_id, CraftCenter.get_id()) self.assertEqual(self.bill.data.modifier_name, CraftCenter.TYPE.text) self.assertEqual(self.bill.data.old_modifier_name, None)
def test_apply(self): 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) self.assertNotEqual(self.place.description, 'old description') self.assertEqual(self.place.description, 'new description')
def test_accepted_bill_might(self): old_might = calculate_might(self.account) bill_data = PlaceRenaming( place_id=self.place_1.id, name_forms=names.generator().get_test_name('bill_place')) bill = BillPrototype.create( self.account, 'caption', bill_data, chronicle_on_accepted='chronicle-on-accepted') bill.state = BILL_STATE.ACCEPTED bill.save() Post.objects.all().delete() Thread.objects.all().delete() Vote.objects.all().delete() self.assertTrue(calculate_might(self.account) > old_might) self.assertEqual(calculate_might(self.account_2), 0)
def test_apply(self): 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) person = persons_storage.persons[self.person_1.id] self.assertEqual(person.place.id, self.place2.id)
def setUp(self): super(PlaceRaceTests, self).setUp() self.place = self.place1 self.place_2 = self.place2 self.place.race = game_relations.RACE.ORC self.place_2.race = game_relations.RACE.ELF self.bill_data = PlaceRace(place_id=self.place.id, new_race=game_relations.RACE.GOBLIN, old_race=self.place.race) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def test_has_meaning__duplicate(self): self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2) 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) bill.state = relations.BILL_STATE.VOTING bill.save() self.assertFalse(bill.has_meaning())
def test_has_meaning__already_in_town(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PersonMove.ModeratorForm({'approved': True}) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.assertTrue(self.bill.has_meaning()) self.assertTrue(self.bill.apply()) bill = BillPrototype.get_by_id(self.bill.id) bill.state = BILL_STATE.VOTING bill.save() self.assertTrue(form.is_valid()) bill.update_by_moderator(form) self.assertFalse(bill.has_meaning())
def test_update(self): data = linguistics_helpers.get_word_post_data( names.generator.get_test_name('new-building-name'), prefix='name') data.update({ 'caption': 'new-caption', 'rationale': 'new-rationale', 'chronicle_on_accepted': 'chronicle-on-accepted', 'person': self.person_2.id }) form = self.bill.data.get_user_form_update(post=data) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.person_id, self.person_2.id) self.assertEqual(self.bill.data.base_name, u'new-building-name-нс,ед,им')
def test_apply(self): 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) self.assertFalse( persons_storage.social_connections.is_connected( self.person_1_1, self.person_2_1))
def setUp(self): super(BillBuildingCreateTests, self).setUp() bill_data = bills.BuildingCreate( person_id=self.place1.persons[0].id, old_place_name_forms=self.place1.utg_name, utg_name=names.generator.get_test_name('building-name')) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') data = linguistics_helpers.get_word_post_data( bill_data.building_name_forms, prefix='name') data.update({'approved': True}) self.form = bills.BuildingCreate.ModeratorForm(data) self.assertTrue(self.form.is_valid())
def check_apply(self, change_power_mock): 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) with mock.patch('the_tale.game.places.objects.Place.cmd_change_power' ) as cmd_change_power: self.assertTrue(self.bill.apply()) self.assertEqual(cmd_change_power.call_args_list, change_power_mock) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED)
def test_update(self): self.place_2.attrs.modifier_craft_center = 100 form = self.bill.data.get_user_form_update( post={ 'caption': 'new-caption', 'place': self.place_2.id, 'chronicle_on_accepted': 'chronicle-on-accepted', 'new_modifier': places_modifiers.CITY_MODIFIERS.CRAFT_CENTER }) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.place_id, self.place_2.id) self.assertTrue(self.bill.data.modifier_id.is_CRAFT_CENTER) self.assertEqual(self.bill.data.modifier_name, places_modifiers.CITY_MODIFIERS.CRAFT_CENTER.text) self.assertEqual(self.bill.data.old_modifier_name, None)
def test_update_by_moderator(self): self.assertEqual(self.bill.approved_by_moderator, False) noun = names.generator.get_test_name('new-name') data = linguistics_helpers.get_word_post_data(noun, prefix='name') data.update({'approved': True}) form = PlaceRenaming.ModeratorForm(data) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(self.bill.state.is_VOTING) self.assertEqual(self.bill.approved_by_moderator, True) self.assertEqual(self.bill.data.name_forms.forms, noun.forms)
def test_duplicate_apply(self): self.assertEqual( Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2) VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = BuildingDestroy.ModeratorForm({'approved': True}) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.assertTrue(self.bill.apply()) bill = BillPrototype.get_by_id(self.bill.id) bill.state = BILL_STATE.VOTING bill.save() self.assertTrue(bill.apply()) self.assertEqual( Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 1)
def setUp(self): from the_tale.game.bills.tests.helpers import choose_conversions from the_tale.game.bills.bills import PlaceResourceConversion super(BillPlaceConversionResourcesTests, self).setUp() self.conversion_1, self.conversion_2 = choose_conversions() self.bill_data = PlaceResourceConversion(place_id=self.place1.id, conversion=self.conversion_1) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.PlaceModifier.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def setUp(self): super(BillBuildingDestroyTests, self).setUp() self.person = self.place1.persons[0] self.building = BuildingPrototype.create( self.person, utg_name=names.generator.get_test_name('building-name')) bill_data = bills.BuildingDestroy( person_id=self.person.id, old_place_name_forms=self.place1.utg_name) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.BuildingDestroy.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def test_apply(self): old_storage_version = resource_exchange_storage._version self.apply_bill() self.assertNotEqual(old_storage_version, resource_exchange_storage._version) self.assertEqual(len(resource_exchange_storage.all()), 1) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) exchange = resource_exchange_storage.all()[0] self.assertEqual(set([exchange.place_1.id, exchange.place_2.id]), set([self.place1.id, self.place2.id])) self.assertEqual(set([exchange.resource_1, exchange.resource_2]), set([self.resource_1, self.resource_2])) self.assertEqual(exchange.bill_id, bill.id)
def setUp(self): super(BuildingCreateTests, self).setUp() self.person_1 = sorted( self.place1.persons, key=lambda p: -p.total_politic_power_fraction)[0] self.person_2 = sorted( self.place2.persons, key=lambda p: -p.total_politic_power_fraction)[-1] self.bill_data = BuildingCreate( person_id=self.person_1.id, old_place_name_forms=self.place1.utg_name, utg_name=names.generator().get_test_name('building-name')) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def test_apply(self): old_storage_version = places_storage.resource_exchanges._version self.apply_bill() self.assertNotEqual(old_storage_version, places_storage.resource_exchanges._version) self.assertEqual(len(places_storage.resource_exchanges.all()), 1) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) exchange = places_storage.resource_exchanges.all()[0] self.assertEqual(exchange.place_1.id, self.place1.id) self.assertEqual(exchange.place_2, None) self.assertEqual(exchange.resource_1, self.conversion_1.resource_from) self.assertEqual(exchange.resource_2, self.conversion_1.resource_to) self.assertEqual(exchange.bill_id, bill.id)
def test_decline__no_excange(self): self.apply_bill() ResourceExchangePrototype._db_all().delete() places_storage.resource_exchanges.refresh() self.assertEqual(len(places_storage.resource_exchanges.all()), 0) old_storage_version = places_storage.resource_exchanges._version decliner = BillPrototype.create( self.account1, 'bill-1-caption', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') self.bill.decline(decliner) self.assertEqual(old_storage_version, places_storage.resource_exchanges._version)
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_apply(self): self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 2) VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = BuildingDestroy.ModeratorForm({'approved': True}) 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) self.assertEqual(Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 1) self.assertEqual(len(buildings_storage.all()), 1) building = buildings_storage.all()[0] self.assertNotEqual(building.id, self.building_1.id)
def setUp(self): super(RecordTests, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() self.account = self.accounts_factory.create_account() 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) bill_data = bills.PlaceRenaming( place_id=self.place_1.id, name_forms=names.generator().get_test_name('new_name')) self.bill = BillPrototype.create( self.account, 'bill-caption', bill_data, chronicle_on_accepted='chronicle-on-accepted')
def test_has_meaning__already_connected(self): 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.has_meaning()) self.assertTrue(self.bill.apply()) bill = BillPrototype.get_by_id(self.bill.id) bill.state = relations.BILL_STATE.VOTING bill.save() self.assertTrue(form.is_valid()) bill.update_by_moderator(form) self.assertFalse(bill.has_meaning())
def setUp(self): from the_tale.game.bills.tests.helpers import choose_exchange_resources from the_tale.game.bills.bills import PlaceResourceExchange super(BillPlaceExchangeResourcesTests, self).setUp() self.resource_1, self.resource_2 = choose_exchange_resources() self.bill_data = PlaceResourceExchange(place_1_id=self.place1.id, place_2_id=self.place2.id, resource_1=self.resource_1, resource_2=self.resource_2) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') self.form = bills.PlaceModifier.ModeratorForm({'approved': True}) self.assertTrue(self.form.is_valid())
def setUp(self): super(BuildingDestroyTests, self).setUp() self.person_1 = self.place1.persons[0] self.person_2 = self.place2.persons[0] self.person_3 = self.place3.persons[0] self.building_1 = places_logic.create_building( self.person_1, utg_name=names.generator().get_test_name('building-name-1')) self.building_2 = places_logic.create_building( self.person_2, utg_name=names.generator().get_test_name('building-name-2')) self.bill_data = BuildingDestroy( person_id=self.person_1.id, old_place_name_forms=self.place1.utg_name) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
def test_update(self): data = { 'caption': 'new-caption', 'chronicle_on_accepted': 'new-chronicle-on-accepted', 'person': self.person_2.id, 'new_place': self.place3.id } form = self.bill.data.get_user_form_update(post=data, owner_id=self.account.id) form.is_valid() self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.person_id, self.person_2.id) self.assertEqual(self.bill.data.new_place_id, self.place3.id) self.assertEqual(self.bill.data.new_place_name_forms, self.place3.utg_name)
def test_update(self): form = self.bill.data.get_user_form_update( post={ 'caption': 'new-caption', 'chronicle_on_accepted': 'chronicle-on-accepted', 'place': self.place2.id, 'conversion': self.conversion_2 }) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertEqual(self.bill.data.place_id, self.place2.id) self.assertEqual(self.bill.data.conversion, self.conversion_2) self.assertEqual(self.bill.data.old_name_forms, self.place2.utg_name) self.assertEqual(self.bill.data.place.id, self.place2.id) self.assertEqual(self.bill.data.old_name_forms, self.place2.utg_name) self.assertFalse(self.bill.data.place_name_changed)
def setUp(self): super(PersonAddSocialConnectionTests, self).setUp() self.person_1_1 = self.place1.persons[0] self.person_2_1, self.person_2_2 = self.place2.persons[0:2] self.person_3_1 = self.place3.persons[0] self.account = self.accounts_factory.create_account() self.bill_data = PersonAddSocialConnection( person_1_id=self.person_1_1.id, person_2_id=self.person_2_1.id, connection_type=persons_relations.SOCIAL_CONNECTION_TYPE.PARTNER) self.bill = BillPrototype.create( self.account1, 'bill-1-caption', self.bill_data, chronicle_on_accepted='chronicle-on-accepted') self.person_1_1.politic_power.change_power(self.person_1_1, hero_id=self.account.id, has_in_preferences=True, power=100)