Example #1
0
    def test_push_action(self):
        self.assertEqual([a.data for a in self.container.actions_list],
                         [None, 2, 3])

        TestAction.create(hero=self.hero, data=4)

        self.assertEqual([a.data for a in self.container.actions_list],
                         [None, 2, 3, 4])
Example #2
0
    def test_push_action(self):
        self.assertEqual([a.data for a in self.container.actions_list], [None, 2, 3])

        self.container.updated = False

        TestAction.create(hero=self.hero, data=4)

        self.assertTrue(self.container.updated)

        self.assertEqual([a.data for a in self.container.actions_list], [None, 2, 3, 4])
Example #3
0
    def setUp(self):
        super(ActionsContainerTests, self).setUp()

        create_test_map()

        account = self.accounts_factory.create_account(is_fast=True)

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

        self.container = self.hero.actions

        self.action_1 = self.container.current_action
        self.action_2 = TestAction.create(hero=self.hero, data=2)
        self.action_3 = TestAction.create(hero=self.hero, data=3)
Example #4
0
    def test_action_default_serialization(self):
        # class TestAction(ActionBase):
        #     TYPE = 'test-action'

        default_action = TestAction( hero=self.hero,
                                     bundle_id=self.bundle_id,
                                     state=TestAction.STATE.UNINITIALIZED)

        self.assertEqual(default_action.serialize(), {'bundle_id': self.bundle_id,
                                                      'state': TestAction.STATE.UNINITIALIZED,
                                                      'percents': 0.0,
                                                      'description': None,
                                                      'type': TestAction.TYPE.value,
                                                      'created_at_turn': TimePrototype.get_current_turn_number()})

        self.assertEqual(default_action, TestAction.deserialize(self.hero, default_action.serialize()))
Example #5
0
    def setUp(self):
        super(ActionsContainerTests, self).setUp()

        create_test_map()

        account = self.accounts_factory.create_account(is_fast=True)

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

        self.container = self.hero.actions

        self.action_1 = self.container.current_action
        self.action_2 = TestAction.create(hero=self.hero, data=2)
        self.action_3 = TestAction.create(hero=self.hero, data=3)
Example #6
0
    def test_is_single__push_and_pop_action(self):
        while self.container.number > 1:
            self.container.pop_action()

        self.assertTrue(self.container.is_single)

        TestAction.create(hero=self.hero, data=4, single=False)
        self.assertFalse(self.container.is_single)

        TestAction.create(hero=self.hero, data=4, single=True)
        self.assertFalse(self.container.is_single)

        self.container.pop_action()
        self.assertFalse(self.container.is_single)

        self.container.pop_action()
        self.assertTrue(self.container.is_single)
Example #7
0
    def setUp(self):
        super(ActionsContainerTests, self).setUp()
        create_test_map()

        result, account_id, bundle_id = register_user('test_user')

        self.bundle_id = bundle_id

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]

        self.container = self.hero.actions

        self.action_1 = self.container.current_action
        self.action_2 = TestAction.create(hero=self.hero, data=2)
        self.action_3 = TestAction.create(hero=self.hero, data=3)
Example #8
0
    def test_is_single__push_and_pop_action(self):
        while self.container.number > 1:
            self.container.pop_action()

        self.assertTrue(self.container.is_single)

        TestAction.create(hero=self.hero, data=4, single=False)
        self.assertFalse(self.container.is_single)

        TestAction.create(hero=self.hero, data=4, single=True)
        self.assertFalse(self.container.is_single)

        self.container.pop_action()
        self.assertFalse(self.container.is_single)

        self.container.pop_action()
        self.assertTrue(self.container.is_single)
Example #9
0
    def setUp(self):
        super(ActionsContainerTests, self).setUp()
        create_test_map()

        result, account_id, bundle_id = register_user('test_user')

        self.bundle_id = bundle_id

        self.storage = LogicStorage()
        self.storage.load_account_data(AccountPrototype.get_by_id(account_id))
        self.hero = self.storage.accounts_to_heroes[account_id]

        self.container = self.hero.actions

        self.action_1 = self.container.current_action
        self.action_2 = TestAction.create(hero=self.hero, data=2)
        self.action_3 = TestAction.create(hero=self.hero, data=3)
Example #10
0
    def test_action_full_serialization(self):
        mob = mobs_storage.create_mob_for_hero(self.hero)

        default_action = TestAction( hero=self.hero,
                                     bundle_id=self.bundle_id,
                                     state=TestAction.STATE.UNINITIALIZED,
                                     created_at_turn=666,
                                     context=TestAction.CONTEXT_MANAGER(),
                                     description=u'description',
                                     place_id=2,
                                     mob=mob,
                                     data={'xxx': 'yyy'},
                                     break_at=0.75,
                                     length=777,
                                     destination_x=20,
                                     destination_y=30,
                                     percents_barier=77,
                                     extra_probability=0.6,
                                     mob_context=TestAction.CONTEXT_MANAGER(),
                                     textgen_id='textgen_id',
                                     back=True,
                                     info_link='/bla-bla',
                                     meta_action_id=7,
                                     replane_required=True)

        self.assertEqual(default_action.serialize(), {'bundle_id': self.bundle_id,
                                                      'state': TestAction.STATE.UNINITIALIZED,
                                                      'context': TestAction.CONTEXT_MANAGER().serialize(),
                                                      'mob_context': TestAction.CONTEXT_MANAGER().serialize(),
                                                      'mob': mob.serialize(),
                                                      'meta_action_id': 7,
                                                      'length': 777,
                                                      'back': True,
                                                      'textgen_id': 'textgen_id',
                                                      'extra_probability': 0.6,
                                                      'percents_barier': 77,
                                                      'destination_x': 20,
                                                      'destination_y': 30,
                                                      'percents': 0.0,
                                                      'description': u'description',
                                                      'type': TestAction.TYPE.value,
                                                      'created_at_turn': 666,
                                                      'place_id': 2,
                                                      'data': {'xxx': 'yyy'},
                                                      'info_link': '/bla-bla',
                                                      'break_at': 0.75,
                                                      'replane_required': True})

        self.assertEqual(default_action, TestAction.deserialize(self.hero, default_action.serialize()))