Exemple #1
0
 def setUp(self):
     super(TestRegistrationTask, self).setUp()
     create_test_map()
     self.task = RegistrationTask(account_id=None,
                                  referer=None,
                                  referral_of_id=None,
                                  action_id=None)
Exemple #2
0
 def test_process_success__with_action(self):
     result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
     task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id='action')
     self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
     self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
     self.assertTrue(task.account)
     self.assertEqual(task.account.action_id, 'action')
 def test_process_success__with_action(self):
     result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
     task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id='action')
     self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
     self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
     self.assertTrue(task.account)
     self.assertEqual(task.account.action_id, 'action')
 def test_process_success__with_referer(self):
     referer = 'http://example.com/forum/post/1/'
     task = RegistrationTask(account_id=None, referer=referer, referral_of_id=None, action_id=None)
     self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
     self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
     self.assertTrue(task.account)
     self.assertEqual(task.account.referer, referer)
     self.assertEqual(task.account.referer_domain, 'example.com')
Exemple #5
0
 def test_process_success__with_referer(self):
     referer = 'http://example.com/forum/post/1/'
     task = RegistrationTask(account_id=None, referer=referer, referral_of_id=None, action_id=None)
     self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
     self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
     self.assertTrue(task.account)
     self.assertEqual(task.account.referer, referer)
     self.assertEqual(task.account.referer_domain, 'example.com')
class TestRegistrationTask(testcase.TestCase):

    def setUp(self):
        super(TestRegistrationTask, self).setUp()
        create_test_map()
        self.task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None)

    def test_create(self):
        self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.UNPROCESSED)

    def test_get_unique_nick(self):
        self.assertTrue(self.task.get_unique_nick() != self.task.get_unique_nick())

    def test_process_success(self):
        self.assertEqual(self.task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(self.task.account)
        self.assertTrue(self.task.account.is_fast)
        self.assertEqual(Account.objects.all().count(), 1)

    def test_process_success__with_referer(self):
        referer = 'http://example.com/forum/post/1/'
        task = RegistrationTask(account_id=None, referer=referer, referral_of_id=None, action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(task.account)
        self.assertEqual(task.account.referer, referer)
        self.assertEqual(task.account.referer_domain, 'example.com')

    def test_process_success__with_referral(self):
        result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
        task = RegistrationTask(account_id=None, referer=None, referral_of_id=account_id, action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(task.account)
        self.assertEqual(task.account.referral_of_id, account_id)

    def test_process_success__with_action(self):
        result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
        task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id='action')
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(task.account)
        self.assertEqual(task.account.action_id, 'action')

    @mock.patch('the_tale.accounts.logic.register_user', lambda *argv, **kwargs: (REGISTER_USER_RESULT.OK+1, None, None))
    def test_process_unknown_error(self):
        self.assertEqual(self.task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.ERROR)
        self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.UNKNOWN_ERROR)
        self.assertEqual(Account.objects.all().count(), 0)

    @mock.patch('the_tale.accounts.logic.register_user', lambda *argv, **kwargs: raise_exception())
    def test_process_exceptin(self):
        self.assertRaises(Exception, self.task.process, FakePostpondTaskPrototype())
        self.assertEqual(Account.objects.all().count(), 0)
Exemple #7
0
class TestRegistrationTask(testcase.TestCase):

    def setUp(self):
        super(TestRegistrationTask, self).setUp()
        create_test_map()
        self.task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None)

    def test_create(self):
        self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.UNPROCESSED)

    def test_get_unique_nick(self):
        self.assertTrue(self.task.get_unique_nick() != self.task.get_unique_nick())

    def test_process_success(self):
        self.assertEqual(self.task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(self.task.account)
        self.assertTrue(self.task.account.is_fast)
        self.assertEqual(Account.objects.all().count(), 1)

    def test_process_success__with_referer(self):
        referer = 'http://example.com/forum/post/1/'
        task = RegistrationTask(account_id=None, referer=referer, referral_of_id=None, action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(task.account)
        self.assertEqual(task.account.referer, referer)
        self.assertEqual(task.account.referer_domain, 'example.com')

    def test_process_success__with_referral(self):
        result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
        task = RegistrationTask(account_id=None, referer=None, referral_of_id=account_id, action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(task.account)
        self.assertEqual(task.account.referral_of_id, account_id)

    def test_process_success__with_action(self):
        result, account_id, bundle_id = register_user('test_user', '*****@*****.**', '111111')
        task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id='action')
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)
        self.assertEqual(task.state, REGISTRATION_TASK_STATE.PROCESSED)
        self.assertTrue(task.account)
        self.assertEqual(task.account.action_id, 'action')

    @mock.patch('the_tale.accounts.logic.register_user', lambda *argv, **kwargs: (REGISTER_USER_RESULT.OK+1, None, None))
    def test_process_unknown_error(self):
        self.assertEqual(self.task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.ERROR)
        self.assertEqual(self.task.state, REGISTRATION_TASK_STATE.UNKNOWN_ERROR)
        self.assertEqual(Account.objects.all().count(), 0)

    @mock.patch('the_tale.accounts.logic.register_user', lambda *argv, **kwargs: raise_exception())
    def test_process_exceptin(self):
        self.assertRaises(Exception, self.task.process, FakePostpondTaskPrototype())
        self.assertEqual(Account.objects.all().count(), 0)
Exemple #8
0
    def test_block_expired_accounts(self):
        task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()), POSTPONED_TASK_LOGIC_RESULT.SUCCESS)

        task.account._model.created_at = datetime.datetime.fromtimestamp(0)
        task.account._model.save()

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

        logic.block_expired_accounts()

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

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

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
Exemple #9
0
    def test_handle_registration__task_not_processed(self):
        registration_task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None)
        task = PostponedTaskPrototype.create(registration_task)

        with mock.patch('the_tale.accounts.middleware.login_user') as login_user:
            result = self.middleware.handle_registration(self.make_request_html('/', session={accounts_settings.SESSION_REGISTRATION_TASK_ID_KEY: task.id}))

        self.assertTrue(result.is_TASK_NOT_PROCESSED)
        self.assertEqual(login_user.call_count, 0)
