Example #1
0
    def setUp(self):
        super(IndexRequestsTests, self).setUp()
        self.requested_url = url('game:companions:')
        self.requested_url_disabled = url('game:companions:', state=relations.STATE.DISABLED.value)

        self.companion_1 = logic.create_companion_record(utg_name=names.generator().get_test_name('c-1'),
                                                         description='companion-description',
                                                         type=game_relations.BEING_TYPE.random(),
                                                         max_health=100,
                                                         dedication=relations.DEDICATION.random(),
                                                         archetype=game_relations.ARCHETYPE.random(),
                                                         mode=relations.MODE.random(),
                                                         abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                                                         communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
                                                         communication_gestures=game_relations.COMMUNICATION_GESTURES.random(),
                                                         communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(),
                                                         intellect_level=game_relations.INTELLECT_LEVEL.random(),
                                                         state=relations.STATE.ENABLED)

        self.companion_2 = logic.create_companion_record(utg_name=names.generator().get_test_name('c-2'),
                                                         description='companion-description',
                                                         type=game_relations.BEING_TYPE.random(),
                                                         max_health=100,
                                                         dedication=relations.DEDICATION.random(),
                                                         archetype=game_relations.ARCHETYPE.random(),
                                                         mode=relations.MODE.random(),
                                                         abilities=helpers.FAKE_ABILITIES_CONTAINER_2,
                                                         communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
                                                         communication_gestures=game_relations.COMMUNICATION_GESTURES.random(),
                                                         communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(),
                                                         intellect_level=game_relations.INTELLECT_LEVEL.random(),
                                                         state=relations.STATE.DISABLED)
Example #2
0
    def test_update_companion_record__linguistics_restrictions(self):
        old_name = names.generator().get_test_name(name='old')
        new_name = names.generator().get_test_name(name='new')

        companion_record = logic.create_companion_record(utg_name=old_name,
                                                         description='old-description',
                                                         type=game_relations.BEING_TYPE.random(),
                                                         max_health=10,
                                                         dedication=relations.DEDICATION.random(),
                                                         archetype=game_relations.ARCHETYPE.random(),
                                                         mode=relations.MODE.random(),
                                                         abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                                                         communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
                                                         communication_gestures=game_relations.COMMUNICATION_GESTURES.random(),
                                                         communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(),
                                                         intellect_level=game_relations.INTELLECT_LEVEL.random())

        with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction:
            logic.update_companion_record(companion_record,
                                          utg_name=new_name,
                                          description='new-description',
                                          type=game_relations.BEING_TYPE.random(),
                                          max_health=10,
                                          dedication=relations.DEDICATION.random(),
                                          archetype=game_relations.ARCHETYPE.random(),
                                          mode=relations.MODE.random(),
                                          abilities=helpers.FAKE_ABILITIES_CONTAINER_2,
                                          communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
                                          communication_gestures=game_relations.COMMUNICATION_GESTURES.random(),
                                          communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(),
                                          intellect_level=game_relations.INTELLECT_LEVEL.random())

        self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION,
                                                                     external_id=companion_record.id,
                                                                     name=new_name.normal_form())])
