예제 #1
0
    def test_1_process(self):
        self.assertEqual(
            PostponedTaskPrototype._model_class.objects.all().count(), 0)
        self.assertEqual(
            ChangeCredentialsTaskPrototype._model_class.objects.all().count(),
            0)

        new_password = self.task.process(logger=mock.Mock())
        self.assertTrue(self.task.is_processed)
        self.assertEqual(
            django_authenticate(nick='test_user', password='******').id,
            self.account.id)

        self.assertEqual(
            PostponedTaskPrototype._model_class.objects.all().count(), 1)
        self.assertEqual(
            ChangeCredentialsTaskPrototype._model_class.objects.all().count(),
            1)

        PostponedTaskPrototype._db_get_object(0).process(logger=mock.Mock())

        self.assertEqual(
            django_authenticate(nick='test_user', password='******'), None)
        self.assertEqual(
            django_authenticate(nick='test_user', password=new_password).id,
            self.account.id)
예제 #2
0
    def test_fast_profile_confirm_email(self):
        self.client.post(reverse('accounts:registration:fast'))
        PostponedTaskPrototype(model=PostponedTask.objects.all()[0]).process(
            FakeLogger())

        self.client.post(
            reverse('accounts:profile:update'), {
                'email': '*****@*****.**',
                'nick': 'test_nick',
                'password': '******'
            })
        self.assertEqual(Message.objects.all().count(), 1)

        uuid = ChangeCredentialsTask.objects.all()[0].uuid

        response = self.client.get(
            reverse('accounts:profile:confirm-email') + '?uuid=' + uuid)
        self.check_response_redirect(
            response,
            PostponedTaskPrototype._db_get_object(1).wait_url)

        self.assertEqual(ChangeCredentialsTask.objects.all().count(), 1)
        self.assertEqual(ChangeCredentialsTask.objects.all()[0].state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)

        self.assertEqual(
            django_authenticate(nick='test_nick', password='******'), None)
예제 #3
0
    def test_1_process(self):
        self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 0)
        self.assertEqual(ChangeCredentialsTaskPrototype._model_class.objects.all().count(), 0)

        new_password = self.task.process(logger=mock.Mock())
        self.assertTrue(self.task.is_processed)
        self.assertEqual(django_authenticate(nick='test_user', password='******').id, self.account.id)

        self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 1)
        self.assertEqual(ChangeCredentialsTaskPrototype._model_class.objects.all().count(), 1)

        PostponedTaskPrototype._db_get_object(0).process(logger=mock.Mock())

        self.assertEqual(django_authenticate(nick='test_user', password='******'), None)
        self.assertEqual(django_authenticate(nick='test_user', password=new_password).id, self.account.id)
예제 #4
0
파일: logic.py 프로젝트: pavetok/the-tale
def purchase_lot(buyer_id, lot):
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    invoice = bank_prototypes.InvoicePrototype.create(
        recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
        recipient_id=lot.seller_id,
        sender_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
        sender_id=buyer_id,
        currency=bank_relations.CURRENCY_TYPE.PREMIUM,
        amount=lot.price,
        description_for_sender=u'Покупка «%s»' % lot.name,
        description_for_recipient=u'Продажа «%s»' % lot.name,
        operation_uid=u'market-buy-lot-%s' % lot.type)

    transaction = bank_transaction.Transaction(invoice.id)

    logic_task = postponed_tasks.BuyLotTask(seller_id=lot.seller_id,
                                            buyer_id=buyer_id,
                                            lot_id=lot.id,
                                            transaction=transaction)

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.refrigerator.cmd_wait_task(task.id)

    return task
예제 #5
0
 def test_choose_ability_request_ok(self):
     self.request_login('*****@*****.**')
     response = self.client.post(
         reverse('game:heroes:choose-ability', args=[self.hero.id]) +
         '?ability_id=' + self.get_new_ability_id())
     task = PostponedTaskPrototype._db_get_object(0)
     self.check_ajax_processing(response, task.status_url)
