Пример #1
0
    def test_valid_oauth_credentials(self, Client):  # noqa
        client = Client.return_value

        client.request.return_value = [
            _Response({}),
            "oauth_token=aabbccdd&oauth_token_secret=efgh1234"
        ]

        url = reverse("services", args=['readability'])
        response = self.app.get(url, user='******')
        form = response.forms['readability']
        form['username'] = '******'
        form['password'] = '******'
        response = form.submit().follow()
        self.assertContains(
            response,
            "You have successfully added Readability",
        )

        client.request.assert_called_with(
            "https://www.readability.com/api/rest/v1/oauth/access_token/",
            method='POST',
            body=('x_auth_mode=client_auth&x_auth_password=correct+password&'
                  'x_auth_username=example'),
        )

        user = User.objects.get(pk=self.user.pk)
        self.assertEqual(user.read_later, 'readability')
        self.assertEqual(json.loads(user.read_later_credentials), {
            "oauth_token": "aabbccdd",
            "oauth_token_secret": "efgh1234",
        })
Пример #2
0
    def test_valid_oauth_credentials(self, Client):  # noqa
        client = Client.return_value

        client.request.return_value = [
            _Response({}), "oauth_token=aabbccdd&oauth_token_secret=efgh1234"
        ]

        url = reverse("services", args=['readability'])
        response = self.app.get(url, user='******')
        form = response.forms['readability']
        form['username'] = '******'
        form['password'] = '******'
        response = form.submit().follow()
        self.assertContains(
            response,
            "You have successfully added Readability",
        )

        client.request.assert_called_with(
            "https://www.readability.com/api/rest/v1/oauth/access_token/",
            method='POST',
            body=('x_auth_mode=client_auth&x_auth_password=correct+password&'
                  'x_auth_username=example'),
        )

        user = User.objects.get(pk=self.user.pk)
        self.assertEqual(user.read_later, 'readability')
        self.assertEqual(json.loads(user.read_later_credentials), {
            "oauth_token": "aabbccdd",
            "oauth_token_secret": "efgh1234",
        })
Пример #3
0
    def test_invalid_oauth_credentials(self, Client):
        client = Client.return_value
        client.request.return_value = [_Response({"status": 401}), "xAuth error"]

        url = reverse("services", args=["instapaper"])
        data = {"username": "******", "password": "******"}
        response = self.client.post(url, data)
        self.assertContains(response, "Unable to verify")
        client.request.assert_called_with(
            "https://www.instapaper.com/api/1/oauth/access_token",
            body=("x_auth_mode=client_auth&" "x_auth_password=incorrect+password&" "x_auth_username=example"),
            method="POST",
        )
Пример #4
0
    def test_invalid_oauth_credentials(self, Client):
        client = Client.return_value
        client.request.return_value = [_Response({"status": 401}), "xAuth error"]

        url = reverse("services", args=["instapaper"])
        response = self.app.get(url, user="******")
        form = response.forms["instapaper"]
        data = {"username": "******", "password": "******"}
        for key, value in data.items():
            form[key] = value
        response = form.submit()
        self.assertContains(response, "Unable to verify")
        client.request.assert_called_with(
            "https://www.instapaper.com/api/1/oauth/access_token",
            body=("x_auth_mode=client_auth&" "x_auth_password=incorrect+password&" "x_auth_username=example"),
            method="POST",
        )
Пример #5
0
    def test_valid_oauth_credentials(self, Client):
        client = Client.return_value

        client.request.return_value = [_Response({}), "oauth_token=aabbccdd&oauth_token_secret=efgh1234"]

        url = reverse("services", args=["readability"])
        data = {"username": "******", "password": "******"}
        response = self.client.post(url, data, follow=True)
        self.assertEqual(len(response.redirect_chain), 1)
        self.assertContains(response, "You have successfully added Readability")

        client.request.assert_called_with(
            "https://www.readability.com/api/rest/v1/oauth/access_token/",
            method="POST",
            body=("x_auth_mode=client_auth&x_auth_password=correct+password&" "x_auth_username=example"),
        )

        user = User.objects.get(pk=self.user.pk)
        self.assertEqual(user.read_later, "readability")
        self.assertEqual(
            json.loads(user.read_later_credentials), {"oauth_token": "aabbccdd", "oauth_token_secret": "efgh1234"}
        )
Пример #6
0
    def test_invalid_oauth_credentials(self, Client):  # noqa
        client = Client.return_value
        client.request.return_value = [_Response({'status': 401}),
                                       "xAuth error"]

        url = reverse("services", args=['instapaper'])
        response = self.app.get(url, user='******')
        form = response.forms['instapaper']
        data = {
            'username': '******',
            'password': '******',
        }
        for key, value in data.items():
            form[key] = value
        response = form.submit()
        self.assertContains(response, "Unable to verify")
        client.request.assert_called_with(
            'https://www.instapaper.com/api/1/oauth/access_token',
            body=('x_auth_mode=client_auth&'
                  'x_auth_password=incorrect+password&'
                  'x_auth_username=example'),
            method='POST',
        )
Пример #7
0
    def test_invalid_oauth_credentials(self, Client):  # noqa
        client = Client.return_value
        client.request.return_value = [
            _Response({'status': 401}), "xAuth error"
        ]

        url = reverse("services", args=['instapaper'])
        response = self.app.get(url, user='******')
        form = response.forms['instapaper']
        data = {
            'username': '******',
            'password': '******',
        }
        for key, value in data.items():
            form[key] = value
        response = form.submit()
        self.assertContains(response, "Unable to verify")
        client.request.assert_called_with(
            'https://www.instapaper.com/api/1/oauth/access_token',
            body=('x_auth_mode=client_auth&'
                  'x_auth_password=incorrect+password&'
                  'x_auth_username=example'),
            method='POST',
        )