Example #3
0
    def setUp(self):
        super(BuildingRenamingTests, 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 = BuildingPrototype.create(
            self.person_1,
            utg_name=names.generator().get_test_name('building-name'))
        self.building_2 = BuildingPrototype.create(
            self.person_2,
            utg_name=names.generator().get_test_name('building-name-2'))

        self.bill_data = BuildingRenaming(
            person_id=self.person_1.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-caption',
            'bill-rationale',
            self.bill_data,
            chronicle_on_accepted='chronicle-accepted-1')
Example #4
0
    def setUp(self):
        super(MobsStorageTests, self).setUp()
        create_test_map()

        self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all()

        self.mob_1.type = game_relations.BEING_TYPE.CIVILIZED
        self.mob_1.save()

        self.mob_2.type = game_relations.BEING_TYPE.CIVILIZED
        self.mob_2.is_mercenary = False
        self.mob_2.save()

        self.mob_3.type = game_relations.BEING_TYPE.CIVILIZED
        self.mob_3.save()

        self.bandit = MobRecordPrototype.create(uuid='bandit',
                                                level=1,
                                                utg_name=names.generator().get_test_name(name='bandint'),
                                                description='description',
                                                abilities=['hit'],
                                                terrains=[map_relations.TERRAIN.PLANE_SAND],
                                                type=game_relations.BEING_TYPE.CIVILIZED,
                                                state=MOB_RECORD_STATE.ENABLED)
        self.bandint_wrong = MobRecordPrototype.create(uuid='bandit_wrong',
                                                       level=1,
                                                       utg_name=names.generator().get_test_name(name='bandit_wrong'),
                                                       description='bandit_wrong description',
                                                       abilities=['hit'],
                                                       terrains=[map_relations.TERRAIN.PLANE_SAND],
                                                       type=game_relations.BEING_TYPE.CIVILIZED,
                                                       state=MOB_RECORD_STATE.DISABLED)
Example #5
0
    def setUp(self):
        super(RepairBuildingTests, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account(is_fast=True)

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]

        self.card = self.CARD()

        environment.deinitialize()
        environment.initialize()

        self.highlevel = environment.workers.highlevel
        self.highlevel.process_initialize(0, "highlevel")

        self.building_1 = BuildingPrototype.create(
            person=self.place_1.persons[0], utg_name=names.generator().get_test_name("building-1-name")
        )
        self.building_2 = BuildingPrototype.create(
            person=self.place_2.persons[0], utg_name=names.generator().get_test_name("building-1-name")
        )

        self.building_1.amortize(c.TURNS_IN_HOUR * 24)
        self.building_2.amortize(c.TURNS_IN_HOUR * 24)
Example #6
0
    def setUp(self):
        super(MobsStorageTests, self).setUp()
        create_test_map()

        self.mob_1, self.mob_2, self.mob_3 = storage.mobs.all()

        self.mob_1.type = beings_relations.TYPE.CIVILIZED
        logic.save_mob_record(self.mob_1)

        self.mob_2.type = beings_relations.TYPE.CIVILIZED
        self.mob_2.is_mercenary = False
        logic.save_mob_record(self.mob_2)

        self.mob_3.type = beings_relations.TYPE.CIVILIZED
        logic.save_mob_record(self.mob_3)

        self.bandit = logic.create_random_mob_record(
            uuid='bandit',
            level=1,
            utg_name=names.generator().get_test_name(name='bandint'),
            description='description',
            abilities=['hit'],
            terrains=[map_relations.TERRAIN.PLANE_SAND],
            type=beings_relations.TYPE.CIVILIZED,
            state=relations.MOB_RECORD_STATE.ENABLED)
        self.bandint_wrong = logic.create_random_mob_record(
            uuid='bandit_wrong',
            level=1,
            utg_name=names.generator().get_test_name(name='bandit_wrong'),
            description='bandit_wrong description',
            abilities=['hit'],
            terrains=[map_relations.TERRAIN.PLANE_SAND],
            type=beings_relations.TYPE.CIVILIZED,
            state=relations.MOB_RECORD_STATE.DISABLED)
    def setUp(self):
        super(RepairBuildingTests, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account(is_fast=True)

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero = self.storage.accounts_to_heroes[self.account_1.id]

        self.card = self.CARD()

        environment.deinitialize()
        environment.initialize()

        self.highlevel = environment.workers.highlevel
        self.highlevel.process_initialize(0, 'highlevel')

        self.building_1 = BuildingPrototype.create(
            person=self.place_1.persons[0],
            utg_name=names.generator().get_test_name('building-1-name'))
        self.building_2 = BuildingPrototype.create(
            person=self.place_2.persons[0],
            utg_name=names.generator().get_test_name('building-1-name'))

        self.building_1.amortize(c.TURNS_IN_HOUR * 24)
        self.building_2.amortize(c.TURNS_IN_HOUR * 24)
    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', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
Example #9
0
    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 = BuildingPrototype.create(self.person_1, utg_name=names.generator().get_test_name('building-name-1'))
        self.building_2 = BuildingPrototype.create(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', 'bill-1-rationale', self.bill_data, chronicle_on_accepted='chronicle-on-accepted')
Example #10
0
def create_test_map():
    linguistics_logic.sync_static_restrictions()

    politic_power_storage.places.reset()
    politic_power_storage.persons.reset()

    tt_api_impacts.debug_clear_service()

    map_logic.create_test_map_info()

    p1 = places_logic.create_place(x=1, y=1, size=1, utg_name=names.generator().get_test_name(name='1x1'), race=relations.RACE.HUMAN)
    p2 = places_logic.create_place(x=3, y=3, size=3, utg_name=names.generator().get_test_name(name='10x10'), race=relations.RACE.HUMAN)
    p3 = places_logic.create_place(x=1, y=3, size=3, utg_name=names.generator().get_test_name(name='1x10'), race=relations.RACE.HUMAN)

    for place in places_storage.places.all():
        for i in range(3):
            persons_logic.create_person(place=place,
                                        race=relations.RACE.random(),
                                        gender=relations.GENDER.random(),
                                        type=persons_relations.PERSON_TYPE.random(),
                                        utg_name=names.generator().get_test_name())

    for place in places_storage.places.all():
        place.refresh_attributes()

    RoadPrototype.create(point_1=p1, point_2=p2).update()
    RoadPrototype.create(point_1=p2, point_2=p3).update()

    update_waymarks()

    nearest_cells.update_nearest_cells()

    mob_1 = mobs_logic.create_random_mob_record('mob_1')
    mob_2 = mobs_logic.create_random_mob_record('mob_2')
    mob_3 = mobs_logic.create_random_mob_record('mob_3')

    artifacts_logic.create_random_artifact_record('loot_1', mob=mob_1)
    artifacts_logic.create_random_artifact_record('loot_2', mob=mob_2)
    artifacts_logic.create_random_artifact_record('loot_3', mob=mob_3)

    artifacts_logic.create_random_artifact_record('helmet_1', type=artifacts_relations.ARTIFACT_TYPE.HELMET, mob=mob_1)
    artifacts_logic.create_random_artifact_record('plate_1', type=artifacts_relations.ARTIFACT_TYPE.PLATE, mob=mob_2)
    artifacts_logic.create_random_artifact_record('boots_1', type=artifacts_relations.ARTIFACT_TYPE.BOOTS, mob=mob_3)

    for equipment_slot in heroes_relations.EQUIPMENT_SLOT.records:
        if equipment_slot.default:
            artifacts_logic.create_random_artifact_record(equipment_slot.default, type=equipment_slot.artifact_type)

    companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED)
    companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED)

    return p1, p2, p3
Example #11
0
    def test_update_companion_record__linguistics_restrictions(self):
        old_name = names.generator().get_test_name(name='old')
        new_name = names.generator().get_test_name(name='new')

        companion_record = logic.create_companion_record(utg_name=old_name,
                                                         description='old-description',
                                                         type=beings_relations.TYPE.random(),
                                                         max_health=10,
                                                         dedication=relations.DEDICATION.random(),
                                                         archetype=game_relations.ARCHETYPE.random(),
                                                         mode=relations.MODE.random(),
                                                         abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                                                         communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(),
                                                         communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(),
                                                         communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(),
                                                         intellect_level=beings_relations.INTELLECT_LEVEL.random(),
                                                         structure=beings_relations.STRUCTURE.random(),
                                                         features=frozenset((beings_relations.FEATURE.random(), beings_relations.FEATURE.random())),
                                                         movement=beings_relations.MOVEMENT.random(),
                                                         body=beings_relations.BODY.random(),
                                                         size=beings_relations.SIZE.random(),
                                                         weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.random(),
                                                                                           material=tt_artifacts_relations.MATERIAL.random(),
                                                                                           power_type=artifacts_relations.ARTIFACT_POWER_TYPE.random())])

        with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction:
            logic.update_companion_record(companion_record,
                                          utg_name=new_name,
                                          description='new-description',
                                          type=beings_relations.TYPE.random(),
                                          max_health=10,
                                          dedication=relations.DEDICATION.random(),
                                          archetype=game_relations.ARCHETYPE.random(),
                                          mode=relations.MODE.random(),
                                          abilities=helpers.FAKE_ABILITIES_CONTAINER_2,
                                          communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(),
                                          communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(),
                                          communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(),
                                          intellect_level=beings_relations.INTELLECT_LEVEL.random(),
                                          structure=beings_relations.STRUCTURE.random(),
                                          features=frozenset((beings_relations.FEATURE.random(), beings_relations.FEATURE.random())),
                                          movement=beings_relations.MOVEMENT.random(),
                                          body=beings_relations.BODY.random(),
                                          size=beings_relations.SIZE.random(),
                                          weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.random(),
                                                                            material=tt_artifacts_relations.MATERIAL.random(),
                                                                            power_type=artifacts_relations.ARTIFACT_POWER_TYPE.random())])

        self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION,
                                                                     external_id=companion_record.id,
                                                                     name=new_name.normal_form())])