예제 #6
0
    def test_buy(self):
        self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 0)
        self.assertEqual(InvoicePrototype._model_class.objects.all().count(), 0)

        with mock.patch("the_tale.common.postponed_tasks.PostponedTaskPrototype.cmd_wait") as cmd_wait:
            self.purchase.buy(account=self.account)

        self.assertEqual(cmd_wait.call_count, 1)

        self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 1)
        self.assertEqual(InvoicePrototype._model_class.objects.all().count(), 1)

        postponed_logic = PostponedTaskPrototype._db_get_object(0).internal_logic

        self.assertTrue(isinstance(postponed_logic, BuyPremium))
        self.assertEqual(postponed_logic.account_id, self.account.id)
        self.assertEqual(postponed_logic.days, self.days)

        invoice = InvoicePrototype.get_by_id(postponed_logic.transaction.invoice_id)

        self.assertEqual(invoice.recipient_type, ENTITY_TYPE.GAME_ACCOUNT)
        self.assertEqual(invoice.recipient_id, self.account.id)
        self.assertEqual(invoice.sender_type, ENTITY_TYPE.GAME_LOGIC)
        self.assertEqual(invoice.sender_id, 0)
        self.assertEqual(invoice.currency, CURRENCY_TYPE.PREMIUM)
        self.assertEqual(invoice.amount, -self.cost)
        self.assertEqual(invoice.description_for_sender, u"premium-days-transaction-description")
        self.assertEqual(invoice.description_for_recipient, u"premium-days-transaction-description")
 def test_fast_registration_processing(self):
     response = self.client.post(reverse('accounts:registration:fast'))
     self.assertEqual(response.status_code, 200)
     task = PostponedTaskPrototype(model=PostponedTask.objects.all()[0])
     self.check_ajax_processing(response, task.status_url)
     self.assertEqual(PostponedTask.objects.all().count(), 1)
     self.assertEqual(task.internal_logic.referer, None)
예제 #8
0
파일: logic.py 프로젝트: Alkalit/the-tale
def purchase_lot(buyer_id, lot):
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    invoice = bank_prototypes.InvoicePrototype.create(recipient_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                                                      recipient_id=lot.seller_id,
                                                      sender_type=bank_relations.ENTITY_TYPE.GAME_ACCOUNT,
                                                      sender_id=buyer_id,
                                                      currency=bank_relations.CURRENCY_TYPE.PREMIUM,
                                                      amount=lot.price,
                                                      description_for_sender=u'Покупка «%s»' % lot.name,
                                                      description_for_recipient=u'Продажа «%s»' % lot.name,
                                                      operation_uid=u'market-buy-lot-%s' % lot.type)

    transaction = bank_transaction.Transaction(invoice.id)

    logic_task = postponed_tasks.BuyLotTask(seller_id=lot.seller_id,
                                            buyer_id=buyer_id,
                                            lot_id=lot.id,
                                            transaction=transaction)

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.refrigerator.cmd_wait_task(task.id)

    return task
예제 #9
0
 def test_profile_update_nick(self):
     self.request_login(self.account.email)
     response = self.client.post(reverse('accounts:profile:update'), {'email': self.account.email, 'nick': 'test_nick'})
     self.assertEqual(response.status_code, 200)
     self.check_ajax_processing(response, PostponedTaskPrototype._db_get_object(0).status_url)
     self.assertEqual(ChangeCredentialsTask.objects.all().count(), 1)
     self.assertEqual(ChangeCredentialsTask.objects.all()[0].state, relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
예제 #10
0
    def test_success(self):
        self.assertEqual(PostponedTask.objects.all().count(), 0)
        response = self.post_ajax_json(url('game:heroes:reset-abilities', self.hero.id))
        self.assertEqual(PostponedTask.objects.all().count(), 1)

        task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, task.status_url)
예제 #11
0
    def test_fast_registration_second_request(self):
        response = self.client.post(reverse('accounts:registration:fast'))
        task = PostponedTaskPrototype(model=PostponedTask.objects.all()[0])

        response = self.client.post(reverse('accounts:registration:fast'))

        self.check_ajax_processing(response, task.status_url)
        self.assertEqual(PostponedTask.objects.all().count(), 1)
