Example #1
0
    def index(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(
                url('collections:collections:', account=self.account.id))

        self.master_account = account

        master_account_items = None
        last_items = []
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(
                self.master_account.id)
            last_items = master_account_items.last_items(
                number=collections_settings.LAST_ITEMS_NUMBER)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(
                self.account.id)

        collections_statistics = get_collections_statistics(
            account_items=master_account_items)

        collections_table = split_into_table(self.collections, 3)

        return self.template(
            'collections/collections/index.html', {
                'collections_statistics': collections_statistics,
                'collections_table': collections_table,
                'account_items': account_items,
                'master_account_items': master_account_items,
                'last_items': last_items
            })
Example #2
0
    def index(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(url('collections:collections:', account=self.account.id))

        self.master_account = account

        master_account_items = None
        last_items = []
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(self.master_account.id)
            last_items = master_account_items.last_items(number=collections_settings.LAST_ITEMS_NUMBER)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(self.account.id)

        collections_statistics = get_collections_statistics(account_items=master_account_items)

        collections_table = split_into_table(self.collections, 3)


        return self.template('collections/collections/index.html',
                             {'collections_statistics': collections_statistics,
                              'collections_table': collections_table,
                              'account_items': account_items,
                              'master_account_items': master_account_items,
                              'last_items': last_items})
Example #3
0
    def test_successfull_result(self):

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
        self.assertEqual(AccountItemsPrototype._db_count(), 0)

        result, account_id, bundle_id = register_user('test_user',
                                                      '*****@*****.**',
                                                      '111111')

        # test result
        self.assertEqual(result, REGISTER_USER_RESULT.OK)
        self.assertTrue(bundle_id is not None)

        #test basic structure
        account = AccountPrototype.get_by_id(account_id)

        self.assertEqual(account.nick, 'test_user')
        self.assertEqual(account.email, '*****@*****.**')

        self.assertTrue(not account.is_fast)

        hero = HeroPrototype.get_by_account_id(account.id)

        # test hero equipment
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.PANTS).id, 'default_pants')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.BOOTS).id, 'default_boots')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.PLATE).id, 'default_plate')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.GLOVES).id, 'default_gloves')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.HAND_PRIMARY).id,
            'default_weapon')

        self.assertTrue(
            hero.equipment.get(EQUIPMENT_SLOT.HAND_SECONDARY) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HELMET) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.SHOULDERS) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.CLOAK) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.AMULET) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.RING) is None)

        self.assertEqual(HeroPreferencesPrototype._db_count(), 1)
        self.assertEqual(
            HeroPreferencesPrototype.get_by_hero_id(
                hero.id).energy_regeneration_type,
            hero.preferences.energy_regeneration_type)

        self.assertEqual(account.referer, None)
        self.assertEqual(account.referer_domain, None)
        self.assertEqual(account.referral_of_id, None)
        self.assertEqual(account.action_id, None)

        self.assertEqual(account.is_bot, False)

        self.assertEqual(AccountAchievementsPrototype._db_count(), 1)
        self.assertEqual(AccountItemsPrototype._db_count(), 1)
        self.assertEqual(market_models.Goods.objects.count(), 1)
