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, 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 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_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) old_storage_version = places_storage.resource_exchanges._version self.assertEqual(len(places_storage.resource_exchanges.all()), 1) form = BillDecline.ModeratorForm({'approved': True}) 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_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_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, 'x': self.accepted_position_2[0], 'y': self.accepted_position_2[1] }) 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.x, self.accepted_position_2[0]) self.assertEqual(self.bill.data.y, self.accepted_position_2[1]) self.assertEqual(self.bill.data.base_name, 'new-building-name-нс,ед,им')
def test_update(self): data = { 'caption': 'new-caption', '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_update(self): declined_bill_2 = BillPrototype.create( self.account1, 'declined-bill-caption', 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', '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_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_has_meaning__duplicate(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.assertFalse(bill.has_meaning())
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_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): 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 = BuildingRenaming.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.filter(state=BUILDING_STATE.WORKING).count(), 2) self.building.reload() self.assertEqual(self.building.name, u'r-building-name-нс,ед,им')
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', '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 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 = 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): form = self.bill.data.get_user_form_update( post={ 'caption': 'new-caption', 'rationale': 'new-rationale', '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_place_name_forms, self.place2.utg_name) self.assertEqual(self.bill.data.place.id, self.place2.id) self.assertEqual(self.bill.data.old_place_name, self.place2.utg_name.normal_form()) self.assertFalse(self.bill.data.place_name_changed)
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_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 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.x, self.accepted_position_1[0]) self.assertEqual(building.y, self.accepted_position_1[1]) self.assertEqual(building.utg_name, noun)
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): 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 test_has_meaning__duplicate(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('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()) form = BuildingCreate.ModeratorForm(data) bill = BillPrototype.get_by_id(self.bill.id) bill.state = relations.BILL_STATE.VOTING bill.save() self.assertFalse(bill.has_meaning())
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 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.sync(force=True) self.place1.sync_parameters() self.assertEqual(self.place1.stability, 1.0) 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 test_not_enough_voices_percents(self): turn.increment() turn.increment() 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, turn.number()) self.check_place(self.place1.id, self.place1.name, self.place1.utg_name.forms)
def test_update(self): form = self.bill.data.get_user_form_update( post={ 'caption': 'new-caption', '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_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') declined_form = PlaceResourceExchange.ModeratorForm({'approved': True}) 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): 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) self.assertTrue(bill.state.is_ACCEPTED) self.assertEqual( Building.objects.filter(state=BUILDING_STATE.WORKING).count(), 1) self.assertEqual(len(places_storage.buildings.all()), 1) building = places_storage.buildings.all()[0] self.assertNotEqual(building.id, self.building_1.id)
def test_approved(self): current_time = TimePrototype.get_current_time() current_time.increment_turn() 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.FOR) VotePrototype.create(self.account4, self.bill, relations.VOTE_TYPE.REFRAINED) ################################## # set name forms data = self.bill.user_form_initials data.update( linguistics_helpers.get_word_post_data(self.bill.data.name_forms, 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.assertEqual(Post.objects.all().count(), 1) with mock.patch( 'the_tale.accounts.workers.accounts_manager.Worker.cmd_run_account_method' ) as cmd_run_account_method: self.assertTrue(self.bill.apply()) self.assertEqual(cmd_run_account_method.call_args_list, [ mock.call(account_id=self.bill.owner.id, method_name=accounts_prototypes.AccountPrototype. update_actual_bills.__name__, data={}) ]) self.assertTrue(self.bill.state.is_ACCEPTED) self.assertEqual(Post.objects.all().count(), 2) bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(bill.state.is_ACCEPTED) places_storage.places.sync(force=True) self.place1.refresh_attributes() self.assertTrue(self.place1.attrs.stability < 1.0) self.assertEqual(bill.applyed_at_turn, current_time.turn_number) self.check_place(self.place1.id, 'new_name_1-нс,ед,им', self.bill.data.name_forms.forms)
def name(self): from the_tale.game.bills.prototypes import BillPrototype from the_tale.game.persons import storage as persons_storage from the_tale.game.places import storage as places_storage if self.bill_id is not None: return BillPrototype.get_by_id(self.bill_id).caption if self.place_id is not None: return places_storage.places[self.place_id].name if self.person_id is not None: return persons_storage.persons[self.person_id].name
def name(self): from the_tale.game.bills.prototypes import BillPrototype from the_tale.game.persons import storage as persons_storage from the_tale.game.places import storage as places_storage if self.bill_id is not None: return BillPrototype.get_by_id(self.bill_id).caption if self.place_id is not None: return places_storage.places[self.place_id].name if self.person_id is not None: return persons_storage.persons[self.person_id].name
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', 'person': self.person_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.person_id, self.person_2.id)
def test_update(self): form = self.bill.data.get_user_form_update(post={'caption': 'new-caption', 'chronicle_on_accepted': 'chronicle-on-accepted-2', 'person': self.person2.id, 'power_bonus': relations.POWER_BONUS_CHANGES.DOWN }) 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.person2.id) self.assertTrue(self.bill.data.power_bonus.is_DOWN)
def test_update(self): form = self.bill.data.get_user_form_update(post={'caption': 'new-caption', 'place': self.place_2.id, 'chronicle_on_accepted': 'chronicle-on-accepted', 'new_description': 'new new description'}) 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.description, 'new new description')
def test_update(self): VotePrototype.create(self.account2, self.bill, VOTE_TYPE.FOR) VotePrototype.create(self.account3, self.bill, VOTE_TYPE.AGAINST) VotePrototype.create(self.account4, self.bill, VOTE_TYPE.REFRAINED) self.bill.recalculate_votes() self.bill.approved_by_moderator = True self.bill.save() old_updated_at = self.bill.updated_at self.assertEqual(self.bill.votes_for, 2) self.assertEqual(self.bill.votes_against, 1) self.assertEqual(self.bill.votes_refrained, 1) self.assertEqual(Vote.objects.all().count(), 4) self.assertEqual(self.bill.caption, 'bill-1-caption') self.assertEqual(self.bill.rationale, 'bill-1-rationale') self.assertEqual(self.bill.approved_by_moderator, True) self.assertEqual(self.bill.data.base_name, u'new_name_1-нс,ед,им') self.assertEqual(self.bill.data.place_id, self.place1.id) self.assertEqual(Post.objects.all().count(), 1) new_name = names.generator.get_test_name('new-new-name') data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'caption': 'new-caption', 'rationale': 'new-rationale', 'chronicle_on_accepted': 'chronicle-on-accepted-2', 'place': self.place2.id}) form = PlaceRenaming.UserForm(data) self.assertTrue(form.is_valid()) self.bill.update(form) self.bill = BillPrototype.get_by_id(self.bill.id) self.assertTrue(old_updated_at < self.bill.updated_at) self.assertTrue(self.bill.state.is_VOTING) self.assertEqual(self.bill.votes_for, 1) self.assertEqual(self.bill.votes_against, 0) self.assertEqual(self.bill.votes_refrained, 0) self.assertEqual(Vote.objects.all().count(), 1) self.assertEqual(self.bill.caption, 'new-caption') self.assertEqual(self.bill.rationale, 'new-rationale') self.assertEqual(self.bill.chronicle_on_accepted, 'chronicle-on-accepted-2') self.assertEqual(self.bill.approved_by_moderator, False) self.assertEqual(self.bill.data.base_name, u'new-new-name-нс,ед,им') self.assertEqual(self.bill.data.place_id, self.place2.id) self.assertEqual(Post.objects.all().count(), 2) self.assertEqual(Thread.objects.get(id=self.bill.forum_thread_id).caption, 'new-caption')
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 test_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PlaceModifier.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.assertTrue(self.place._modifier.is_TRADE_CENTER)
def test_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PlaceModifier.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.assertTrue(self.place._modifier.is_TRADE_CENTER)
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', 'person': self.person2.id, 'power_bonus': relations.POWER_BONUS_CHANGES.DOWN }) 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.person2.id) self.assertTrue(self.bill.data.power_bonus.is_DOWN)
def check_apply(self, change_power_mock): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PersonChronicle.ModeratorForm({'approved': True}) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) with mock.patch('the_tale.game.persons.prototypes.PersonPrototype.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_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PlaceDescripton.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.assertNotEqual(self.place.description, 'old description') self.assertEqual(self.place.description, 'new description')
def test_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PlaceModifier.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.assertNotEqual(self.place.modifier, None) self.assertEqual(self.place.modifier, TradeCenter(self.place))
def test_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PlaceDescripton.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.assertNotEqual(self.place.description, 'old description' ) self.assertEqual(self.place.description, 'new description' )
def test_apply(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.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_update(self): form = self.bill.data.get_user_form_update( post={ "caption": "new-caption", "rationale": "new-rationale", "chronicle_on_accepted": "chronicle-on-accepted-2", "person": self.person2.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_id, self.person2.id)
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, False) VotePrototype.create(self.account3, self.bill, True) form = PersonRemove.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.assertNotEqual(self.place1.persons[0].id, self.person1.id) self.assertTrue(self.person1.out_game) self.assertTrue(Person.objects.get(id=self.person1.id).state, PERSON_STATE.OUT_GAME)
def test_has_meaning__duplicate(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.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 check_apply(self, change_power_mock): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PersonChronicle.ModeratorForm({'approved': True}) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) with mock.patch('the_tale.game.persons.objects.Person.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_apply(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) form = PersonRemove.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.assertNotEqual(self.place1.persons[0].id, self.person1.id) self.assertTrue(self.person1.out_game) self.assertTrue(Person.objects.get(id=self.person1.id).state, PERSON_STATE.OUT_GAME)
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(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 test_apply(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.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 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.assertTrue(self.place._modifier.is_TRADE_CENTER)
def test_update(self): self.place_2.attrs.modifier_craft_center = 100 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': 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)