예제 #12
0
파일: views.py 프로젝트: Alkalit/the-tale
    def choose_ability(self, ability_id):

        choose_task = postponed_tasks.ChooseHeroAbilityTask(hero_id=self.hero.id, ability_id=ability_id)

        task = PostponedTaskPrototype.create(choose_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
예제 #13
0
 def test_fast_registration_processing__with_referer(self):
     referer = 'http://example.com/forum/post/1/'
     response = self.client.post(reverse('accounts:registration:fast'),
                                 HTTP_REFERER=referer)
     self.assertEqual(response.status_code, 200)
     task = PostponedTaskPrototype(model=PostponedTask.objects.all()[0])
     self.check_ajax_processing(response, task.status_url)
     self.assertEqual(PostponedTask.objects.all().count(), 1)
     self.assertEqual(task.internal_logic.referer, referer)
예제 #14
0
    def change_credentials(self):
        from the_tale.accounts.postponed_tasks import ChangeCredentials

        change_credentials_task = ChangeCredentials(task_id=self.id)
        task = PostponedTaskPrototype.create(change_credentials_task)

        environment.workers.accounts_manager.cmd_task(task.id)

        return task
예제 #15
0
    def test_profile_confirm_email_for_unlogined(self):
        self.request_login(self.account.email)
        self.client.post(reverse('accounts:profile:update'), {'email': '*****@*****.**', 'nick': 'test_nick'})
        self.request_logout()

        uuid = ChangeCredentialsTask.objects.all()[0].uuid

        response = self.client.get(reverse('accounts:profile:confirm-email')+'?uuid='+uuid)
        self.check_response_redirect(response, PostponedTaskPrototype._db_get_object(0).wait_url)
예제 #16
0
    def test_choose_processing(self):
        self.turn_to_quest(self.storage, self.hero.id)

        self.request_login('*****@*****.**')
        response = self.client.post(url('game:quests:api-choose', option_uid=self.option_uid, api_version='1.0', api_client=project_settings.API_CLIENT))

        task = PostponedTaskPrototype._db_get_object(0)
        self.check_ajax_processing(response, task.status_url)
        self.assertEqual(PostponedTask.objects.all().count(), 1)
예제 #17
0
    def test_success_multiply_accoutns(self):
        with self.check_delta(PostponedTaskPrototype._db_count, 1):
            self.check_ajax_processing(self.post_ajax_json(url('accounts:messages:create'), {'text': 'test-message', 'recipients': ('%d,%d' % (self.account2.id, self.account3.id))}))

        task = PostponedTaskPrototype._db_latest()

        self.assertEqual(task.internal_logic.message, 'test-message')
        self.assertEqual(task.internal_logic.account_id, self.account1.id)
        self.assertEqual(task.internal_logic.recipients, [self.account2.id, self.account3.id])
예제 #18
0
    def change_credentials(self):
        from the_tale.accounts.postponed_tasks import ChangeCredentials

        change_credentials_task = ChangeCredentials(task_id=self.id)
        task = PostponedTaskPrototype.create(change_credentials_task)

        environment.workers.accounts_manager.cmd_task(task.id)

        return task
예제 #19
0
    def test_initialization(self):
        from the_tale.common.postponed_tasks import PostponedTask, PostponedTaskPrototype, POSTPONED_TASK_STATE, FakePostponedInternalTask

        PostponedTaskPrototype.create(FakePostponedInternalTask())

        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.WAITING).count(), 1)

        self.worker.process_initialize()

        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.WAITING).count(), 0)
        self.assertEqual(PostponedTask.objects.filter(state=POSTPONED_TASK_STATE.RESETED).count(), 1)

        self.assertEqual(self.worker.tasks, {})
        self.assertEqual(self.worker.accounts_for_tasks, {})
        self.assertEqual(self.worker.accounts_owners, {self.account_1.id: 'game_logic_1', self.account_2.id: 'game_logic_2'})
        self.assertEqual(self.worker.accounts_queues, {})
        self.assertTrue(self.worker.initialized)
        self.assertFalse(self.worker.wait_next_turn_answer)
        self.assertTrue(GameState.is_working())
예제 #20
0
파일: views.py 프로젝트: Alkalit/the-tale
    def reset_name(self):
        change_task = postponed_tasks.ChangeHeroTask(hero_id=self.hero.id,
                                     name=names.generator.get_name(self.hero.race, self.hero.gender),
                                     race=self.hero.race,
                                     gender=self.hero.gender)

        task = PostponedTaskPrototype.create(change_task)

        environment.workers.supervisor.cmd_logic_task(self.hero.account_id, task.id)

        return self.json_processing(task.status_url)