Example #12
0
    def setUp(self):
        super(InfoRequestsTests, self).setUp()

        self.companion_1 = logic.create_companion_record(
            utg_name=names.generator().get_test_name('c-1'),
            description='companion-description-1',
            type=game_relations.BEING_TYPE.random(),
            max_health=100,
            dedication=relations.DEDICATION.random(),
            archetype=game_relations.ARCHETYPE.random(),
            mode=relations.MODE.random(),
            abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
            communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
            communication_gestures=game_relations.COMMUNICATION_GESTURES.
            random(),
            communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.
            random(),
            intellect_level=game_relations.INTELLECT_LEVEL.random(),
            state=relations.STATE.ENABLED)

        self.companion_2 = logic.create_companion_record(
            utg_name=names.generator().get_test_name('c-2'),
            description='companion-description-2',
            type=game_relations.BEING_TYPE.random(),
            max_health=100,
            dedication=relations.DEDICATION.random(),
            archetype=game_relations.ARCHETYPE.random(),
            mode=relations.MODE.random(),
            abilities=helpers.FAKE_ABILITIES_CONTAINER_2,
            communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
            communication_gestures=game_relations.COMMUNICATION_GESTURES.
            random(),
            communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.
            random(),
            intellect_level=game_relations.INTELLECT_LEVEL.random(),
            state=relations.STATE.DISABLED)

        self.requested_url_1 = url('game:companions:info', self.companion_1.id)
        self.requested_url_2 = url('game:companions:info', self.companion_2.id)

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()
        self.account_3 = self.accounts_factory.create_account()

        group_edit = sync_group('edit companions',
                                ['companions.create_companionrecord'])
        group_edit.user_set.add(self.account_2._model)

        group_moderate = sync_group('moderate companions',
                                    ['companions.moderate_companionrecord'])
        group_moderate.user_set.add(self.account_3._model)