Example #4
0
def register_user(nick,
                  email=None,
                  password=None,
                  referer=None,
                  referral_of_id=None,
                  action_id=None,
                  is_bot=False,
                  gender=game_relations.GENDER.MASCULINE,
                  full_create=True):
    from the_tale.game import tt_api as game_tt_api
    from the_tale.game.heroes import logic as heroes_logic
    from the_tale.game.balance import constants as c

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id,
                                      gender=gender)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    hero = heroes_logic.create_hero(account=account, full_create=full_create)

    if full_create:
        game_tt_api.change_energy_balance(account_id=account.id,
                                          type='initial_contribution',
                                          energy=c.INITIAL_ENERGY_AMOUNT,
                                          async=False,
                                          autocommit=True)

        tt_api.create_cards_timer(account_id=account.id)

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
Example #5
0
    def show(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(
                url('collections:collections:show',
                    self.collection.id,
                    account=self.account.id))

        self.master_account = account

        master_account_items = None
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(
                self.master_account.id)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(
                self.account.id)

        collections_statistics = get_collections_statistics(
            account_items=master_account_items)

        kits = sorted([
            kit for kit in kits_storage.all()
            if kit.collection_id == self.collection.id
        ],
                      key=lambda k: k.caption)

        if not (self.can_edit_kit or self.can_moderate_kit):
            kits = [kit for kit in kits if kit.approved]

        items = {kit.id: [] for kit in kits}

        items_query = items_storage.all()

        if not self.edit_item_permission and not self.moderate_item_permission:
            items_query = (item for item in items_query if item.approved)

        items_query = sorted(
            [item for item in items_query if item.kit_id in items],
            key=lambda i: i.caption)

        for item in items_query:
            items[item.kit_id].append(item)

        return self.template(
            'collections/collections/show.html', {
                'kits': kits,
                'items': items,
                'account_items': account_items,
                'master_account_items': master_account_items,
                'collections_statistics': collections_statistics
            })
Example #6
0
    def test_successfull_result(self):

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
        self.assertEqual(AccountItemsPrototype._db_count(), 0)

        result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')

        # test result
        self.assertEqual(result, REGISTER_USER_RESULT.OK)
        self.assertTrue(bundle_id is not None)


        #test basic structure
        account = AccountPrototype.get_by_id(account_id)

        self.assertEqual(account.nick, 'test_user')
        self.assertEqual(account.email, '*****@*****.**')

        self.assertTrue(not account.is_fast)

        hero = HeroPrototype.get_by_account_id(account.id)

        # test hero equipment
        self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.PANTS).id, 'default_pants')
        self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.BOOTS).id, 'default_boots')
        self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.PLATE).id, 'default_plate')
        self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.GLOVES).id, 'default_gloves')
        self.assertEqual(hero.equipment.get(EQUIPMENT_SLOT.HAND_PRIMARY).id, 'default_weapon')

        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HAND_SECONDARY) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HELMET) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.SHOULDERS) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.CLOAK) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.AMULET) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.RING) is None)

        self.assertEqual(HeroPreferencesPrototype._db_count(), 1)
        self.assertEqual(HeroPreferencesPrototype.get_by_hero_id(hero.id).energy_regeneration_type,
                         hero.preferences.energy_regeneration_type)

        self.assertEqual(account.referer, None)
        self.assertEqual(account.referer_domain, None)
        self.assertEqual(account.referral_of_id, None)
        self.assertEqual(account.action_id, None)

        self.assertEqual(account.is_bot, False)

        self.assertEqual(AccountAchievementsPrototype._db_count(), 1)
        self.assertEqual(AccountItemsPrototype._db_count(), 1)
        self.assertEqual(market_models.Goods.objects.count(), 1)
Example #7
0
def register_user(nick,
                  email=None,
                  password=None,
                  referer=None,
                  referral_of_id=None,
                  action_id=None,
                  is_bot=False):
    from the_tale.game.heroes import logic as heroes_logic

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    market_logic.create_goods(account.id)

    hero = heroes_logic.create_hero(account=account)

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
Example #8
0
    def setUp(self):
        super(ItemsManagerTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption='kit_3', description='description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption='item_2_2', text='text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption='item_3_1', text='text_3_1', approved=True)

        self.account_1_items.add_item(self.item_1_2)
        self.account_1_items.save()

        self.worker = environment.workers.items_manager
        self.worker.initialize()
Example #9
0
    def setUp(self):
        super(ItemsManagerTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption=u'kit_2', description=u'description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption=u'kit_3', description=u'description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_1', text=u'text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_2', text=u'text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption=u'item_3_1', text=u'text_3_1', approved=True)

        self.account_1_items.add_item(self.item_1_2)
        self.account_1_items.save()

        self.worker = environment.workers.items_manager
        self.worker.initialize()
