def test_request_email_confirmation(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
        task.request_email_confirmation()
        self.assertEqual(Message.objects.all().count(), 1)

        task = ChangeCredentialsTaskPrototype.create(self.fast_account, new_email='*****@*****.**', new_password='******', new_nick='test_nick')
        task.request_email_confirmation()
        self.assertEqual(Message.objects.all().count(), 2)
    def test_email_changed(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
        self.assertTrue(task.email_changed)

        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_password='******')
        self.assertTrue(not task.email_changed)

        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
        self.assertTrue(not task.email_changed)
    def test_create(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**', new_password='******', new_nick='test_nick')

        self.assertTrue(task._model.new_password != '222222')
        self.assertTrue(task._model.new_nick == 'test_nick')
        self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.WAITING)
        self.assertEqual(task.account.id, self.test_account.id)
        self.assertTrue(not AccountPrototype.get_by_id(self.test_account.id).is_fast)

        task_duplicate = ChangeCredentialsTaskPrototype.get_by_uuid(task.uuid)

        self.assertEqual(task.id, task_duplicate.id)
 def test_process_timeout(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
     task._model.created_at = datetime.datetime.fromtimestamp(0)
     task.process(FakeLogger())
     self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.TIMEOUT)
     self.assertEqual(task._model.comment, 'timeout')
     self.assertEqual(django_authenticate(nick='test_user', password='******').id, task.account.id)
示例#5
0
    def create_task_and_message(self, account, new_nick):
        task = ChangeCredentialsTaskPrototype.create(account=account,
                                                     new_email='*****@*****.**' % new_nick,
                                                     new_password='******',
                                                     new_nick=new_nick)
        task.request_email_confirmation()

        return task, MessagePrototype.get_priority_message()
示例#6
0
    def test_confirm_email__error_occured(self):
        self.request_login(self.account.email)
        self.client.post(reverse('accounts:profile:update'), {'email': '*****@*****.**', 'nick': 'test_nick'})

        task = ChangeCredentialsTaskPrototype._db_get_object(0)
        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR
        task._model.save()

        self.check_html_ok(self.client.get(url('accounts:profile:confirm-email', uuid=task.uuid), texts=['pgf-change-credentials-error']))
示例#7
0
 def test_process_waiting_and_email_confirmation(self):
     task = ChangeCredentialsTaskPrototype.create(
         self.test_account, new_email='*****@*****.**')
     task.process(FakeLogger())
     self.assertEqual(task.state,
                      relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT)
     self.assertEqual(Message.objects.all().count(), 1)
     self.assertEqual(
         django_authenticate(nick='test_user', password='******').id,
         task.account.id)
示例#8
0
 def test_process_waiting_and_nick_change(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account,
                                                  new_nick='test_nick')
     postponed_task = task.process(FakeLogger())
     self.assertEqual(task.state,
                      relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
     self.assertNotEqual(postponed_task, None)
     self.assertEqual(
         django_authenticate(nick='test_user', password='******').id,
         task.account.id)
    def test_change_credentials(self):
        task = ChangeCredentialsTaskPrototype.create(self.fast_account, new_email='*****@*****.**', new_password='******', new_nick='test_nick')

        self.assertTrue(AccountPrototype.get_by_id(self.fast_account.id).is_fast)

        with mock.patch('the_tale.amqp_environment.environment.workers.supervisor.cmd_update_hero_with_account_data') as fake_cmd:
            postponed_task = task.change_credentials()

        self.assertNotEqual(postponed_task, None)
        self.assertEqual(fake_cmd.call_count, 0)
 def test_process_timeout(self):
     task = ChangeCredentialsTaskPrototype.create(
         self.test_account, new_email='*****@*****.**')
     task._model.created_at = datetime.datetime.fromtimestamp(0)
     task.process(FakeLogger())
     self.assertEqual(task.state,
                      relations.CHANGE_CREDENTIALS_TASK_STATE.TIMEOUT)
     self.assertEqual(task._model.comment, 'timeout')
     self.assertEqual(
         django_authenticate(nick=self.test_account.nick,
                             password='******').id, task.account.id)
示例#11
0
    def test_process_email_sent(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**', new_password='******')
        postponed_task = task.process(FakeLogger())
        self.assertEqual(postponed_task, None)
        self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT)
        self.assertEqual(Message.objects.all().count(), 1)
        self.assertEqual(django_authenticate(nick='test_user', password='******').id, task.account.id)
        self.assertEqual(django_authenticate(nick='test_user', password='******'), None)

        postponed_task = task.process(FakeLogger())
        self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
        self.assertNotEqual(postponed_task, None)
示例#12
0
    def test_process_completed_state(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.PROCESSED
        task.process(FakeLogger())
        self.assertEqual(task._model.state, relations.CHANGE_CREDENTIALS_TASK_STATE.PROCESSED)

        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.UNPROCESSED
        task.process(FakeLogger())
        self.assertEqual(task._model.state, relations.CHANGE_CREDENTIALS_TASK_STATE.UNPROCESSED)

        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR
        task.process(FakeLogger())
        self.assertEqual(task._model.state, relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR)
示例#13
0
    def setUp(self):
        super(PostponedChangeCredentialsTaskTests, self).setUp()
        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.task = ChangeCredentialsTaskPrototype.create(self.account,
                                                          new_email='*****@*****.**',
                                                          new_password='******',
                                                          new_nick='test_nick',
                                                          relogin_required=True)

        self.postponed_task = ChangeCredentials(task_id=self.task.id)
示例#14
0
    def test_confirm_email__wrong_timeout(self):
        self.request_login(self.account.email)
        self.client.post(reverse("accounts:profile:update"), {"email": "*****@*****.**", "nick": "test_nick"})

        task = ChangeCredentialsTaskPrototype._db_get_object(0)
        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.TIMEOUT
        task._model.save()

        self.check_html_ok(
            self.client.get(
                url("accounts:profile:confirm-email", uuid=task.uuid), texts=["pgf-change-credentials-timeout"]
            )
        )
    def setUp(self):
        super(PostponedChangeCredentialsTaskTests, self).setUp()
        create_test_map()

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

        self.task = ChangeCredentialsTaskPrototype.create(self.account,
                                                          new_email='*****@*****.**',
                                                          new_password='******',
                                                          new_nick='test_nick',
                                                          relogin_required=True)

        self.postponed_task = ChangeCredentials(task_id=self.task.id)
    def setUp(self):
        super(PostponedChangeCredentialsTaskTests, self).setUp()
        create_test_map()

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

        self.task = ChangeCredentialsTaskPrototype.create(self.account,
                                                          new_email='*****@*****.**',
                                                          new_password='******',
                                                          new_nick='test_nick',
                                                          relogin_required=True)

        self.postponed_task = ChangeCredentials(task_id=self.task.id)
    def setUp(self):
        super(PostponedChangeCredentialsTaskTests, self).setUp()
        create_test_map()

        self.account = self.accounts_factory.create_account()

        self.task = ChangeCredentialsTaskPrototype.create(
            self.account,
            new_email="*****@*****.**",
            new_password="******",
            new_nick="test_nick",
            relogin_required=True,
        )

        self.postponed_task = ChangeCredentials(task_id=self.task.id)
示例#18
0
    def process(self):

        subject = '«Сказка»: подтвердите email'

        task = ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

        if task.account.id == get_system_user().id or task.account.is_bot:
            return True

        context = {'task': task}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([(task.account, task.new_email)], subject, text_content, html_content)
示例#19
0
    def test_change_credentials_nick(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_nick='test_nick')

        fake_cmd = FakeWorkerCommand()

        with mock.patch('the_tale.amqp_environment.environment.workers.supervisor.cmd_update_hero_with_account_data') as fake_cmd:
            postponed_task = task.change_credentials()

        self.assertNotEqual(postponed_task, None)

        self.assertEqual(Message.objects.all().count(), 0)

        self.assertEqual(fake_cmd.call_count, 0)

        self.assertEqual(django_authenticate(nick='test_nick', password='******'), None)
示例#20
0
    def process(self):

        subject = '«Сказка»: подтвердите email'

        task = ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

        if task.account.id == get_system_user().id or task.account.is_bot:
            return True

        context = {'task': task}

        html_content = jinja2.render(self.EMAIL_HTML_TEMPLATE, context)
        text_content = jinja2.render(self.EMAIL_TEXT_TEMPLATE, context)

        return logic.send_mail([(task.account, task.new_email)], subject, text_content, html_content)
示例#21
0
    def test_confirm_email__error_occured(self):
        self.request_login(self.account.email)
        self.client.post(reverse('accounts:profile:update'), {
            'email': '*****@*****.**',
            'nick': 'test_nick'
        })

        task = ChangeCredentialsTaskPrototype._db_get_object(0)
        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR
        task._model.save()

        self.check_html_ok(
            self.client.get(url('accounts:profile:confirm-email',
                                uuid=task.uuid),
                            texts=['pgf-change-credentials-error']))
    def test_change_credentials(self):
        task = ChangeCredentialsTaskPrototype.create(
            self.fast_account,
            new_email='*****@*****.**',
            new_password='******',
            new_nick='test_nick')

        self.assertTrue(
            AccountPrototype.get_by_id(self.fast_account.id).is_fast)

        with mock.patch(
                'the_tale.amqp_environment.environment.workers.supervisor.cmd_update_hero_with_account_data'
        ) as fake_cmd:
            postponed_task = task.change_credentials()

        self.assertNotEqual(postponed_task, None)
        self.assertEqual(fake_cmd.call_count, 0)
    def test_process_completed_state(self):
        task = ChangeCredentialsTaskPrototype.create(
            self.test_account, new_email='*****@*****.**')
        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.PROCESSED
        task.process(FakeLogger())
        self.assertEqual(task._model.state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.PROCESSED)

        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.UNPROCESSED
        task.process(FakeLogger())
        self.assertEqual(task._model.state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.UNPROCESSED)

        task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR
        task.process(FakeLogger())
        self.assertEqual(task._model.state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR)
    def test_change_credentials_nick(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account,
                                                     new_nick='test_nick')

        fake_cmd = FakeWorkerCommand()

        with mock.patch(
                'the_tale.amqp_environment.environment.workers.supervisor.cmd_update_hero_with_account_data'
        ) as fake_cmd:
            postponed_task = task.change_credentials()

        self.assertNotEqual(postponed_task, None)

        self.assertEqual(Message.objects.all().count(), 0)

        self.assertEqual(fake_cmd.call_count, 0)

        self.assertEqual(
            django_authenticate(nick='test_nick', password='******'), None)
示例#25
0
    def test_process_email_sent(self):
        task = ChangeCredentialsTaskPrototype.create(
            self.test_account,
            new_email='*****@*****.**',
            new_password='******')
        postponed_task = task.process(FakeLogger())
        self.assertEqual(postponed_task, None)
        self.assertEqual(task.state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT)
        self.assertEqual(Message.objects.all().count(), 1)
        self.assertEqual(
            django_authenticate(nick='test_user', password='******').id,
            task.account.id)
        self.assertEqual(
            django_authenticate(nick='test_user', password='******'), None)

        postponed_task = task.process(FakeLogger())
        self.assertEqual(task.state,
                         relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
        self.assertNotEqual(postponed_task, None)
 def test_request_email_confirmation_exceptions(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account,
                                                  new_password='******')
     self.assertRaises(exceptions.NewEmailNotSpecifiedError,
                       task.request_email_confirmation)
 def test_change_credentials_email(self):
     task = ChangeCredentialsTaskPrototype.create(
         self.test_account, new_email='*****@*****.**')
     postponed_task = task.change_credentials()
     self.assertNotEqual(postponed_task, None)
     self.assertEqual(Message.objects.all().count(), 0)
示例#28
0
 def test_process_duplicated_email(self):
     register_user('duplicated_user', '*****@*****.**', '111111')
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
     task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT
     task.process(FakeLogger())
     self.assertEqual(task._model.state, relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR)
示例#29
0
 def test_process_waiting_and_email_confirmation(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
     task.process(FakeLogger())
     self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT)
     self.assertEqual(Message.objects.all().count(), 1)
     self.assertEqual(django_authenticate(nick='test_user', password='******').id, task.account.id)
示例#30
0
    def task(self): return ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

    def process(self, main_task):
示例#31
0
 def test_change_credentials_email(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**')
     postponed_task = task.change_credentials()
     self.assertNotEqual(postponed_task, None)
     self.assertEqual(Message.objects.all().count(), 0)
示例#32
0
 def test_process_error(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email='*****@*****.**', new_password='******')
     task.process(FakeLogger())
     self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR)
     self.assertEqual(Message.objects.all().count(), 0)
示例#33
0
 def test_request_email_confirmation_exceptions(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_password='******')
     self.assertRaises(exceptions.NewEmailNotSpecifiedError, task.request_email_confirmation)
示例#34
0
 def test_process_waiting_and_nick_change(self):
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_nick='test_nick')
     postponed_task = task.process(FakeLogger())
     self.assertEqual(task.state, relations.CHANGE_CREDENTIALS_TASK_STATE.CHANGING)
     self.assertNotEqual(postponed_task, None)
     self.assertEqual(django_authenticate(nick='test_user', password='******').id, task.account.id)
示例#35
0
    def task(self): return ChangeCredentialsTaskPrototype.get_by_id(self.task_id)

    def process(self, main_task):
示例#36
0
    def test_change_credentials_password(self):
        task = ChangeCredentialsTaskPrototype.create(self.test_account, new_password='******')
        postponed_task = task.change_credentials()

        self.assertNotEqual(postponed_task, None)
        self.assertEqual(Message.objects.all().count(), 0)
示例#37
0
 def task(self):
     return ChangeCredentialsTaskPrototype.get_by_id(self.task_id)
示例#38
0
 def test_process_duplicated_email(self):
     duplicated_user = self.accounts_factory.create_account()
     task = ChangeCredentialsTaskPrototype.create(self.test_account, new_email=duplicated_user.email)
     task._model.state = relations.CHANGE_CREDENTIALS_TASK_STATE.EMAIL_SENT
     task.process(FakeLogger())
     self.assertEqual(task._model.state, relations.CHANGE_CREDENTIALS_TASK_STATE.ERROR)