Example #13
0
    def test_amortization_grows(self):
        building = logic.create_building(self.place_1.persons[0], utg_name=names.generator().get_test_name(name='building-name'))

        old_integrity = building.integrity
        building.amortize(1000)
        amortization_delta = old_integrity - building.integrity

        building_2 = logic.create_building(self.place_1.persons[1], utg_name=names.generator().get_test_name(name='building-name-2'))

        old_integrity_2 = building_2.integrity
        building_2.amortize(1000)
        amortization_delta_2 = old_integrity_2 - building_2.integrity

        self.assertTrue(amortization_delta < amortization_delta_2)
Example #14
0
    def create_random(cls, uuid, type=game_relations.BEING_TYPE.CIVILIZED, level=1, abilities_number=3, terrains=map_relations.TERRAIN.records, state=relations.MOB_RECORD_STATE.ENABLED, global_action_probability=0, is_mercenary=True, is_eatable=True): # pylint: disable=W0102

        name = uuid.lower()

        utg_name = names.generator().get_test_name(name=name)

        battle_abilities = cls.get_available_abilities()
        battle_abilities = set([a.get_id() for a in battle_abilities])

        abilities = set(['hit'])

        for i in range(abilities_number-1): # pylint: disable=W0612
            abilities.add(random.choice(list(battle_abilities-abilities)))

        return cls.create(uuid,
                          level=level,
                          type=type,
                          utg_name=utg_name,
                          description='description of %s' % name,
                          abilities=abilities,
                          terrains=terrains,
                          state=state,
                          global_action_probability=global_action_probability,
                          is_mercenary=is_mercenary,
                          is_eatable=is_eatable)
Example #15
0
    def setUp(self):
        super(UseCardTaskTests, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account = self.accounts_factory.create_account()
        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.building_1 = places_logic.create_building(
            person=self.place_1.persons[0],
            utg_name=names.generator().get_test_name('building-1-name'))

        environment.deinitialize()
        environment.initialize()

        self.highlevel = environment.workers.highlevel
        self.highlevel.process_initialize(0, 'highlevel')

        self.task_data = {
            'place_id': self.place_1.id,
            'person_id': self.place_1.persons[0].id,
            'building_id': self.building_1.id
        }
    def setUp(self):
        super(BuildingRepairTest, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account(is_fast=True)

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.ability_1 = self.PROCESSOR()
        self.ability_2 = self.PROCESSOR()

        environment.deinitialize()
        environment.initialize()

        self.highlevel = environment.workers.highlevel
        self.highlevel.process_initialize(0, 'highlevel')

        self.building = BuildingPrototype.create(
            self.place_1.persons[0],
            utg_name=names.generator().get_test_name('building-name'))
        self.building._model.integrity = 0.5
        self.building.save()
Example #17
0
def create_random_companion_record(
        name,
        type=game_relations.BEING_TYPE.CIVILIZED,
        max_health=int(c.COMPANIONS_MEDIUM_HEALTH),
        dedication=relations.DEDICATION.BRAVE,
        archetype=game_relations.ARCHETYPE.NEUTRAL,
        state=relations.STATE.DISABLED,
        abilities=abilities_container.Container(),
        mode=relations.MODE.AUTOMATIC,
        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.LOW):
    return create_companion_record(
        utg_name=names.generator().get_test_name(name=name),
        description='description-%s' % name,
        type=type,
        max_health=max_health,
        dedication=dedication,
        archetype=archetype,
        mode=mode,
        abilities=abilities,
        state=state,
        communication_verbal=communication_verbal,
        communication_gestures=communication_gestures,
        communication_telepathic=communication_telepathic,
        intellect_level=intellect_level)
Example #18
0
def create_random_companion_record(name,
                                   type=game_relations.BEING_TYPE.CIVILIZED,
                                   max_health=int(c.COMPANIONS_MEDIUM_HEALTH),
                                   dedication=relations.DEDICATION.BRAVE,
                                   archetype=game_relations.ARCHETYPE.NEUTRAL,
                                   state=relations.STATE.DISABLED,
                                   abilities=abilities_container.Container(),
                                   mode=relations.MODE.AUTOMATIC,
                                   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.LOW):
    return create_companion_record(utg_name=names.generator().get_test_name(name=name),
                                   description='description-%s' % name,
                                   type=type,
                                   max_health=max_health,
                                   dedication=dedication,
                                   archetype=archetype,
                                   mode=mode,
                                   abilities=abilities,
                                   state=state,
                                   communication_verbal=communication_verbal,
                                   communication_gestures=communication_gestures,
                                   communication_telepathic=communication_telepathic,
                                   intellect_level=intellect_level)
    def setUp(self):
        super(BaseEffectsTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.companion_record = logic.create_companion_record(utg_name=names.generator().get_test_name(),
                                                              description='description',
                                                              type=beings_relations.TYPE.random(),
                                                              max_health=10,
                                                              dedication=relations.DEDICATION.random(),
                                                              archetype=game_relations.ARCHETYPE.random(),
                                                              mode=relations.MODE.random(),
                                                              abilities=abilities_container.Container(),
                                                              communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(),
                                                              communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(),
                                                              communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(),
                                                              intellect_level=beings_relations.INTELLECT_LEVEL.random(),
                                                              structure=beings_relations.STRUCTURE.random(),
                                                              features=frozenset((beings_relations.FEATURE.random(), beings_relations.FEATURE.random())),
                                                              movement=beings_relations.MOVEMENT.random(),
                                                              body=beings_relations.BODY.random(),
                                                              size=beings_relations.SIZE.random(),
                                                              weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.random(),
                                                                                                material= tt_artifacts_relations.MATERIAL.random(),
                                                                                                power_type=artifacts_relations.ARTIFACT_POWER_TYPE.random())],
                                                              state=relations.STATE.ENABLED)
        self.hero.set_companion(logic.create_companion(self.companion_record))
Example #20
0
    def test_create_companion_record__linguistics_restriction_setupped(self):
        with mock.patch('the_tale.linguistics.logic.sync_restriction'
                        ) as sync_restriction:
            companion_record = logic.create_companion_record(
                utg_name=names.generator().get_test_name(),
                description='description',
                type=game_relations.BEING_TYPE.random(),
                max_health=10,
                dedication=relations.DEDICATION.random(),
                archetype=game_relations.ARCHETYPE.random(),
                mode=relations.MODE.random(),
                abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                communication_verbal=game_relations.COMMUNICATION_VERBAL.
                random(),
                communication_gestures=game_relations.COMMUNICATION_GESTURES.
                random(),
                communication_telepathic=game_relations.
                COMMUNICATION_TELEPATHIC.random(),
                intellect_level=game_relations.INTELLECT_LEVEL.random(),
                state=relations.STATE.ENABLED)

        self.assertEqual(sync_restriction.call_args_list, [
            mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.
                      COMPANION,
                      external_id=companion_record.id,
                      name=companion_record.name)
        ])
