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)
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()
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_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)
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)
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_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 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)
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() 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)
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)
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)
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)
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)
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_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)
def task(self): return ChangeCredentialsTaskPrototype.get_by_id(self.task_id) def process(self, main_task):
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)
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='test_user', password='******').id, task.account.id)
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)
def task(self): return ChangeCredentialsTaskPrototype.get_by_id(self.task_id)
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)