Beispiel #1
0
    def test_provider_identity_error(self):
        MockResponses.provider_identity(self.provider, code=401)

        with self.assertRaises(ProviderError) as e:
            self.provider.identity('qwerty')

        self.assertEqual(e.exception.code, 401)
Beispiel #2
0
    def test_provider_touch_error(self):
        MockResponses.provider_touch(self.provider, identity='123', code=503)

        with self.assertRaises(ProviderError) as e:
            self.provider.touch('qwerty', '123')

        self.assertEqual(e.exception.code, 503)
Beispiel #3
0
    def test_provider_tokenize_error(self):
        MockResponses.provider_tokenize_access(self.provider, code=400)

        with self.assertRaises(ProviderError) as e:
            self.provider.tokenize('qwerty')

        self.assertEqual(e.exception.code, 400)
Beispiel #4
0
    def test_provider_tokenize_refresh(self):
        MockResponses.provider_tokenize_refresh()

        result = self.provider.tokenize('qwerty', refresh=True)

        self.assertIn('access_token', result)
        self.assertIn('refresh_token', result)
Beispiel #5
0
    def test_provider_fetch_error(self):
        body = FakeResponses.resume(self.provider.name)
        MockResponses.provider_fetch(self.provider, body=body, code=500)

        with self.assertRaises(ProviderError) as e:
            self.provider.fetch('qwerty')

        self.assertEqual(e.exception.code, 500)
Beispiel #6
0
    def test_provider_fetch(self):
        body = FakeResponses.resume(self.provider.name)
        MockResponses.provider_fetch(self.provider, body=body)

        result = self.provider.fetch('qwerty')

        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
Beispiel #7
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)
Beispiel #8
0
    def test_provider_touch_limit_error(self):
        MockResponses.provider_touch(
            self.provider, identity='123',
            code=self.provider.touch_limit_error[0],
            body=self.provider.touch_limit_error[1])

        with self.assertRaises(TouchLimitError) as e:
            self.provider.touch('qwerty', '123')

        self.assertEqual(e.exception.code, self.provider.touch_limit_error[0])
Beispiel #9
0
    def test_view_login_provider_error(self):
        for provider in providers.values():
            MockResponses.provider_tokenize_access(provider)
            MockResponses.provider_identity(provider, code=400)

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

            self.assertFalse(Account.query.all())
            self.assertEqual(response.status_code, 302)
            self.assertTrue(response.location.endswith(url_for('views.main')))
Beispiel #10
0
    def test_view_login(self):
        for provider in providers.values():
            MockResponses.provider_tokenize_access(provider)
            MockResponses.provider_identity(provider)

            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))
Beispiel #11
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)
Beispiel #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)
Beispiel #13
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)
Beispiel #14
0
    def test_provider_touch(self):
        MockResponses.provider_touch(self.provider, identity='123')

        result = self.provider.touch('qwerty', '123')

        self.assertTrue(result)
Beispiel #15
0
    def test_provider_identity(self):
        MockResponses.provider_identity(self.provider, identity='12345')

        result = self.provider.identity('qwerty')

        self.assertIn('12345', result)