Example #21
0
    def setUp(self):
        super(BaseEffectsTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.companion_record = logic.create_companion_record(
            utg_name=names.generator().get_test_name(),
            description='description',
            type=game_relations.BEING_TYPE.random(),
            max_health=10,
            dedication=relations.DEDICATION.random(),
            archetype=game_relations.ARCHETYPE.random(),
            mode=relations.MODE.random(),
            abilities=abilities_container.Container(),
            communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
            communication_gestures=game_relations.COMMUNICATION_GESTURES.
            random(),
            communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.
            random(),
            intellect_level=game_relations.INTELLECT_LEVEL.random(),
            state=relations.STATE.ENABLED)
        self.hero.set_companion(logic.create_companion(self.companion_record))
Example #22
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)

        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-нс,ед,им')
Example #23
0
    def test_apply_bills__stop_bill_without_meaning(self):
        from the_tale.forum.models import Category, SubCategory

        forum_category = Category.objects.create(caption='category-1', slug='category-1')
        SubCategory.objects.create(caption=bills_settings.FORUM_CATEGORY_UID + '-caption',
                                   uid=bills_settings.FORUM_CATEGORY_UID,
                                   category=forum_category)

        new_name = names.generator().get_test_name('new-new-name')

        bill_data_1 = bills.PlaceRenaming(place_id=self.p1.id, name_forms=new_name)
        bill_1 = bills_prototypes.BillPrototype.create(self.account, 'bill-1-caption', 'bill-1-rationale', bill_data_1, chronicle_on_accepted='chronicle-on-accepted')
        bill_1.approved_by_moderator = True
        bill_1.save()

        bill_data_2 = bills.PlaceRenaming(place_id=self.p1.id, name_forms=new_name)
        bill_2 = bills_prototypes.BillPrototype.create(self.account, 'bill-2-caption', 'bill-2-rationale', bill_data_2, chronicle_on_accepted='chronicle-on-accepted')
        bill_2.approved_by_moderator = True
        bill_2.save()

        self.worker.apply_bills()

        bill_1.reload()
        bill_2.reload()

        self.assertTrue(bill_1.state.is_ACCEPTED)
        self.assertTrue(bill_2.state.is_STOPPED)
Example #24
0
    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)
Example #25
0
    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)
