Example #1
0
    def test_view_resume_switch(self):
        for provider in providers.values():
            user = FakeModels.user()
            account = FakeModels.account(provider=provider, user=user)
            resume = FakeModels.resume(account=account, provider=provider)
            self.auth_user(user=user)

            body = dict(id=resume.identity)
            response = self.client.post(
                url_for('views.switch'), data=body,
                headers={'X-CSRFToken': generate_csrf()})
            same_resume = Resume.query.get(resume.identity)

            self.assertFalse(same_resume.autoupdate)
            self.assertEqual(response.status_code, 400)

            another_resume = FakeModels.resume(provider=provider)
            body = dict(resume=another_resume.identity)
            response = self.client.post(url_for('views.switch'), data=body)
            same_resume = Resume.query.get(another_resume.identity)

            self.assertFalse(same_resume.autoupdate)
            self.assertEqual(response.status_code, 404)

            body = dict(resume=resume.identity)
            response = self.client.post(url_for('views.switch'), data=body)
            same_resume = Resume.query.get(resume.identity)

            self.assertTrue(same_resume.autoupdate)
            self.assertEqual(response.status_code, 200)
Example #2
0
    def test_view_accounts(self):
        for provider in providers.values():
            user = FakeModels.user()
            FakeModels.account(provider=provider, user=user)

            self.auth_user(user=user)
            response = self.client.get(url_for('views.accounts'))

            self.assertEqual(response.status_code, 200)
Example #3
0
    def test_task_refresh_tokens(self):
        for provider in providers.values():
            MockResponses.provider_tokenize_refresh()
            FakeModels.account(provider=provider)

        result = tasks.refresh_tokens()

        total = len(providers)
        self.assertTaskResult(result, total=total, success=total)
Example #4
0
    def test_task_cleanup_tasks(self):
        for _ in range(4):
            FakeModels.task()

        before_cleanup = Task.query.count()
        self.assertEqual(4, before_cleanup)

        result = tasks.cleanup_tasks(2)
        self.assertEqual(2, result)

        after_cleanup = Task.query.count()
        self.assertEqual(2, after_cleanup)
Example #5
0
    def test_view_login_again(self):
        for provider in providers.values():
            identity = f'{uuid4()}'
            MockResponses.provider_tokenize_access(provider)
            MockResponses.provider_identity(provider, identity=identity)
            FakeModels.account(provider, identity)

            url = url_for('views.login', provider=provider.name, code=123)
            response = self.client.get(url)

            self.assertResponseRedirect(response, url_for('views.resume'))

        self.assertEqual(Account.query.count(), len(providers))
Example #6
0
    def test_view_resume_provider_error(self):
        for provider in providers.values():
            MockResponses.provider_fetch(provider, body=dict(), code=401)

            user = FakeModels.user()
            account = FakeModels.account(provider=provider, user=user)

            self.auth_user(user=user)
            response = self.client.get(url_for('views.resume'))
            same_account = Account.query.get(account.identity)

            self.assertEqual(response.status_code, 200)
            self.assertFalse(same_account.resume)
Example #7
0
    def test_task_cleanup_users(self):
        user1, user2 = FakeModels.user(), FakeModels.user()
        FakeModels.account(user=user1)

        before_cleanup = User.query.all()
        self.assertIn(user1, before_cleanup)
        self.assertIn(user2, before_cleanup)

        result = tasks.cleanup_users()
        self.assertEqual(1, result)

        after_cleanup = User.query.all()
        self.assertIn(user1, after_cleanup)
        self.assertNotIn(user2, after_cleanup)
Example #8
0
    def test_task_cleanup_resume(self):
        resume1 = FakeModels.resume(autoupdate=True)
        resume2 = FakeModels.resume(autoupdate=False)

        before_cleanup = Resume.query.all()
        self.assertIn(resume1, before_cleanup)
        self.assertIn(resume2, before_cleanup)

        result = tasks.cleanup_resume()
        self.assertEqual(1, result)

        after_cleanup = Resume.query.all()
        self.assertIn(resume1, after_cleanup)
        self.assertNotIn(resume2, after_cleanup)
Example #9
0
    def test_task_cleanup_accounts(self):
        account1 = FakeModels.account()
        account2 = FakeModels.account()
        FakeModels.resume(account=account1)

        before_cleanup = Account.query.all()
        self.assertIn(account1, before_cleanup)
        self.assertIn(account2, before_cleanup)

        result = tasks.cleanup_accounts()
        self.assertEqual(1, result)

        after_cleanup = Account.query.all()
        self.assertIn(account1, after_cleanup)
        self.assertNotIn(account2, after_cleanup)
Example #10
0
    def test_task_touch_resume(self):
        for provider in providers.values():
            FakeModels.resume(provider=provider, autoupdate=True)
            resume = FakeModels.resume(provider=provider,
                                       autoupdate=True,
                                       old=True)
            MockResponses.provider_touch(provider, identity=resume.identity)

        result = tasks.touch_resume()

        prov = len(providers)
        self.assertTaskResult(result,
                              total=prov * 2,
                              success=prov,
                              skipped=prov)
Example #11
0
    def test_model_cascade_delete(self):
        user = FakeModels.user()

        account = FakeModels.account(user=user)
        self.assertIn(account, user.accounts)
        self.assertTrue(Account.query.all())

        resume = FakeModels.resume(account=account)
        self.assertIn(resume, account.resume)
        self.assertTrue(Resume.query.all())

        db.session.delete(user)
        db.session.commit()

        self.assertFalse(Account.query.all())
        self.assertFalse(Resume.query.all())
Example #12
0
    def test_task_touch_resume_disable(self):
        for provider in providers.values():
            resume = FakeModels.resume(provider=provider,
                                       autoupdate=True,
                                       old=True)
            MockResponses.provider_touch(provider,
                                         identity=resume.identity,
                                         code=500)

            result = tasks.touch_resume()
            same_resume = Resume.query.get(resume.identity)

            self.assertFalse(same_resume.autoupdate)
            self.assertTaskResult(result, total=1, success=0, skipped=1)
Example #13
0
    def test_view_logout(self):
        self.auth_user(FakeModels.user())
        response = self.client.get(url_for('views.logout'))

        self.assertResponseRedirect(response, url_for('views.main'))
Example #14
0
 def test_view_main(self):
     FakeModels.task()
     for provider in providers.values():
         self.auth_user(FakeModels.user(), last_provider=provider.name)
         response = self.client.get(url_for('views.main'))
         self.assertEqual(response.status_code, 200)