Example #10
0
def get_account_info(account, hero):
    from the_tale.game.ratings import prototypes as ratings_prototypes
    from the_tale.game.ratings import relations as ratings_relations

    ratings = {}

    rating_places = ratings_prototypes.RatingPlacesPrototype.get_by_account_id(account.id)

    rating_values = ratings_prototypes.RatingValuesPrototype.get_by_account_id(account.id)

    if rating_values and rating_places:
        for rating in ratings_relations.RATING_TYPE.records:
            ratings[rating.value] = {'name': rating.text,
                                     'place': getattr(rating_places, '%s_place' % rating.field, None),
                                     'value': getattr(rating_values, rating.field, None)}

    places_history = [{'place': {'id': place.id, 'name': place.name}, 'count': help_count} for place, help_count in hero.places_history.get_most_common_places()]

    return {'id': account.id,
            'registered': not account.is_fast,
            'name': account.nick_verbose,
            'hero_id': hero.id,
            'places_history': places_history,
            'might': account.might,
            'achievements': AccountAchievementsPrototype.get_by_account_id(account.id).points,
            'collections': AccountItemsPrototype.get_by_account_id(account.id).get_items_count(),
            'referrals': account.referrals_number,
            'ratings': ratings,
            'permissions': {
                'can_affect_game': account.can_affect_game
                },
            'description': account.description_html}
Example #11
0
    def setUp(self):
        super(ItemsManagerTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2',
            description=u'description_2',
            approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_2',
                                         description=u'description_2',
                                         approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_3',
                                         description=u'description_3',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_1',
                                             text=u'text_2_1',
                                             approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_2',
                                             text=u'text_2_2',
                                             approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3,
                                             caption=u'item_3_1',
                                             text=u'text_3_1',
                                             approved=True)

        self.account_1_items.add_item(self.item_1_2)
        self.account_1_items.save()

        self.worker = environment.workers.items_manager
        self.worker.initialize()
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2', '*****@*****.**', '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_3', '*****@*****.**', '111111')
        self.account_3 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_4', '*****@*****.**', '111111')
        self.account_4 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)
        self.account_2_items = AccountItemsPrototype.get_by_account_id(self.account_2.id)
        self.account_3_items = AccountItemsPrototype.get_by_account_id(self.account_3.id)

        group_edit_kit = sync_group('edit kit', ['collections.edit_kit'])
        group_edit = sync_group('edit collection', ['collections.edit_collection'])
        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate = sync_group('moderate collection', ['collections.moderate_collection'])
        group_moderate_kit = sync_group('moderate kit', ['collections.moderate_kit'])
        group_moderate_item = sync_group('moderate item', ['collections.moderate_item'])

        group_edit_kit.user_set.add(self.account_2._model)
        group_edit.user_set.add(self.account_2._model)
        group_edit_item.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)
        group_moderate_kit.user_set.add(self.account_3._model)
        group_moderate_item.user_set.add(self.account_3._model)


        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption=u'kit_2', description=u'description_2', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'item_text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'item_text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_1', text=u'item_text_2_1', approved=True)
Example #13
0
def register_user(nick, email=None, password=None, referer=None, referral_of_id=None, action_id=None, is_bot=False):

    if Account.objects.filter(nick=nick).exists():
        return REGISTER_USER_RESULT.DUPLICATE_USERNAME, None, None

    if email and Account.objects.filter(email=email).exists():
        return REGISTER_USER_RESULT.DUPLICATE_EMAIL, None, None

    try:
        referral_of = AccountPrototype.get_by_id(referral_of_id)
    except ValueError:
        referral_of = None

    if (email and not password) or (not email and password):
        raise exceptions.EmailAndPasswordError()

    is_fast = not (email and password)

    if is_fast and is_bot:
        raise exceptions.BotIsFastError()

    if password is None:
        password = accounts_settings.FAST_REGISTRATION_USER_PASSWORD

    account = AccountPrototype.create(nick=nick,
                                      email=email,
                                      is_fast=is_fast,
                                      is_bot=is_bot,
                                      password=password,
                                      referer=referer,
                                      referral_of=referral_of,
                                      action_id=action_id)

    AccountAchievementsPrototype.create(account)
    AccountItemsPrototype.create(account)

    market_logic.create_goods(account.id)

    hero = HeroPrototype.create(account=account)
    dress_new_hero(hero)
    messages_for_new_hero(hero)
    hero.save()

    return REGISTER_USER_RESULT.OK, account.id, hero.actions.current_action.bundle_id