Example #26
0
    def setUp(self):
        super(EnableRequestsTests, self).setUp()

        self.companion_1 = logic.create_companion_record(utg_name=names.generator().get_test_name('c-1'),
                                                         description='companion-description-1',
                                                         type=game_relations.BEING_TYPE.random(),
                                                         max_health=100,
                                                         dedication=relations.DEDICATION.random(),
                                                         archetype=game_relations.ARCHETYPE.random(),
                                                         abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                                                         mode=relations.MODE.random(),
                                                         communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
                                                         communication_gestures=game_relations.COMMUNICATION_GESTURES.random(),
                                                         communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(),
                                                         intellect_level=game_relations.INTELLECT_LEVEL.random(),
                                                         state=relations.STATE.DISABLED)

        self.requested_url = url('game:companions:enable', self.companion_1.id)

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account()
        self.account_3 = self.accounts_factory.create_account()

        group_edit = sync_group('edit companions', ['companions.create_companionrecord'])
        group_edit.user_set.add(self.account_2._model)

        group_edit = sync_group('moderate companions', ['companions.moderate_companionrecord'])
        group_edit.user_set.add(self.account_3._model)
Example #27
0
    def test_create_companion(self):
        companion_record = logic.create_companion_record(utg_name=names.generator().get_test_name(),
                                                         description='description',
                                                         type=beings_relations.TYPE.random(),
                                                         max_health=10,
                                                         dedication=relations.DEDICATION.random(),
                                                         archetype=game_relations.ARCHETYPE.random(),
                                                         mode=relations.MODE.random(),
                                                         abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                                                         communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(),
                                                         communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(),
                                                         communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(),
                                                         intellect_level=beings_relations.INTELLECT_LEVEL.random(),
                                                         structure=beings_relations.STRUCTURE.random(),
                                                         features=frozenset((beings_relations.FEATURE.random(), beings_relations.FEATURE.random())),
                                                         movement=beings_relations.MOVEMENT.random(),
                                                         body=beings_relations.BODY.random(),
                                                         size=beings_relations.SIZE.random(),
                                                         weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.random(),
                                                                                           material=tt_artifacts_relations.MATERIAL.random(),
                                                                                           power_type=artifacts_relations.ARTIFACT_POWER_TYPE.random())],
                                                         state=relations.STATE.ENABLED)

        companion = logic.create_companion(companion_record)

        self.assertEqual(companion.record.id, companion_record.id)
        self.assertEqual(companion.health, companion_record.max_health)
        self.assertEqual(companion.coherence, 0)
Example #28
0
    def test_filter_by_state(self):
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        bill_voting, bill_accepted, bill_rejected = self.create_bills(3, self.account1, 'Caption-%d', 'rationale-%d', bill_data)

        bill_accepted.state = BILL_STATE.ACCEPTED
        bill_accepted._model.voting_end_at = datetime.datetime.now()
        bill_accepted.applyed_at_turn = 0
        bill_accepted.save()

        bill_rejected.state = BILL_STATE.REJECTED
        bill_rejected._model.voting_end_at = datetime.datetime.now()
        bill_rejected.applyed_at_turn = 0
        bill_rejected.save()

        def check_state_filter(self, state, voting_number, accepted_number, rejected_number):
            url = reverse('game:bills:')
            if state is not None:
                url += ('?state=%d' % state.value)
            self.check_html_ok(self.request_html(url),
                               texts=[('Caption-0', voting_number),
                                      ('Caption-1', accepted_number),
                                      ('Caption-2', rejected_number)])

        check_state_filter(self, BILL_STATE.VOTING, 1, 0, 0)
        check_state_filter(self, BILL_STATE.ACCEPTED, 0, 1, 0)
        check_state_filter(self, BILL_STATE.REJECTED, 0, 0, 1)
        check_state_filter(self, None, 1, 1, 1)
Example #29
0
    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)
Example #30
0
    def test_forum_vote_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_2,
            'caption',
            'rationale',
            bill_data,
            chronicle_on_accepted='chronicle-on-accepted')
        bill.state = BILL_STATE.REJECTED
        bill.save()

        Post.objects.all().delete()
        Thread.objects.all().delete()
        Vote.objects.all().delete()

        self.assertEqual(calculate_might(self.account_2), old_might)
        self.assertEqual(calculate_might(self.account), 0)

        VotePrototype.create(self.account, bill, VOTE_TYPE.FOR)
        self.assertTrue(calculate_might(self.account) > 0)

        Vote.objects.all().delete()
        VotePrototype.create(self.account, bill, VOTE_TYPE.AGAINST)
        self.assertTrue(calculate_might(self.account) > 0)

        Vote.objects.all().delete()
        VotePrototype.create(self.account, bill, VOTE_TYPE.REFRAINED)
        self.assertEqual(calculate_might(self.account), 0)
