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_actors_after_user_update(self): old_actors_timestamps = list(Actor.objects.all().values_list( 'created_at', flat=True)) noun = names.generator.get_test_name('new-new-name') data = linguistics_helpers.get_word_post_data(noun, 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) new_actors_timestamps = list(Actor.objects.all().values_list( 'created_at', flat=True)) self.assertFalse( set(old_actors_timestamps) & set(new_actors_timestamps)) self.assertTrue(new_actors_timestamps)
def test_achievements(self): 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 = linguistics_helpers.get_word_post_data( self.bill.data.name_forms, prefix='name') data.update({'approved': True}) form = PlaceRenaming.ModeratorForm(data) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) ################################## with mock.patch( 'the_tale.accounts.achievements.storage.AchievementsStorage.verify_achievements' ) as verify_achievements: self.assertTrue(self.bill.apply()) self.assertEqual(verify_achievements.call_args_list, [ mock.call(account_id=self.account1.id, type=ACHIEVEMENT_TYPE.POLITICS_ACCEPTED_BILLS, old_value=0, new_value=1) ])
def get_form_data(self): mob = prototypes.MobRecordPrototype.create_random( uuid='bandit', state=relations.MOB_RECORD_STATE.DISABLED) data = linguistics_helpers.get_word_post_data(mob.utg_name, prefix='name') data.update({ 'level': str(mob.level), 'global_action_probability': '0.25', 'terrains': ['TERRAIN.PLANE_GRASS', 'TERRAIN.HILLS_GRASS'], 'abilities': ['hit', 'strong_hit', 'sidestep'], 'type': 'BEING_TYPE.CIVILIZED', 'archetype': 'ARCHETYPE.NEUTRAL', 'description': mob.description, 'communication_verbal': game_relations.COMMUNICATION_VERBAL.CAN, 'communication_gestures': game_relations.COMMUNICATION_GESTURES.CAN, 'communication_telepathic': game_relations.COMMUNICATION_TELEPATHIC.CAN, 'intellect_level': game_relations.INTELLECT_LEVEL.NORMAL }) return data
def get_form_data(self): mob = logic.create_random_mob_record(uuid='bandit', state=relations.MOB_RECORD_STATE.DISABLED) data = linguistics_helpers.get_word_post_data(mob.utg_name, prefix='name') data.update({'level': str(mob.level), 'global_action_probability': '0.25', 'terrains': ['TERRAIN.PLANE_GRASS', 'TERRAIN.HILLS_GRASS'], 'abilities': ['hit', 'strong_hit', 'sidestep'], 'type': 'TYPE.CIVILIZED', 'archetype': 'ARCHETYPE.NEUTRAL', 'description': mob.description, 'communication_verbal': beings_relations.COMMUNICATION_VERBAL.CAN, 'communication_gestures': beings_relations.COMMUNICATION_GESTURES.CAN, 'communication_telepathic': beings_relations.COMMUNICATION_TELEPATHIC.CAN, 'intellect_level': beings_relations.INTELLECT_LEVEL.NORMAL, 'structure': 'STRUCTURE.STRUCTURE_1', 'features': ['FEATURE.FEATURE_1', 'FEATURE.FEATURE_7'], 'movement': 'MOVEMENT.MOVEMENT_2', 'body': 'BODY.BODY_3', 'size': 'SIZE.SIZE_4', 'weapon_1': 'STANDARD_WEAPON.WEAPON_1', 'material_1': 'MATERIAL.MATERIAL_1', 'power_type_1': 'ARTIFACT_POWER_TYPE.NEUTRAL', 'weapon_2': 'STANDARD_WEAPON.WEAPON_10', 'material_2': 'MATERIAL.MATERIAL_10', 'power_type_2': 'ARTIFACT_POWER_TYPE.MOST_PHYSICAL',}) return data
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_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_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): 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 = {'rationale': 'bill-rationale', 'person': self.person_1.id, 'chronicle_on_accepted': 'chronicle-accepted-1', 'caption': 'bill-caption'} 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.filter(state=BUILDING_STATE.WORKING).count(), 2) self.building.reload() self.assertEqual(self.building.name, 'r-building-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 get_create_data(self, name='mob name'): word = names.generator.get_test_name(name=name) data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update({ 'level': 666, 'terrains': [TERRAIN.PLANE_GRASS, TERRAIN.HILLS_GRASS], 'abilities': ['hit', 'strong_hit', 'sidestep'], 'type': game_relations.BEING_TYPE.CIVILIZED, 'archetype': game_relations.ARCHETYPE.NEUTRAL, 'global_action_probability': 0.5, 'description': 'mob description', 'communication_verbal': game_relations.COMMUNICATION_VERBAL.CAN, 'communication_gestures': game_relations.COMMUNICATION_GESTURES.CAN, 'communication_telepathic': game_relations.COMMUNICATION_TELEPATHIC.CAN, 'intellect_level': game_relations.INTELLECT_LEVEL.NORMAL }) return data
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_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 setUp(self): super(TestVoteRequests, self).setUp() self.account2.prolong_premium(30) self.account2.save() self.hero = heroes_logic.load_hero(account_id=self.account2.id) self.hero.places_history.add_place(self.place1.id) self.hero.places_history.add_place(self.place2.id) self.hero.places_history.add_place(self.place3.id) heroes_logic.save_hero(self.hero) new_name = names.generator().get_test_name('new-name') data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'caption': 'bill-caption', 'rationale': 'bill-rationale', 'chronicle_on_accepted': 'chronicle-on-accepted', 'place': self.place1.id}) self.client.post(reverse('game:bills:create') + ('?bill_type=%s' % PlaceRenaming.type.value), data) self.bill = BillPrototype(Bill.objects.all()[0]) self.request_logout() self.request_login(self.account2.email)
def get_update_data(self, name='new name'): word = names.generator.get_test_name(name=name) data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update({ 'level': 667, 'terrains': [TERRAIN.PLANE_JUNGLE, TERRAIN.HILLS_JUNGLE], 'abilities': ['hit', 'speedup'], 'type': game_relations.BEING_TYPE.ANIMAL, 'archetype': game_relations.ARCHETYPE.MAGICAL, 'global_action_probability': 0.1, 'description': 'new description', 'communication_verbal': game_relations.COMMUNICATION_VERBAL.CAN_NOT, 'communication_gestures': game_relations.COMMUNICATION_GESTURES.CAN_NOT, 'communication_telepathic': game_relations.COMMUNICATION_TELEPATHIC.CAN_NOT, 'intellect_level': game_relations.INTELLECT_LEVEL.LOW }) return data
def test_is_make_sense__no_building(self): 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 = { 'person': self.person_1.id, 'chronicle_on_accepted': 'chronicle-accepted-1', 'caption': 'bill-caption' } 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) places_logic.destroy_building(self.building) self.assertFalse(self.bill.has_meaning())
def setUp(self): super(BillBuildingRenamingTests, 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.BuildingRenaming( person_id=self.person.id, old_place_name_forms=self.place1.utg_name, new_building_name_forms=names.generator.get_test_name( 'new-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.new_building_name_forms, prefix='name') data.update({'approved': True}) self.form = bills.BuildingRenaming.ModeratorForm(data) self.assertTrue(self.form.is_valid())
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_apply(self): 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 = { 'person': self.person_1.id, 'chronicle_on_accepted': 'chronicle-accepted-1', 'caption': 'bill-caption' } 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.filter(state=BUILDING_STATE.WORKING).count(), 2) building = places_logic.load_building(self.building.id) self.assertEqual(building.name, 'r-building-name-нс,ед,им')
def test_create__with_on_review_parent__by_moderator(self): self.request_login(self.moderator.email) for word_type in utg_relations.WORD_TYPE.records: parent_word = utg_words.Word.create_test_word(word_type, prefix=u'parent-') child_word = utg_words.Word.create_test_word(word_type, prefix=u'child-') parent = prototypes.WordPrototype.create(parent_word, author=self.account_1) requested_url = url('linguistics:words:create', type=word_type.value, parent=parent.id) with self.check_delta(prototypes.WordPrototype._db_count, 0): response = self.client.post( requested_url, helpers.get_word_post_data(child_word)) last_prototype = prototypes.WordPrototype._db_latest() self.assertTrue(parent.created_at < last_prototype.created_at) self.check_ajax_ok(response, data={ 'next_url': url('linguistics:words:show', last_prototype.id) }) self.assertEqual(child_word, last_prototype.utg_word) self.assertEqual(last_prototype.parent_id, None)
def test_create__with_parent(self): for word_type in utg_relations.WORD_TYPE.records: parent_word = utg_words.Word.create_test_word(word_type, prefix=u'parent-') child_word = utg_words.Word.create_test_word(word_type, prefix=u'child-') parent = prototypes.WordPrototype.create(parent_word) parent.state = relations.WORD_STATE.IN_GAME parent.save() requested_url = url('linguistics:words:create', type=word_type.value, parent=parent.id) with self.check_delta(prototypes.WordPrototype._db_count, 1): response = self.client.post( requested_url, helpers.get_word_post_data(child_word)) self.assertTrue( prototypes.WordPrototype._db_filter(id=parent.id).exists()) last_prototype = prototypes.WordPrototype._db_latest() self.check_ajax_ok(response, data={ 'next_url': url('linguistics:words:show', last_prototype.id) }) self.assertEqual(child_word, last_prototype.utg_word) self.assertEqual(last_prototype.parent_id, parent.id)
def test_create__copy_of_onreview__when_ingame_parent_exists(self): for word_type in utg_relations.WORD_TYPE.records: ingame_parent_word = utg_words.Word.create_test_word( word_type, prefix=u'in-game-parent-') onreview_parent_word = utg_words.Word.create_test_word( word_type, prefix=u'on-review-parent-') child_word = utg_words.Word.create_test_word(word_type, prefix=u'child-') ingame_parent = prototypes.WordPrototype.create(ingame_parent_word) ingame_parent.state = relations.WORD_STATE.IN_GAME ingame_parent.save() onreview_parent = prototypes.WordPrototype.create( onreview_parent_word, parent=ingame_parent, author=self.account_1) onreview_parent.state = relations.WORD_STATE.ON_REVIEW onreview_parent.save() requested_url = url('linguistics:words:create', type=word_type.value, parent=onreview_parent.id) with self.check_delta(prototypes.WordPrototype._db_count, 0): self.check_ajax_ok( self.client.post(requested_url, helpers.get_word_post_data(child_word))) last_prototype = prototypes.WordPrototype._db_latest() self.assertTrue( last_prototype.created_at > onreview_parent.created_at) self.assertEqual(last_prototype.parent_id, ingame_parent.id)
def test_login_required(self): self.request_logout() word_type = utg_relations.WORD_TYPE.records[0] word = utg_words.Word.create_test_word(word_type, prefix='w-') requested_url = url('linguistics:words:create', type=word_type.value) self.check_ajax_error( self.client.post(requested_url, helpers.get_word_post_data(word)), 'common.login_required')
def test_duplicate_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('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) dup_noun = names.generator().get_test_name('dup-building-name') bill = BillPrototype.get_by_id(self.bill.id) bill.state = relations.BILL_STATE.VOTING bill.save() data = bill.user_form_initials data.update( linguistics_helpers.get_word_post_data(dup_noun, prefix='name')) data['approved'] = True form = bill.data.get_moderator_form_update(data) self.assertTrue(form.is_valid()) bill.update_by_moderator(form) # apply first bill self.assertTrue(self.bill.apply()) # apply second bill self.assertTrue(bill.apply()) self.assertEqual(Building.objects.all().count(), 1) building = places_logic.load_building(Building.objects.all()[0].id) self.assertEqual(building.utg_name, noun) self.assertNotEqual(building.utg_name, dup_noun)
def get_post_data(self): 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}) return data
def get_post_data(self, depends_on_id=None): new_name = names.generator().get_test_name('new-name') data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'caption': 'bill-caption', 'chronicle_on_accepted': 'chronicle-on-accepted', 'depends_on': depends_on_id, 'place': self.place1.id}) return data
def get_post_data(self, name=u'новое имя', gender=GENDER.MASCULINE, race=RACE.DWARF): data = {'gender': gender, 'race': race} data.update( linguistics_helpers.get_word_post_data( names.generator.get_test_name(name=name), prefix=u'name')) return data
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_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 setUp(self): super(BillPlaceRenamingTests, self).setUp() bill_data = bills.PlaceRenaming(place_id=self.place1.id, name_forms=names.generator.get_test_name('new-name')) self.bill = BillPrototype.create(self.account1, 'bill-caption', 'bill-rationale', bill_data, chronicle_on_accepted='chronicle-on-accepted') data = linguistics_helpers.get_word_post_data(bill_data.name_forms, prefix='name') data.update({'approved': True}) self.form = bills.PlaceRenaming.ModeratorForm(data) self.assertTrue(self.form.is_valid())
def post_data(self): data = {'description': 'new-description', 'type': relations.TYPE.random(), 'max_health': 650, 'dedication': relations.DEDICATION.random(), 'archetype': game_relations.ARCHETYPE.random(), 'mode': relations.MODE.random()} data.update(linguistics_helpers.get_word_post_data(names.generator.get_test_name(name='new_name'), prefix='name')) data.update(helpers.get_abilities_post_data(helpers.FAKE_ABILITIES_CONTAINER_2),) return data
def get_create_data(self, name='mob name'): word = names.generator().get_test_name(name=name) data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update({ 'level': 666, 'terrains': [TERRAIN.PLANE_GRASS, TERRAIN.HILLS_GRASS], 'abilities': ['hit', 'strong_hit', 'sidestep'], 'type': beings_relations.TYPE.CIVILIZED, 'archetype': game_relations.ARCHETYPE.NEUTRAL, 'global_action_probability': 0.5, 'description': 'mob description', 'communication_verbal': beings_relations.COMMUNICATION_VERBAL.CAN, 'communication_gestures': beings_relations.COMMUNICATION_GESTURES.CAN, 'communication_telepathic': beings_relations.COMMUNICATION_TELEPATHIC.CAN, 'intellect_level': beings_relations.INTELLECT_LEVEL.NORMAL, 'structure': beings_relations.STRUCTURE.STRUCTURE_1, 'features': [ beings_relations.FEATURE.FEATURE_1, beings_relations.FEATURE.FEATURE_7 ], 'movement': beings_relations.MOVEMENT.MOVEMENT_2, 'body': beings_relations.BODY.BODY_3, 'size': beings_relations.SIZE.SIZE_4, 'weapon_1': artifacts_relations.STANDARD_WEAPON.WEAPON_1, 'material_1': tt_artifacts_relations.MATERIAL.MATERIAL_1, 'power_type_1': artifacts_relations.ARTIFACT_POWER_TYPE.NEUTRAL, 'weapon_2': artifacts_relations.STANDARD_WEAPON.WEAPON_10, 'material_2': tt_artifacts_relations.MATERIAL.MATERIAL_10, 'power_type_2': artifacts_relations.ARTIFACT_POWER_TYPE.MOST_MAGICAL }) return data
def setUp(self): super(TestUpdateRequests, self).setUp() new_name = names.generator().get_test_name('new-name') data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'caption': 'bill-caption', 'chronicle_on_accepted': 'chronicle-on-accepted', 'place': self.place1.id}) self.client.post(reverse('game:bills:create') + ('?bill_type=%s' % PlaceRenaming.type.value), data) self.bill = BillPrototype(Bill.objects.all()[0])
def get_update_data(self, name='new name'): word = names.generator().get_test_name(name=name) data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update({ 'level': 667, 'terrains': [TERRAIN.PLANE_JUNGLE, TERRAIN.HILLS_JUNGLE], 'abilities': ['hit', 'speedup'], 'type': beings_relations.TYPE.ANIMAL, 'archetype': game_relations.ARCHETYPE.MAGICAL, 'description': 'new description', 'communication_verbal': beings_relations.COMMUNICATION_VERBAL.CAN_NOT, 'communication_gestures': beings_relations.COMMUNICATION_GESTURES.CAN_NOT, 'communication_telepathic': beings_relations.COMMUNICATION_TELEPATHIC.CAN_NOT, 'intellect_level': beings_relations.INTELLECT_LEVEL.LOW, 'structure': beings_relations.STRUCTURE.STRUCTURE_1, 'features': [ beings_relations.FEATURE.FEATURE_1, beings_relations.FEATURE.FEATURE_7 ], 'movement': beings_relations.MOVEMENT.MOVEMENT_2, 'body': beings_relations.BODY.BODY_3, 'size': beings_relations.SIZE.SIZE_4, 'orientation': beings_relations.ORIENTATION.VERTICAL, 'weapon_1': artifacts_relations.STANDARD_WEAPON.WEAPON_1, 'material_1': tt_artifacts_relations.MATERIAL.MATERIAL_1, 'power_type_1': artifacts_relations.ARTIFACT_POWER_TYPE.MOST_PHYSICAL, 'weapon_2': artifacts_relations.STANDARD_WEAPON.WEAPON_10, 'material_2': tt_artifacts_relations.MATERIAL.MATERIAL_10, 'power_type_2': artifacts_relations.ARTIFACT_POWER_TYPE.PHYSICAL }) return data
def test_duplicate_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('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) dup_noun = names.generator().get_test_name('dup-building-name') bill = BillPrototype.get_by_id(self.bill.id) bill.state = relations.BILL_STATE.VOTING bill.save() data = bill.user_form_initials data.update(linguistics_helpers.get_word_post_data(dup_noun, prefix='name')) data['approved'] = True form = bill.data.get_moderator_form_update(data) self.assertTrue(form.is_valid()) bill.update_by_moderator(form) # apply first bill self.assertTrue(self.bill.apply()) # apply second bill 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 setUp(self): super(TestEditRequests, self).setUp() new_name = names.generator().get_test_name('new-name') data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'caption': 'bill-caption', 'rationale': 'bill-rationale', 'chronicle_on_accepted': 'chronicle-on-accepted', 'place': self.place1.id}) self.client.post(reverse('game:bills:create') + ('?bill_type=%s' % PlaceRenaming.type.value), data) self.bill = BillPrototype(Bill.objects.all()[0])
def test_create_with_all_fields(self): for word_type in utg_relations.WORD_TYPE.records: word = utg_words.Word.create_test_word(word_type, prefix='w-') requested_url = url('linguistics:words:create', type=word_type.value) with self.check_delta(prototypes.WordPrototype._db_count, 1): response = self.client.post(requested_url, helpers.get_word_post_data(word)) last_prototype = prototypes.WordPrototype._db_latest() self.check_ajax_ok(response, data={'next_url': url('linguistics:words:show', last_prototype.id)}) self.assertEqual(word, last_prototype.utg_word)
def test_create__parent_not_cpecified(self): for word_type in utg_relations.WORD_TYPE.records: word = utg_words.Word.create_test_word(word_type) parent = prototypes.WordPrototype.create(word) parent.state = random.choice(relations.WORD_STATE.records) parent.save() requested_url = url('linguistics:words:create', type=word_type.value) with self.check_delta(prototypes.WordPrototype._db_count, 0): self.check_ajax_error(self.client.post(requested_url, helpers.get_word_post_data(word)), 'linguistics.words.create.parent_exists')
def test_create__with_parent__full_copy(self): for word_type in utg_relations.WORD_TYPE.records: word = utg_words.Word.create_test_word(word_type) parent = prototypes.WordPrototype.create(word) parent.state = relations.WORD_STATE.IN_GAME parent.save() requested_url = url('linguistics:words:create', type=word_type.value, parent=parent.id) with self.check_not_changed(prototypes.WordPrototype._db_count): self.check_ajax_error(self.client.post(requested_url, helpers.get_word_post_data(parent.utg_word)), 'linguistics.words.create.full_copy_restricted')
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 test_update(self): VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.FOR) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account4, self.bill, relations.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, '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, '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_has_meaning__duplicate_name(self): VotePrototype.create(self.account2, self.bill, False) VotePrototype.create(self.account3, self.bill, True) new_name = names.generator.get_test_name('new-new-name') self.bill.data.place.set_utg_name(new_name) data = linguistics_helpers.get_word_post_data(new_name, prefix='name') data.update({'approved': True}) form = PlaceRenaming.ModeratorForm(data) self.assertTrue(form.is_valid()) self.bill.update_by_moderator(form) self.assertFalse(self.bill.has_meaning())
def post_data(self): data = {'description': 'new-description', 'type': game_relations.BEING_TYPE.random(), 'max_health': 650, 'dedication': relations.DEDICATION.random(), 'archetype': game_relations.ARCHETYPE.random(), 'mode': relations.MODE.random(), 'communication_verbal': game_relations.COMMUNICATION_VERBAL.CAN, 'communication_gestures': game_relations.COMMUNICATION_GESTURES.CAN, 'communication_telepathic': game_relations.COMMUNICATION_TELEPATHIC.CAN, 'intellect_level': game_relations.INTELLECT_LEVEL.NORMAL} data.update(linguistics_helpers.get_word_post_data(names.generator.get_test_name(name='new_name'), prefix='name')) data.update(helpers.get_abilities_post_data(helpers.FAKE_ABILITIES_CONTAINER_2),) return data
def get_create_data(self): word = names.generator.get_test_name(name='mob name') data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update( { 'level': 666, 'terrains': [TERRAIN.PLANE_GRASS, TERRAIN.HILLS_GRASS], 'abilities': ['hit', 'strong_hit', 'sidestep'], 'type': MOB_TYPE.CIVILIZED, 'archetype': game_relations.ARCHETYPE.NEUTRAL, 'global_action_probability': 0.5, 'description': 'mob description'} ) return data
def get_update_data(self): word = names.generator.get_test_name(name='new name') data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update( {'level': 667, 'terrains': [TERRAIN.PLANE_JUNGLE, TERRAIN.HILLS_JUNGLE], 'abilities': ['hit', 'speedup'], 'type': MOB_TYPE.BARBARIAN, 'archetype': game_relations.ARCHETYPE.MAGICAL, 'global_action_probability': 0.1, 'description': 'new description'}) return data
def get_form_data(self): mob = prototypes.MobRecordPrototype.create_random(uuid='bandit', state=relations.MOB_RECORD_STATE.DISABLED) data = linguistics_helpers.get_word_post_data(mob.utg_name, prefix='name') data.update( { 'level': str(mob.level), 'global_action_probability': '0.25', 'terrains': ['TERRAIN.PLANE_GRASS', 'TERRAIN.HILLS_GRASS'], 'abilities': ['hit', 'strong_hit', 'sidestep'], 'type': 'MOB_TYPE.CIVILIZED', 'archetype': 'ARCHETYPE.NEUTRAL', 'description': mob.description} ) return data
def get_update_data(self, mob=None): word = names.generator.get_test_name(name='new name') data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update({ 'level': 2, 'type': relations.ARTIFACT_TYPE.AMULET, 'power_type': relations.ARTIFACT_POWER_TYPE.MAGICAL, 'rare_effect': relations.ARTIFACT_EFFECT.NO_EFFECT, 'epic_effect': relations.ARTIFACT_EFFECT.POISON, 'special_effect': relations.ARTIFACT_EFFECT.CHILD_GIFT, 'description': 'new artifact description', 'mob': u'' if mob is None else mob.id}) return data
def get_create_data(self, mob=None): word = names.generator.get_test_name(name='artifact') data = linguistics_helpers.get_word_post_data(word, prefix='name') data.update({ 'level': 1, 'type': relations.ARTIFACT_TYPE.RING, 'power_type': relations.ARTIFACT_POWER_TYPE.NEUTRAL, 'rare_effect': relations.ARTIFACT_EFFECT.POISON, 'epic_effect': relations.ARTIFACT_EFFECT.GREAT_PHYSICAL_DAMAGE, 'special_effect': relations.ARTIFACT_EFFECT.NO_EFFECT, 'description': 'artifact description', 'mob': u'' if mob is None else mob.id}) return data
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_has_meaning__duplicate_name(self): VotePrototype.create(self.account2, self.bill, relations.VOTE_TYPE.AGAINST) VotePrototype.create(self.account3, self.bill, relations.VOTE_TYPE.FOR) new_name = names.generator().get_test_name('new-new-name') self.bill.data.place.set_utg_name(new_name) data = self.bill.user_form_initials data.update(linguistics_helpers.get_word_post_data(new_name, 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.assertFalse(self.bill.has_meaning())
def get_form_data(self): artifact = prototypes.ArtifactRecordPrototype.create_random(uuid='sword') data = linguistics_helpers.get_word_post_data(artifact.utg_name, prefix='name') data.update({ 'level': '1', 'type': 'ARTIFACT_TYPE.RING', 'power_type': 'ARTIFACT_POWER_TYPE.NEUTRAL', 'rare_effect': 'ARTIFACT_EFFECT.POISON', 'epic_effect': 'ARTIFACT_EFFECT.GREAT_PHYSICAL_DAMAGE', 'special_effect': 'ARTIFACT_EFFECT.NO_EFFECT', 'description': 'artifact description', 'uuid': 'some-uuid', 'mob': ''}) return data
def get_form_data(self, artifact): from the_tale.linguistics.tests import helpers as linguistics_helpers data = linguistics_helpers.get_word_post_data(artifact.utg_name, prefix='name') data.update({ 'level': str(artifact.level), 'type': artifact.type, 'power_type': artifact.power_type, 'rare_effect': artifact.rare_effect, 'epic_effect': artifact.epic_effect, 'special_effect': artifact.special_effect, 'description': artifact.description, 'uuid': artifact.uuid, 'mob': str(artifact.mob.id) if artifact.mob else ''}) return data
def test_can_not_replace_onreview_word_from_another_author(self): for word_type in utg_relations.WORD_TYPE.records: parent_word = utg_words.Word.create_test_word(word_type, prefix=u'parent-') child_word = utg_words.Word.create_test_word(word_type, prefix=u'child-') parent = prototypes.WordPrototype.create(parent_word, author=self.account_2) requested_url = url('linguistics:words:create', type=word_type.value, parent=parent.id) with self.check_delta(prototypes.WordPrototype._db_count, 0): self.check_ajax_error(self.client.post(requested_url, helpers.get_word_post_data(child_word)), 'linguistics.words.create.can_not_edit_anothers_word') last_prototype = prototypes.WordPrototype._db_latest() self.assertEqual(parent.created_at, last_prototype.created_at) self.assertEqual(parent_word, last_prototype.utg_word)
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 get_create_data(self, mob=None): word = names.generator().get_test_name(name="artifact") data = linguistics_helpers.get_word_post_data(word, prefix="name") data.update( { "level": 1, "type": relations.ARTIFACT_TYPE.RING, "power_type": relations.ARTIFACT_POWER_TYPE.NEUTRAL, "rare_effect": relations.ARTIFACT_EFFECT.POISON, "epic_effect": relations.ARTIFACT_EFFECT.GREAT_PHYSICAL_DAMAGE, "special_effect": relations.ARTIFACT_EFFECT.NO_EFFECT, "description": "artifact description", "mob": "" if mob is None else mob.id, } ) return data
def get_update_data(self, mob=None): word = names.generator().get_test_name(name="new name") data = linguistics_helpers.get_word_post_data(word, prefix="name") data.update( { "level": 2, "type": relations.ARTIFACT_TYPE.AMULET, "power_type": relations.ARTIFACT_POWER_TYPE.MAGICAL, "rare_effect": relations.ARTIFACT_EFFECT.NO_EFFECT, "epic_effect": relations.ARTIFACT_EFFECT.POISON, "special_effect": relations.ARTIFACT_EFFECT.CHILD_GIFT, "description": "new artifact description", "mob": "" if mob is None else mob.id, } ) return data