Example #14
0
    def handle(self, *args, **options):

        for achievements in models.AccountAchievements.objects.all().iterator():
            prototype = prototypes.AccountAchievementsPrototype(achievements)

            collection = AccountItemsPrototype.get_by_account_id(prototype.account_id)

            for achievement_id in prototype.achievements.achievements_ids():
                for item in storage.achievements_storage[achievement_id].rewards:
                    if not collection.has_item(item):
                        GiveItemTaskPrototype.create(prototype.account_id, item.id)
Example #15
0
    def show(self, account=None):

        if account is None and self.account.is_authenticated:
            return self.redirect(url('collections:collections:show', self.collection.id, account=self.account.id))

        self.master_account = account

        master_account_items = None
        if self.master_account:
            master_account_items = AccountItemsPrototype.get_by_account_id(self.master_account.id)

        account_items = None
        if self.account.is_authenticated:
            account_items = AccountItemsPrototype.get_by_account_id(self.account.id)

        collections_statistics = get_collections_statistics(account_items=master_account_items)


        kits = sorted([kit for kit in kits_storage.all() if kit.collection_id == self.collection.id], key=lambda k: k.caption)

        if not (self.can_edit_kit or self.can_moderate_kit):
            kits = [kit for kit in kits if kit.approved]

        items = {kit.id: [] for kit in kits}

        items_query = items_storage.all()

        if not self.edit_item_permission and not self.moderate_item_permission:
            items_query = (item for item in items_query if item.approved)

        items_query = sorted([item for item in items_query if item.kit_id in items], key=lambda i: i.caption)

        for item in items_query:
            items[item.kit_id].append(item)

        return self.template('collections/collections/show.html',
                             {'kits': kits,
                              'items': items,
                              'account_items': account_items,
                              'master_account_items': master_account_items,
                              'collections_statistics': collections_statistics})
Example #16
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2',
            description=u'description_2',
            approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_2',
                                         description=u'description_2',
                                         approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_3',
                                         description=u'description_3',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_1',
                                             text=u'text_2_1',
                                             approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_2',
                                             text=u'text_2_2',
                                             approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3,
                                             caption=u'item_3_1',
                                             text=u'text_3_1',
                                             approved=True)
Example #17
0
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

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

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)
        self.account_2_items = AccountItemsPrototype.get_by_account_id(self.account_2.id)
        self.account_3_items = AccountItemsPrototype.get_by_account_id(self.account_3.id)

        group_edit_kit = sync_group('edit kit', ['collections.edit_kit'])
        group_edit = sync_group('edit collection', ['collections.edit_collection'])
        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate = sync_group('moderate collection', ['collections.moderate_collection'])
        group_moderate_kit = sync_group('moderate kit', ['collections.moderate_kit'])
        group_moderate_item = sync_group('moderate item', ['collections.moderate_item'])

        group_edit_kit.user_set.add(self.account_2._model)
        group_edit.user_set.add(self.account_2._model)
        group_edit_item.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)
        group_moderate_kit.user_set.add(self.account_3._model)
        group_moderate_item.user_set.add(self.account_3._model)


        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='item_text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='item_text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='item_text_2_1', approved=True)
    def handle(self, *args, **options):

        for achievements in models.AccountAchievements.objects.all().iterator(
        ):
            prototype = prototypes.AccountAchievementsPrototype(achievements)

            collection = AccountItemsPrototype.get_by_account_id(
                prototype.account_id)

            for achievement_id in prototype.achievements.achievements_ids():
                for item in storage.achievements_storage[
                        achievement_id].rewards:
                    if not collection.has_item(item):
                        GiveItemTaskPrototype.create(prototype.account_id,
                                                     item.id)
Example #19
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)

        self.collection_1 = CollectionPrototype.create(
            caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(
            caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption='kit_1',
                                         description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption='kit_2',
                                         description='description_2',
                                         approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2,
                                         caption='kit_3',
                                         description='description_3',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_1',
                                             text='text_1_1',
                                             approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption='item_1_2',
                                             text='text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption='item_2_1',
                                             text='text_2_1',
                                             approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2,
                                             caption='item_2_2',
                                             text='text_2_2',
                                             approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3,
                                             caption='item_3_1',
                                             text='text_3_1',
                                             approved=True)
Example #20
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        self.account_1 = self.accounts_factory.create_account()

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption='collection_1', description='description_1')
        self.collection_2 = CollectionPrototype.create(caption='collection_2', description='description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption='kit_1', description='description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption='kit_2', description='description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption='kit_3', description='description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption='item_1_1', text='text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption='item_1_2', text='text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption='item_2_1', text='text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption='item_2_2', text='text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption='item_3_1', text='text_3_1', approved=True)