Example #31
0
    def test_one_page(self):
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(2, self.account1, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill_data = PlaceRenaming(place_id=self.place2.id, name_forms=names.generator().get_test_name('new_name_2'))
        self.create_bills(3, self.account2, 'Caption-a2-%d', 'rationale-a2-%d', bill_data)

        texts = [('pgf-no-bills-message', 0),
                 ('Caption-a1-0', 1), ('rationale-a1-0', 0),
                 ('Caption-a1-1', 1), ('rationale-a1-1', 0),
                 ('Caption-a2-0', 1), ('rationale-a2-0', 0),
                 ('Caption-a2-1', 1), ('rationale-a2-1', 0),
                 ('Caption-a2-2', 1), ('rationale-a2-2', 0),
                 (self.account1.nick, 3),
                 (self.account2.nick, 3)]

        self.check_html_ok(self.request_html(reverse('game:bills:')), texts=texts)
Example #32
0
    def create_random(cls,
                      uuid,
                      type=game_relations.BEING_TYPE.CIVILIZED,
                      level=1,
                      abilities_number=3,
                      terrains=map_relations.TERRAIN.records,
                      state=relations.MOB_RECORD_STATE.ENABLED,
                      global_action_probability=0,
                      is_mercenary=True,
                      is_eatable=True):  # pylint: disable=W0102

        name = uuid.lower()

        utg_name = names.generator().get_test_name(name=name)

        battle_abilities = cls.get_available_abilities()
        battle_abilities = set([a.get_id() for a in battle_abilities])

        abilities = set(['hit'])

        for i in range(abilities_number - 1):  # pylint: disable=W0612
            abilities.add(random.choice(list(battle_abilities - abilities)))

        return cls.create(uuid,
                          level=level,
                          type=type,
                          utg_name=utg_name,
                          description='description of %s' % name,
                          abilities=abilities,
                          terrains=terrains,
                          state=state,
                          global_action_probability=global_action_probability,
                          is_mercenary=is_mercenary,
                          is_eatable=is_eatable)
Example #33
0
    def setUp(self):
        super(BuildingRepairTest, self).setUp()

        self.place_1, self.place_2, self.place_3 = create_test_map()

        self.account_1 = self.accounts_factory.create_account()
        self.account_2 = self.accounts_factory.create_account(is_fast=True)

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account_1)
        self.storage.load_account_data(self.account_2)

        self.hero_1 = self.storage.accounts_to_heroes[self.account_1.id]
        self.hero_2 = self.storage.accounts_to_heroes[self.account_2.id]

        self.ability_1 = self.PROCESSOR()
        self.ability_2 = self.PROCESSOR()

        environment.deinitialize()
        environment.initialize()

        self.highlevel = environment.workers.highlevel
        self.highlevel.process_initialize(0, 'highlevel')

        self.building = BuildingPrototype.create(self.place_1.persons[0], utg_name=names.generator().get_test_name('building-name'))
        self.building._model.integrity = 0.5
        self.building.save()
    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_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())
Example #36
0
    def test_unlogined(self):
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account1, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.request_logout()
        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-unlogined-message', 1),))
Example #37
0
    def setUp(self):
        super(BaseEffectsTests, self).setUp()

        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.storage = LogicStorage()
        self.storage.load_account_data(self.account)
        self.hero = self.storage.accounts_to_heroes[self.account.id]

        self.companion_record = logic.create_companion_record(utg_name=names.generator().get_test_name(),
                                                              description='description',
                                                              type=game_relations.BEING_TYPE.random(),
                                                              max_health=10,
                                                              dedication=relations.DEDICATION.random(),
                                                              archetype=game_relations.ARCHETYPE.random(),
                                                              mode=relations.MODE.random(),
                                                              abilities=abilities_container.Container(),
                                                              communication_verbal=game_relations.COMMUNICATION_VERBAL.random(),
                                                              communication_gestures=game_relations.COMMUNICATION_GESTURES.random(),
                                                              communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(),
                                                              intellect_level=game_relations.INTELLECT_LEVEL.random(),
                                                              state=relations.STATE.ENABLED)
        self.hero.set_companion(logic.create_companion(self.companion_record))
Example #38
0
    def test_create_companion_record__linguistics_restriction_setupped(self):
        with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction:
            companion_record = logic.create_companion_record(utg_name=names.generator().get_test_name(),
                                                            description='description',
                                                            type=beings_relations.TYPE.random(),
                                                            max_health=10,
                                                            dedication=relations.DEDICATION.random(),
                                                            archetype=game_relations.ARCHETYPE.random(),
                                                            mode=relations.MODE.random(),
                                                            abilities=helpers.FAKE_ABILITIES_CONTAINER_1,
                                                            communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(),
                                                            communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(),
                                                            communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(),
                                                            intellect_level=beings_relations.INTELLECT_LEVEL.random(),
                                                            structure=beings_relations.STRUCTURE.STRUCTURE_2,
                                                            features=frozenset((beings_relations.FEATURE.FEATURE_1, beings_relations.FEATURE.FEATURE_3)),
                                                            movement=beings_relations.MOVEMENT.MOVEMENT_4,
                                                            body=beings_relations.BODY.BODY_5,
                                                            size=beings_relations.SIZE.SIZE_6,
                                                            weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.WEAPON_1,
                                                                                              material=tt_artifacts_relations.MATERIAL.MATERIAL_1,
                                                                                              power_type=artifacts_relations.ARTIFACT_POWER_TYPE.NEUTRAL),
                                                                     artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.WEAPON_3,
                                                                                              material=tt_artifacts_relations.MATERIAL.MATERIAL_3,
                                                                                              power_type=artifacts_relations.ARTIFACT_POWER_TYPE.MOST_PHYSICAL)],
                                                            state=relations.STATE.ENABLED,)

        self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.COMPANION,
                                                                     external_id=companion_record.id,
                                                                     name=companion_record.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())
