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 #2
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)
 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')
Exemple #4
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_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 #6
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')
Exemple #7
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 #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)