Example #21
0
    def setUp(self):
        super(LogicTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(self.account_1.id)

        self.collection_1 = CollectionPrototype.create(caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(caption=u'collection_2', description=u'description_2', approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1, caption=u'kit_1', description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2, caption=u'kit_2', description=u'description_2', approved=True)
        self.kit_3 = KitPrototype.create(collection=self.collection_2, caption=u'kit_3', description=u'description_3', approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_1', text=u'text_1_1', approved=False)
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1, caption=u'item_1_2', text=u'text_1_2', approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_1', text=u'text_2_1', approved=True)
        self.item_2_2 = ItemPrototype.create(kit=self.kit_2, caption=u'item_2_2', text=u'text_2_2', approved=False)
        self.item_3_1 = ItemPrototype.create(kit=self.kit_3, caption=u'item_3_1', text=u'text_3_1', approved=True)
Example #22
0
    def test_successfull_result(self):
        game_tt_api.debug_clear_service()

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
        self.assertEqual(AccountItemsPrototype._db_count(), 0)

        result, account_id, bundle_id = register_user('test_user',
                                                      '*****@*****.**',
                                                      '111111')

        # test result
        self.assertEqual(result, REGISTER_USER_RESULT.OK)
        self.assertTrue(bundle_id is not None)

        #test basic structure
        account = AccountPrototype.get_by_id(account_id)

        self.assertEqual(account.nick, 'test_user')
        self.assertEqual(account.email, '*****@*****.**')

        self.assertTrue(not account.is_fast)

        hero = heroes_logic.load_hero(account_id=account.id)

        # test hero equipment
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.PANTS).id, 'default_pants')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.BOOTS).id, 'default_boots')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.PLATE).id, 'default_plate')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.GLOVES).id, 'default_gloves')
        self.assertEqual(
            hero.equipment.get(EQUIPMENT_SLOT.HAND_PRIMARY).id,
            'default_weapon')

        self.assertTrue(
            hero.equipment.get(EQUIPMENT_SLOT.HAND_SECONDARY) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.HELMET) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.SHOULDERS) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.CLOAK) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.AMULET) is None)
        self.assertTrue(hero.equipment.get(EQUIPMENT_SLOT.RING) is None)

        self.assertEqual(heroes_models.HeroPreferences.objects.all().count(),
                         1)
        self.assertEqual(
            heroes_models.HeroPreferences.objects.get(
                hero_id=hero.id).energy_regeneration_type,
            hero.preferences.energy_regeneration_type)

        self.assertEqual(account.referer, None)
        self.assertEqual(account.referer_domain, None)
        self.assertEqual(account.referral_of_id, None)
        self.assertEqual(account.action_id, None)

        self.assertEqual(account.is_bot, False)

        self.assertEqual(AccountAchievementsPrototype._db_count(), 1)
        self.assertEqual(AccountItemsPrototype._db_count(), 1)

        self.assertEqual(game_tt_api.energy_balance(account.id),
                         c.INITIAL_ENERGY_AMOUNT)

        self.assertEqual(game_tt_api.energy_balance(account.id),
                         c.INITIAL_ENERGY_AMOUNT)

        timers = tt_api.get_owner_timers(account_id=account.id)

        self.assertEqual(len(timers), 1)
    def setUp(self):
        super(BaseRequestTests, self).setUp()

        create_test_map()

        result, account_id, bundle_id = register_user('test_user_1',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_1 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_2',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_2 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_3',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_3 = AccountPrototype.get_by_id(account_id)

        result, account_id, bundle_id = register_user('test_user_4',
                                                      '*****@*****.**',
                                                      '111111')
        self.account_4 = AccountPrototype.get_by_id(account_id)

        self.account_1_items = AccountItemsPrototype.get_by_account_id(
            self.account_1.id)
        self.account_2_items = AccountItemsPrototype.get_by_account_id(
            self.account_2.id)
        self.account_3_items = AccountItemsPrototype.get_by_account_id(
            self.account_3.id)

        group_edit_kit = sync_group('edit kit', ['collections.edit_kit'])
        group_edit = sync_group('edit collection',
                                ['collections.edit_collection'])
        group_edit_item = sync_group('edit item', ['collections.edit_item'])
        group_moderate = sync_group('moderate collection',
                                    ['collections.moderate_collection'])
        group_moderate_kit = sync_group('moderate kit',
                                        ['collections.moderate_kit'])
        group_moderate_item = sync_group('moderate item',
                                         ['collections.moderate_item'])

        group_edit_kit.user_set.add(self.account_2._model)
        group_edit.user_set.add(self.account_2._model)
        group_edit_item.user_set.add(self.account_2._model)
        group_moderate.user_set.add(self.account_3._model)
        group_moderate_kit.user_set.add(self.account_3._model)
        group_moderate_item.user_set.add(self.account_3._model)

        self.collection_1 = CollectionPrototype.create(
            caption=u'collection_1', description=u'description_1')
        self.collection_2 = CollectionPrototype.create(
            caption=u'collection_2',
            description=u'description_2',
            approved=True)

        self.kit_1 = KitPrototype.create(collection=self.collection_1,
                                         caption=u'kit_1',
                                         description=u'description_1')
        self.kit_2 = KitPrototype.create(collection=self.collection_2,
                                         caption=u'kit_2',
                                         description=u'description_2',
                                         approved=True)

        self.item_1_1 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_1',
                                             text=u'item_text_1_1')
        self.item_1_2 = ItemPrototype.create(kit=self.kit_1,
                                             caption=u'item_1_2',
                                             text=u'item_text_1_2',
                                             approved=True)
        self.item_2_1 = ItemPrototype.create(kit=self.kit_2,
                                             caption=u'item_2_1',
                                             text=u'item_text_2_1',
                                             approved=True)