Example #40
0
 def add_person_to_place(self, place):
     persons_logic.create_person(
         place=place,
         race=game_relations.RACE.random(),
         gender=game_relations.GENDER.random(),
         type=persons_relations.PERSON_TYPE.random(),
         utg_name=names.generator().get_test_name())
Example #41
0
    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 setUp(self):
        super(BuildingCreateTests, self).setUp()

        self.person_1 = sorted(self.place1.persons,
                               key=lambda person: -politic_power_storage.
                               persons.total_power_fraction(person.id))[0]
        self.person_2 = sorted(self.place2.persons,
                               key=lambda person: -politic_power_storage.
                               persons.total_power_fraction(person.id))[-1]

        self.accepted_position_1 = random.choice(
            list(
                places_logic.get_available_positions(
                    center_x=self.person_1.place.x,
                    center_y=self.person_1.place.y)))
        self.accepted_position_2 = random.choice(
            list(
                places_logic.get_available_positions(
                    center_x=self.person_2.place.x,
                    center_y=self.person_2.place.y)))

        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'),
            x=self.accepted_position_1[0],
            y=self.accepted_position_1[1])
        self.bill = BillPrototype.create(
            self.account1,
            'bill-1-caption',
            self.bill_data,
            chronicle_on_accepted='chronicle-on-accepted')
    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-нс,ед,им')
Example #44
0
    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()
Example #45
0
    def create_bill(self, index, owner, state):
        from the_tale.game.bills.bills import PlaceRenaming
        from the_tale.game.bills.prototypes import BillPrototype

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_%d' % index))
        bill = BillPrototype.create(owner, 'bill-%d-caption' % index, 'bill-%d-rationale' % index, bill_data, chronicle_on_accepted='chronicle-on-accepted')
        bill.state = state
        bill.save()
Example #46
0
    def test_can_not_participate_in_politics(self):
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account2, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.account1.prolong_premium(-100)
        self.account1.save()
        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-participate-in-politics', 1),))
Example #47
0
def create_person(place):
    race = random.choice(RACE.records)
    gender = random.choice((GENDER.MASCULINE, GENDER.FEMININE))
    return logic.create_person(place,
                               race=race,
                               type=random.choice(PERSON_TYPE.records),
                               utg_name=names.generator().get_name(race, gender),
                               gender=gender)
Example #48
0
    def test_can_not_voted(self):
        self.assertEqual(heroes_logic.load_hero(account_id=self.account1.id).places_history.history, collections.deque([], maxlen=200))

        # one vote automaticaly created for bill author
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account1, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 0),))
Example #49
0
    def test_filter_by_type(self):
        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(3, self.account1, 'Caption-%d', 'rationale-%d', bill_data)

        self.check_html_ok(self.request_html(reverse('game:bills:')+('?bill_type=%d' % PlaceRenaming.type.value)),
                           texts=[('pgf-no-bills-message', 0),
                                  ('Caption-0', 1),
                                  ('Caption-1', 1),
                                  ('Caption-2', 1)])
Example #50
0
    def deserialize(cls, data):
        obj = super(BuildingDestroy, cls).deserialize(data)

        if 'building_name_forms' in data:
            obj.building_name_forms = utg_words.Word.deserialize(data['building_name_forms'])
        else:
            obj.building_name_forms = names.generator().get_fast_name('название неизвестно')

        return obj
Example #51
0
    def test_can_not_vote(self):
        self.hero.places_history._reset()
        heroes_logic.save_hero(self.hero)

        bill_data = PlaceRenaming(place_id=self.place1.id, name_forms=names.generator().get_test_name('new_name_1'))
        self.create_bills(1, self.account2, 'Caption-a1-%d', 'rationale-a1-%d', bill_data)
        bill = Bill.objects.all()[0]

        self.check_html_ok(self.request_html(reverse('game:bills:show', args=[bill.id])), texts=(('pgf-can-not-vote-message', 1),))
Example #52
0
    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
Example #53
0
    def setUp(self):
        super(TestPrototypeEnd, 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.state = relations.BILL_STATE.ACCEPTED

        TimePrototype.get_current_time().increment_turn()
Example #54
0
    def test_linguistics_restrictions_update_on_save(self):
        mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED)
        mob.set_utg_name(names.generator().get_test_name('new-name'))

        with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction:
            mob.save()

        self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB,
                                                                     external_id=mob.id,
                                                                     name=mob.name)])
Example #55
0
    def test_linguistics_restriction_version_update_on_save(self):
        artifact = ArtifactRecordPrototype.create_random(uuid='bandit_loot')
        artifact.set_utg_name(names.generator().get_test_name('new-name'))

        with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction:
            artifact.save()

        self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.ARTIFACT,
                                                                     external_id=artifact.id,
                                                                     name=artifact.name)])