Esempio n. 1
0
    def test_revoke_token(self):
        """Test the github utility revoke_token method."""
        auth_dict = build_auth_dict(self.user_oauth_token)
        url = TOKEN_URL.format(**auth_dict)
        responses.add(responses.DELETE, url, headers=HEADERS, status=204)
        result = revoke_token(self.user_oauth_token)

        assert responses.calls[0].request.url == url
        assert result is True
Esempio n. 2
0
    def test_revoke_token(self):
        """Test the github utility revoke_token method."""
        auth_dict = build_auth_dict(self.user_oauth_token)
        url = TOKEN_URL.format(**auth_dict)
        responses.add(responses.DELETE, url, headers=HEADERS, status=204)
        result = revoke_token(self.user_oauth_token)

        assert responses.calls[0].request.url == url
        assert result is True
Esempio n. 3
0
    def test_reset_token(self):
        """Test the github utility reset_token method."""
        auth_dict = build_auth_dict(self.user_oauth_token)
        url = TOKEN_URL.format(**auth_dict)
        data = {'token': self.user_oauth_token}
        responses.add(responses.POST, url, json=data, headers=HEADERS, status=200)
        responses.add(responses.POST, url, headers=HEADERS, status=404)
        result = reset_token(self.user_oauth_token)
        result_not_found = reset_token(self.user_oauth_token)

        assert responses.calls[0].request.url == url
        assert responses.calls[1].request.url == url
        assert result == self.user_oauth_token
        assert result_not_found == ''
Esempio n. 4
0
    def test_reset_token(self):
        """Test the github utility reset_token method."""
        auth_dict = build_auth_dict(self.user_oauth_token)
        url = TOKEN_URL.format(**auth_dict)
        data = {'token': self.user_oauth_token}
        responses.add(responses.POST, url, json=data, headers=HEADERS, status=200)
        responses.add(responses.POST, url, headers=HEADERS, status=404)
        result = reset_token(self.user_oauth_token)
        result_not_found = reset_token(self.user_oauth_token)

        assert responses.calls[0].request.url == url
        assert responses.calls[1].request.url == url
        assert result == self.user_oauth_token
        assert result_not_found == ''
Esempio n. 5
0
    def test_is_github_token_valid(self):
        """Test the github utility is_github_token_valid method."""
        now = timezone.now()
        expired = (now - timedelta(hours=2)).isoformat()
        return_false = is_github_token_valid()
        return_valid = is_github_token_valid(self.user_oauth_token, now.isoformat())
        params = build_auth_dict(self.user_oauth_token)
        url = TOKEN_URL.format(**params)
        responses.add(responses.GET, url, headers=HEADERS, status=200)
        return_expired = is_github_token_valid(self.user_oauth_token, expired)

        assert responses.calls[0].request.url == url
        assert return_false is False
        assert return_valid is True
        assert return_expired is True
Esempio n. 6
0
    def test_is_github_token_valid(self):
        """Test the github utility is_github_token_valid method."""
        now = timezone.now()
        expired = (now - timedelta(hours=2)).isoformat()
        return_false = is_github_token_valid()
        return_valid = is_github_token_valid(self.user_oauth_token, now.isoformat())
        params = build_auth_dict(self.user_oauth_token)
        url = TOKEN_URL.format(**params)
        responses.add(responses.GET, url, headers=HEADERS, status=200)
        return_expired = is_github_token_valid(self.user_oauth_token, expired)

        assert responses.calls[0].request.url == url
        assert return_false is False
        assert return_valid is True
        assert return_expired is True
Esempio n. 7
0
    def is_github_token_valid(self):
        """Check whether or not a Github OAuth token is valid.

        Args:
            access_token (str): The Github OAuth token.

        Returns:
            bool: Whether or not the provided OAuth token is valid.

        """
        if not self.github_access_token:
            return False

        _params = build_auth_dict(self.github_access_token)
        url = TOKEN_URL.format(**_params)
        response = requests.get(url,
                                auth=(_params['client_id'],
                                      _params['client_secret']),
                                headers=HEADERS)

        if response.status_code == 200:
            return True
        return False