예제 #21
0
파일: views.py 프로젝트: Alkalit/the-tale
    def reset_abilities(self):

        if not self.hero.abilities.can_reset:
            return self.json_error('heroes.reset_abilities.reset_timeout', u'Сброс способностей пока не доступен')

        reset_task = postponed_tasks.ResetHeroAbilitiesTask(hero_id=self.hero.id)

        task = PostponedTaskPrototype.create(reset_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
예제 #22
0
파일: views.py 프로젝트: lshestov/the-tale
def create(context):
    check_recipients(context.form)

    logic_task = postponed_tasks.SendMessagesTask(
        account_id=context.account.id, recipients=context.form.c.recipients, message=context.form.c.text
    )

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.accounts_manager.cmd_task(task.id)

    return dext_views.AjaxProcessing(status_url=task.status_url)
예제 #23
0
    def test_profile_confirm_email(self):
        self.request_login(self.account.email)
        self.client.post(reverse('accounts:profile:update'), {'email': '*****@*****.**', 'nick': 'test_nick'})
        self.assertEqual(PostponedTaskPrototype._model_class.objects.all().count(), 0)
        uuid = ChangeCredentialsTask.objects.all()[0].uuid

        response = self.client.get(reverse('accounts:profile:confirm-email')+'?uuid='+uuid)
        self.check_response_redirect(response, PostponedTaskPrototype._db_get_object(0).wait_url)

        self.assertEqual(ChangeCredentialsTask.objects.all().count(), 1)
        self.assertEqual(ChangeCredentialsTask.objects.all()[0].state, relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
        self.assertEqual(Message.objects.all().count(), 1)
예제 #24
0
def create(context):
    check_recipients(context.form)

    logic_task = postponed_tasks.SendMessagesTask(account_id=context.account.id,
                                                  recipients=context.form.c.recipients,
                                                  message=context.form.c.text)

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.accounts_manager.cmd_task(task.id)

    return dext_views.AjaxProcessing(status_url=task.status_url)
예제 #25
0
    def test_change_hero(self):
        self.assertEqual(PostponedTask.objects.all().count(), 0)
        response = self.client.post(url('game:heroes:change-hero', self.hero.id), self.get_post_data())
        self.assertEqual(PostponedTask.objects.all().count(), 1)

        task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, task.status_url)

        self.assertEqual(task.internal_logic.name, names.generator.get_test_name(name=u'новое имя'))
        self.assertEqual(task.internal_logic.gender, GENDER.MASCULINE)
        self.assertEqual(task.internal_logic.race, RACE.DWARF)
예제 #26
0
    def test_success(self):

        with mock.patch('the_tale.accounts.workers.accounts_manager.Worker.cmd_task') as cmd_task:
            with self.check_delta(PostponedTaskPrototype._db_count, 1):
                self.check_ajax_processing(self.post_ajax_json(url('accounts:messages:create'), {'text': 'test-message', 'recipients': self.account2.id}))

        task = PostponedTaskPrototype._db_latest()

        self.assertEqual(cmd_task.call_args_list, [mock.call(task.id)])

        self.assertEqual(task.internal_logic.message, 'test-message')
        self.assertEqual(task.internal_logic.account_id, self.account1.id)
        self.assertEqual(task.internal_logic.recipients, [self.account2.id])
예제 #27
0
    def fast(self):

        if self.account.is_authenticated():
            return self.json_error('accounts.registration.fast.already_registered', u'Вы уже зарегистрированы')

        if conf.accounts_settings.SESSION_REGISTRATION_TASK_ID_KEY in self.request.session:

            task_id = self.request.session[conf.accounts_settings.SESSION_REGISTRATION_TASK_ID_KEY]
            task = PostponedTaskPrototype.get_by_id(task_id)

            if task is not None:
                if task.state.is_processed:
                    return self.json_error('accounts.registration.fast.already_processed', u'Вы уже зарегистрированы, обновите страницу')
                if task.state.is_waiting:
                    return self.json_processing(task.status_url)
                # in other case create new task

        referer = None
        if conf.accounts_settings.SESSION_REGISTRATION_REFERER_KEY in self.request.session:
            referer = self.request.session[conf.accounts_settings.SESSION_REGISTRATION_REFERER_KEY]

        referral_of_id = None
        if conf.accounts_settings.SESSION_REGISTRATION_REFERRAL_KEY in self.request.session:
            referral_of_id = self.request.session[conf.accounts_settings.SESSION_REGISTRATION_REFERRAL_KEY]

        action_id = None
        if conf.accounts_settings.SESSION_REGISTRATION_ACTION_KEY in self.request.session:
            action_id = self.request.session[conf.accounts_settings.SESSION_REGISTRATION_ACTION_KEY]

        registration_task = postponed_tasks.RegistrationTask(account_id=None, referer=referer, referral_of_id=referral_of_id, action_id=action_id)

        task = PostponedTaskPrototype.create(registration_task,
                                             live_time=conf.accounts_settings.REGISTRATION_TIMEOUT)

        self.request.session[conf.accounts_settings.SESSION_REGISTRATION_TASK_ID_KEY] = task.id

        environment.workers.registration.cmd_task(task.id)

        return self.json_processing(task.status_url)
예제 #28
0
 def test_profile_update_nick(self):
     self.request_login(self.account.email)
     response = self.client.post(reverse('accounts:profile:update'), {
         'email': self.account.email,
         'nick': 'test_nick'
     })
     self.assertEqual(response.status_code, 200)
     self.check_ajax_processing(
         response,
         PostponedTaskPrototype._db_get_object(0).status_url)
     self.assertEqual(ChangeCredentialsTask.objects.all().count(), 1)
     self.assertEqual(ChangeCredentialsTask.objects.all()[0].state,
                      relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
예제 #29
0
    def test_choose_processing(self):
        self.turn_to_quest(self.storage, self.hero.id)

        self.request_login('*****@*****.**')
        response = self.client.post(
            url('game:quests:api-choose',
                option_uid=self.option_uid,
                api_version='1.0',
                api_client=project_settings.API_CLIENT))

        task = PostponedTaskPrototype._db_get_object(0)
        self.check_ajax_processing(response, task.status_url)
        self.assertEqual(PostponedTask.objects.all().count(), 1)
예제 #30
0
파일: views.py 프로젝트: nbadp/the-tale
    def use_ability(self, ability):

        battle = Battle1x1Prototype.get_by_account_id(self.account.id)

        if battle is None or not battle.state.is_PROCESSING:
            return self.json_error("pvp.use_ability.no_battle", u"Бой не идёт, вы не можете использовать способность")

        use_ability_task = UsePvPAbilityTask(battle_id=battle.id, account_id=self.account.id, ability_id=ability.TYPE)

        task = PostponedTaskPrototype.create(use_ability_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
예제 #31
0
파일: logic.py 프로젝트: Alkalit/the-tale
def send_good_to_market(seller_id, good, price):
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    logic_task = postponed_tasks.CreateLotTask(account_id=seller_id,
                                               good_type=good.type,
                                               good_uid=good.uid,
                                               price=price)

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.market_manager.cmd_logic_task(seller_id, task.id)

    return task
예제 #32
0
    def activate(self, hero, card_uid, data):
        data['hero_id'] = hero.id
        data['account_id'] = hero.account_id
        data['card_uid'] = card_uid

        card_task = UseCardTask(processor_id=self.TYPE.value,
                                hero_id=hero.id,
                                data=data)

        task = PostponedTaskPrototype.create(card_task)

        environment.workers.supervisor.cmd_logic_task(hero.account_id, task.id)

        return task
예제 #33
0
파일: effects.py 프로젝트: Alkalit/the-tale
    def activate(self, hero, card_uid, data):
        data['hero_id'] = hero.id
        data['account_id'] = hero.account_id
        data['card_uid'] = card_uid

        card_task = UseCardTask(processor_id=self.TYPE.value,
                                hero_id=hero.id,
                                data=data)

        task = PostponedTaskPrototype.create(card_task)

        environment.workers.supervisor.cmd_logic_task(hero.account_id, task.id)

        return task
예제 #34
0
파일: logic.py 프로젝트: pavetok/the-tale
def send_good_to_market(seller_id, good, price):
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    logic_task = postponed_tasks.CreateLotTask(account_id=seller_id,
                                               good_type=good.type,
                                               good_uid=good.uid,
                                               price=price)

    task = PostponedTaskPrototype.create(logic_task)

    amqp_environment.environment.workers.market_manager.cmd_logic_task(
        seller_id, task.id)

    return task
예제 #35
0
    def activate(self, hero, data):
        from the_tale.game.abilities.postponed_tasks import UseAbilityTask

        data['hero_id'] = hero.id
        data['account_id'] = hero.account_id

        ability_task = UseAbilityTask(processor_id=self.TYPE.value,
                                      hero_id=hero.id,
                                      data=data)

        task = PostponedTaskPrototype.create(ability_task)

        environment.workers.supervisor.cmd_logic_task(hero.account_id, task.id)

        return task
예제 #36
0
    def activate(self, hero, data):
        from the_tale.game.abilities.postponed_tasks import UseAbilityTask

        data['hero_id'] = hero.id
        data['account_id'] = hero.account_id

        ability_task = UseAbilityTask(processor_id=self.TYPE.value,
                                      hero_id=hero.id,
                                      data=data)

        task = PostponedTaskPrototype.create(ability_task)

        environment.workers.supervisor.cmd_logic_task(hero.account_id, task.id)

        return task
예제 #37
0
    def test_profile_confirm_email_for_unlogined(self):
        self.request_login(self.account.email)
        self.client.post(reverse('accounts:profile:update'), {
            'email': '*****@*****.**',
            'nick': 'test_nick'
        })
        self.request_logout()

        uuid = ChangeCredentialsTask.objects.all()[0].uuid

        response = self.client.get(
            reverse('accounts:profile:confirm-email') + '?uuid=' + uuid)
        self.check_response_redirect(
            response,
            PostponedTaskPrototype._db_get_object(0).wait_url)
예제 #38
0
    def test_change_hero(self):
        self.hero._model.name = '111'
        self.hero.save()

        self.assertEqual(PostponedTask.objects.all().count(), 0)
        response = self.client.post(url('game:heroes:reset-name', self.hero.id))
        self.assertEqual(PostponedTask.objects.all().count(), 1)

        task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, task.status_url)

        self.assertNotEqual(task.internal_logic.name, self.hero.name)
        self.assertEqual(task.internal_logic.gender, self.hero.gender)
        self.assertEqual(task.internal_logic.race, self.hero.race)
예제 #39
0
파일: views.py 프로젝트: Alkalit/the-tale
    def change_hero(self):
        edit_name_form = forms.EditNameForm(self.request.POST)

        if not edit_name_form.is_valid():
            return self.json_error('heroes.change_name.form_errors', edit_name_form.errors)

        change_task = postponed_tasks.ChangeHeroTask(hero_id=self.hero.id,
                                                     name=edit_name_form.c.name,
                                                     race=edit_name_form.c.race,
                                                     gender=edit_name_form.c.gender)

        task = PostponedTaskPrototype.create(change_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
예제 #40
0
    def test_fast_profile_confirm_email(self):
        self.client.post(reverse('accounts:registration:fast'))
        PostponedTaskPrototype(model=PostponedTask.objects.all()[0]).process(FakeLogger())

        self.client.post(reverse('accounts:profile:update'), {'email': '*****@*****.**', 'nick': 'test_nick', 'password': '******'})
        self.assertEqual(Message.objects.all().count(), 1)

        uuid = ChangeCredentialsTask.objects.all()[0].uuid

        response = self.client.get(reverse('accounts:profile:confirm-email')+'?uuid='+uuid)
        self.check_response_redirect(response, PostponedTaskPrototype._db_get_object(1).wait_url)

        self.assertEqual(ChangeCredentialsTask.objects.all().count(), 1)
        self.assertEqual(ChangeCredentialsTask.objects.all()[0].state, relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)

        self.assertEqual(django_authenticate(nick='test_nick', password='******'), None)
예제 #41
0
파일: views.py 프로젝트: Alkalit/the-tale
    def choose_preferences(self):

        choose_preferences_form = forms.ChoosePreferencesForm(self.request.POST)

        if not choose_preferences_form.is_valid():
            return self.json_error('heroes.choose_preferences.form_errors', choose_preferences_form.errors)

        choose_task = postponed_tasks.ChoosePreferencesTask(hero_id=self.hero.id,
                                            preference_type=choose_preferences_form.c.preference_type,
                                            preference_id=choose_preferences_form.c.preference_id if choose_preferences_form.c.preference_id != '' else None)

        task = PostponedTaskPrototype.create(choose_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(status_url=task.status_url)
예제 #42
0
파일: logic.py 프로젝트: Alkalit/the-tale
def close_lots_by_timeout():
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    expired_lots_query = models.Lot.objects.filter(state=relations.LOT_STATE.ACTIVE,
                                                   created_at__lt=datetime.datetime.now()-datetime.timedelta(days=conf.settings.LOT_LIVE_TIME))

    tasks = []

    for lot_id, seller_id in expired_lots_query.values_list('id', 'seller_id'):
        logic_task = postponed_tasks.CloseLotByTimoutTask(lot_id=lot_id)
        task = PostponedTaskPrototype.create(logic_task)
        amqp_environment.environment.workers.market_manager.cmd_logic_task(seller_id, task.id)
        tasks.append(task)

    return tasks
예제 #43
0
    def test_success(self):
        old_nick = self.account_1.nick

        response = self.client.post(reverse('accounts:reset-nick', args=[self.account_1.id]))

        postponed_task = PostponedTaskPrototype._db_get_object(0)

        self.check_ajax_processing(response, reverse('postponed-tasks:status', args=[postponed_task.id]))

        task = ChangeCredentialsTaskPrototype._db_get_object(0)

        self.assertFalse(task.relogin_required)
        self.assertEqual(self.account_1.id, task.account.id)
        self.assertNotEqual(self.account_1.nick, task.new_nick)

        self.assertEqual(old_nick, AccountPrototype.get_by_id(self.account_1.id).nick)
예제 #44
0
def initiate_transfer_money(sender_id, recipient_id, amount, comment):
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.accounts import postponed_tasks

    commission = get_transfer_commission(amount)

    task = postponed_tasks.TransferMoneyTask(sender_id=sender_id,
                                             recipient_id=recipient_id,
                                             amount=amount-commission,
                                             commission=commission,
                                             comment=comment)
    task = PostponedTaskPrototype.create(task)

    amqp_environment.environment.workers.refrigerator.cmd_wait_task(task.id)

    return task
예제 #45
0
    def test_success_multiply_accoutns(self):
        with self.check_delta(PostponedTaskPrototype._db_count, 1):
            self.check_ajax_processing(
                self.post_ajax_json(
                    url('accounts:messages:create'), {
                        'text':
                        'test-message',
                        'recipients':
                        ('%d,%d' % (self.account2.id, self.account3.id))
                    }))

        task = PostponedTaskPrototype._db_latest()

        self.assertEqual(task.internal_logic.message, 'test-message')
        self.assertEqual(task.internal_logic.account_id, self.account1.id)
        self.assertEqual(task.internal_logic.recipients,
                         [self.account2.id, self.account3.id])
예제 #46
0
파일: goods.py 프로젝트: Alkalit/the-tale
    def buy(self, account):
        if account.is_fast:
            raise exceptions.FastAccountError(purchase_uid=self.uid, account_id=account.id)

        self.additional_checks(account)

        transaction = transaction_logic(account=account,
                                        amount=-self.cost,
                                        description=self.transaction_description,
                                        uid='ingame-purchase-<%s>' % self.uid)

        postponed_logic = self.construct_postponed_task(account, transaction)

        postponed_task = PostponedTaskPrototype.create(postponed_logic)
        postponed_task.cmd_wait()

        return postponed_task
예제 #47
0
    def use_ability(self, ability):

        battle = Battle1x1Prototype.get_by_account_id(self.account.id)

        if battle is None or not battle.state.is_PROCESSING:
            return self.json_error(
                'pvp.use_ability.no_battle',
                u'Бой не идёт, вы не можете использовать способность')

        use_ability_task = UsePvPAbilityTask(battle_id=battle.id,
                                             account_id=self.account.id,
                                             ability_id=ability.TYPE)

        task = PostponedTaskPrototype.create(use_ability_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
예제 #48
0
    def test_success(self):

        with mock.patch(
                'the_tale.accounts.workers.accounts_manager.Worker.cmd_task'
        ) as cmd_task:
            with self.check_delta(PostponedTaskPrototype._db_count, 1):
                self.check_ajax_processing(
                    self.post_ajax_json(url('accounts:messages:create'), {
                        'text': 'test-message',
                        'recipients': self.account2.id
                    }))

        task = PostponedTaskPrototype._db_latest()

        self.assertEqual(cmd_task.call_args_list, [mock.call(task.id)])

        self.assertEqual(task.internal_logic.message, 'test-message')
        self.assertEqual(task.internal_logic.account_id, self.account1.id)
        self.assertEqual(task.internal_logic.recipients, [self.account2.id])
예제 #49
0
    def buy(self, account):
        if account.is_fast:
            raise exceptions.FastAccountError(purchase_uid=self.uid,
                                              account_id=account.id)

        self.additional_checks(account)

        transaction = transaction_logic(
            account=account,
            amount=-self.cost,
            description=self.transaction_description,
            uid='ingame-purchase-<%s>' % self.uid)

        postponed_logic = self.construct_postponed_task(account, transaction)

        postponed_task = PostponedTaskPrototype.create(postponed_logic)
        postponed_task.cmd_wait()

        return postponed_task
예제 #50
0
파일: logic.py 프로젝트: pavetok/the-tale
def close_lots_by_timeout():
    from the_tale.common.postponed_tasks import PostponedTaskPrototype
    from the_tale.finances.market import postponed_tasks

    expired_lots_query = models.Lot.objects.filter(
        state=relations.LOT_STATE.ACTIVE,
        created_at__lt=datetime.datetime.now() -
        datetime.timedelta(days=conf.settings.LOT_LIVE_TIME))

    tasks = []

    for lot_id, seller_id in expired_lots_query.values_list('id', 'seller_id'):
        logic_task = postponed_tasks.CloseLotByTimoutTask(lot_id=lot_id)
        task = PostponedTaskPrototype.create(logic_task)
        amqp_environment.environment.workers.market_manager.cmd_logic_task(
            seller_id, task.id)
        tasks.append(task)

    return tasks
예제 #51
0
    def test_profile_confirm_email(self):
        self.request_login(self.account.email)
        self.client.post(reverse('accounts:profile:update'), {
            'email': '*****@*****.**',
            'nick': 'test_nick'
        })
        self.assertEqual(
            PostponedTaskPrototype._model_class.objects.all().count(), 0)
        uuid = ChangeCredentialsTask.objects.all()[0].uuid

        response = self.client.get(
            reverse('accounts:profile:confirm-email') + '?uuid=' + uuid)
        self.check_response_redirect(
            response,
            PostponedTaskPrototype._db_get_object(0).wait_url)

        self.assertEqual(ChangeCredentialsTask.objects.all().count(), 1)
        self.assertEqual(ChangeCredentialsTask.objects.all()[0].state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
        self.assertEqual(Message.objects.all().count(), 1)
예제 #52
0
    def say(self):

        battle = Battle1x1Prototype.get_by_account_id(self.account.id)

        if battle is None or not battle.state.is_PROCESSING:
            return self.json_error('pvp.say.no_battle',
                                   u'Бой не идёт, вы не можете говорить')

        say_form = SayForm(self.request.POST)

        if not say_form.is_valid():
            return self.json_error('pvp.say.form_errors', say_form.errors)

        say_task = SayInBattleLogTask(battle_id=battle.id,
                                      text=say_form.c.text)

        task = PostponedTaskPrototype.create(say_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.json_processing(task.status_url)
예제 #53
0
파일: views.py 프로젝트: pavetok/the-tale
    def api_choose(self, option_uid, api_version):
        u'''
Изменение пути выполнения задания героем

- **адрес:** /game/quests/api/choose/
- **http-метод:** POST
- **версии:** 1.0
- **параметры:**
    * GET: option_uid — уникальный идентификатор выбора в задании (получается с информацией о состоянии игры)
- **возможные ошибки**: нет

Метод является «неблокирующей операцией» (см. документацию), формат ответа соответствует ответу для всех «неблокирующих операций».
        '''
        choose_task = MakeChoiceTask(account_id=self.account.id,
                                     option_uid=option_uid)

        task = PostponedTaskPrototype.create(choose_task)

        environment.workers.supervisor.cmd_logic_task(self.account.id, task.id)

        return self.processing(status_url=task.status_url)