def test_fetch_access_data_can_use_a_custom_oauth_url(self):
        self.stub_get_requests(response_body=self.valid_response_json)
        authenticator = Authenticator(
            client_id="foo",
            client_secret="bar",
            oauth_base_url="http://example.com/oauth",
        )

        authenticator.fetch_access_data("some-code")

        self.assert_get_request("http://example.com/oauth/access_token.json")
Пример #2
0
    def test_fetch_access_data_can_use_a_custom_oauth_url(self):
        self.stub_get_requests(response_body=self.valid_response_json)
        authenticator = Authenticator(
            client_id="foo",
            client_secret="bar",
            oauth_base_url="http://example.com/oauth",
        )

        authenticator.fetch_access_data("some-code")

        self.assert_get_request("http://example.com/oauth/access_token.json")
Пример #3
0
    def test_fetch_access_data_returns_parsed_response_json(self):
        self.stub_get_requests(response_body=self.valid_response_json)
        authenticator = Authenticator(client_id="foo", client_secret="bar")

        response_data = authenticator.fetch_access_data("my-code")

        self.assert_get_request(
            url="https://www.yammer.com/oauth2/access_token.json",
            headers={},
            params={
                "client_id": "foo",
                "client_secret": "bar",
                "code": "my-code",
            },
        )
        self.assertEqual(self.valid_response_data, response_data)
    def test_fetch_access_data_returns_parsed_response_json(self):
        self.stub_get_requests(response_body=self.valid_response_json)
        authenticator = Authenticator(client_id="foo", client_secret="bar")

        response_data = authenticator.fetch_access_data("my-code")

        self.assert_get_request(
            url="https://www.yammer.com/oauth2/access_token.json",
            headers={},
            params={
                "client_id": "foo",
                "client_secret": "bar",
                "code": "my-code",
            },
        )
        self.assertEqual(self.valid_response_data, response_data)
Пример #5
0
    def test_authorization_url_using_the_default_oauth_dialog_url(self):
        authenticator = Authenticator(
            client_id="foo",
            client_secret="bar",
        )
        auth_url_parts, params = self.parsed_authorization_url(authenticator)

        self.assertEqual("https", auth_url_parts.scheme)
        self.assertEqual("www.yammer.com", auth_url_parts.netloc)
        self.assertEqual("/dialog/oauth", auth_url_parts.path)
        self.assertEqual(
            {
                "client_id": ["foo"],
                "redirect_uri": ["http://example.com/auth/callback"],
            },
            params,
        )
Пример #6
0
    def test_authorization_url_can_use_a_custom_oauth_dialog_url(self):
        authenticator = Authenticator(
            client_id="my-client-id",
            client_secret="bar",
            oauth_dialog_url="http://example.com/test/dialog",
        )
        auth_url_parts, params = self.parsed_authorization_url(authenticator)

        self.assertEqual("http", auth_url_parts.scheme)
        self.assertEqual("example.com", auth_url_parts.netloc)
        self.assertEqual("/test/dialog", auth_url_parts.path)
        self.assertEqual(
            {
                "client_id": ["my-client-id"],
                "redirect_uri": ["http://example.com/auth/callback"],
            },
            params,
        )
Пример #7
0
    def test_fetch_access_token_handles_an_unexpected_response_format(self):
        self.stub_get_requests(response_body="""{"foo": "bar"}""")
        authenticator = Authenticator(client_id="foo", client_secret="bar")

        self.assertRaises(ResponseError, authenticator.fetch_access_token,
                          "my-code")