Beispiel #1
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)
Beispiel #2
0
    def test_process_success(self):
        with mock.patch.object(FakePostponedInternalTask, 'process',
                               mock.Mock(return_value=POSTPONED_TASK_LOGIC_RESULT.SUCCESS)) as call_counter:
            self.task.process(FakeLogger())

        self.assertEqual(call_counter.call_count, 1)
        self.assertTrue(self.task.state.is_processed)
 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)
    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)
Beispiel #5
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)
 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)
 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=self.test_account.nick,
                             password='******').id, task.account.id)
 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=self.test_account.nick,
                             password='******').id, task.account.id)
Beispiel #9
0
    def test_process_exception(self):

        def process_with_exception(self, *argv, **kwargs):
            raise Exception()

        with mock.patch.object(FakePostponedInternalTask, 'process', process_with_exception):
            self.task.process(FakeLogger())

        self.assertTrue(self.task.state.is_exception)
        self.assertTrue(self.task.comment)
 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)
Beispiel #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)
Beispiel #12
0
    def test_process_not_waiting_state(self):

        for state in POSTPONED_TASK_STATE._ALL:

            if state == POSTPONED_TASK_STATE.WAITING:
                continue

            self.task.state = state

            with mock.patch.object(FakePostponedInternalTask, 'process',
                                   mock.Mock(return_value=POSTPONED_TASK_LOGIC_RESULT.SUCCESS)) as call_counter:
                self.task.process(FakeLogger())

            self.assertEqual(call_counter.call_count, 0)
            self.assertEqual(self.task.state, state)
Beispiel #13
0
    def test_process_internal_wait(self):

        with mock.patch.object(FakePostponedInternalTask, 'process',
                               mock.Mock(return_value=POSTPONED_TASK_LOGIC_RESULT.WAIT)) as call_counter:
            self.task.process(FakeLogger())

        self.assertEqual(len(self.task._postsave_actions), 1)

        with mock.patch('the_tale.common.postponed_tasks.workers.refrigerator.Worker.cmd_wait_task') as cmd_wait_task:
            self.task.do_postsave_actions()

        self.assertEqual(cmd_wait_task.call_count, 1)

        self.assertEqual(call_counter.call_count, 1)
        self.assertTrue(self.task.state.is_waiting)
Beispiel #14
0
    def test_profile_update_fast_errors(self):
        response = self.client.post(reverse('accounts:registration:fast'))
        PostponedTaskPrototype(model=PostponedTask.objects.all()[0]).process(
            FakeLogger())

        response = self.client.post(reverse('accounts:profile:update'),
                                    {'email': '*****@*****.**'})
        self.check_ajax_error(response, 'accounts.profile.update.form_errors')

        response = self.client.post(reverse('accounts:profile:update'),
                                    {'password': '******'})
        self.check_ajax_error(response, 'accounts.profile.update.form_errors')

        response = self.client.post(reverse('accounts:profile:update'),
                                    {'nick': 'test_nick'})
        self.check_ajax_error(response, 'accounts.profile.update.form_errors')

        response = self.client.post(reverse('accounts:profile:update'), {
            'email': '*****@*****.**',
            'nick': 'test_nick'
        })
        self.check_ajax_error(response, 'accounts.profile.update.empty_fields')

        response = self.client.post(reverse('accounts:profile:update'), {
            'email': '*****@*****.**',
            'password': '******'
        })
        self.check_ajax_error(response, 'accounts.profile.update.form_errors')

        response = self.client.post(reverse('accounts:profile:update'), {
            'password': '******',
            'nick': 'test_nick'
        })
        self.check_ajax_error(response, 'accounts.profile.update.form_errors')

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