Example #24
0
 def add_item(self, item, account_id, notify):
     account_items = AccountItemsPrototype.get_by_account_id(account_id)
     account_items.add_item(item, notify=notify)
     account_items.save()
Example #25
0
 def add_item(self, item, account_id, notify):
     account_items = AccountItemsPrototype.get_by_account_id(account_id)
     account_items.add_item(item, notify=notify)
     account_items.save()
Example #26
0
def get_account_info(account, hero):
    from the_tale.game.ratings import prototypes as ratings_prototypes
    from the_tale.game.ratings import relations as ratings_relations
    from the_tale.game.places import storage as places_storage
    from the_tale.game.places import logic as places_logic

    ratings = {}

    rating_places = ratings_prototypes.RatingPlacesPrototype.get_by_account_id(
        account.id)

    rating_values = ratings_prototypes.RatingValuesPrototype.get_by_account_id(
        account.id)

    if rating_values and rating_places:
        for rating in ratings_relations.RATING_TYPE.records:
            ratings[rating.value] = {
                'name': rating.text,
                'place': getattr(rating_places, '%s_place' % rating.field,
                                 None),
                'value': getattr(rating_values, rating.field, None)
            }

    popularity = places_logic.get_hero_popularity(hero.id)

    places_history = [{
        'place': {
            'id': place_id,
            'name': places_storage.places[place_id].name
        },
        'count': help_count
    } for place_id, help_count in popularity.places_rating()]

    clan_info = None

    if account.clan_id:
        clan = account.clan
        clan_info = {'id': clan.id, 'abbr': clan.abbr, 'name': clan.name}

    return {
        'id':
        account.id,
        'registered':
        not account.is_fast,
        'name':
        account.nick_verbose,
        'hero_id':
        hero.id,
        'places_history':
        places_history,
        'might':
        account.might,
        'achievements':
        AccountAchievementsPrototype.get_by_account_id(account.id).points,
        'collections':
        AccountItemsPrototype.get_by_account_id(account.id).get_items_count(),
        'referrals':
        account.referrals_number,
        'ratings':
        ratings,
        'permissions': {
            'can_affect_game': account.can_affect_game
        },
        'description':
        account.description_html,
        'clan':
        clan_info
    }