Exemple #10
0
    def test_block_expired_accounts(self):
        task = RegistrationTask(account_id=None,
                                referer=None,
                                referral_of_id=None,
                                action_id=None)
        self.assertEqual(task.process(FakePostpondTaskPrototype()),
                         POSTPONED_TASK_LOGIC_RESULT.SUCCESS)

        task.account._model.created_at = datetime.datetime.fromtimestamp(0)
        task.account._model.save()

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

        logic.block_expired_accounts()

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

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

        self.assertEqual(AccountAchievementsPrototype._db_count(), 0)
Exemple #11
0
    def test_handle_registration__task_processed(self):
        # self.request_login('*****@*****.**')

        registration_task = RegistrationTask(account_id=None,
                                             referer=None,
                                             referral_of_id=None,
                                             action_id=None)
        task = postponed_tasks.PostponedTaskPrototype.create(registration_task)
        task.process(logger=mock.Mock)

        with mock.patch(
                'the_tale.accounts.middleware.login_user') as login_user:
            result = self.middleware.handle_registration(
                self.make_request_html(
                    '/',
                    session={
                        accounts_settings.SESSION_REGISTRATION_TASK_ID_KEY:
                        task.id
                    }))

        self.assertTrue(result.is_USER_LOGINED)
        self.assertEqual(login_user.call_count, 1)
Exemple #12
0
 def setUp(self):
     super(TestRegistrationTask, self).setUp()
     create_test_map()
     self.task = RegistrationTask(account_id=None, referer=None, referral_of_id=None, action_id=None)