コード例 #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
コード例 #2
0
ファイル: test_utils.py プロジェクト: owocki/GiraffeTools
    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
コード例 #3
0
ファイル: test_utils.py プロジェクト: owocki/GiraffeTools
    def test_build_auth_dict(self):
        """Test the github utility build_auth_dict method."""
        auth_dict = build_auth_dict(self.user_oauth_token)

        assert isinstance(auth_dict, dict)
        assert auth_dict == {
            'api_url': settings.GITHUB_API_BASE_URL,
            'client_id': settings.GITHUB_CLIENT_ID,
            'client_secret': settings.GITHUB_CLIENT_SECRET,
            'oauth_token': self.user_oauth_token
        }
コード例 #4
0
    def test_build_auth_dict(self):
        """Test the github utility build_auth_dict method."""
        auth_dict = build_auth_dict(self.user_oauth_token)

        assert isinstance(auth_dict, dict)
        assert auth_dict == {
            'api_url': settings.GITHUB_API_BASE_URL,
            'client_id': settings.GITHUB_CLIENT_ID,
            'client_secret': settings.GITHUB_CLIENT_SECRET,
            'oauth_token': self.user_oauth_token
        }
コード例 #5
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 == ''
コード例 #6
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 == ''
コード例 #7
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
コード例 #8
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
コード例 #9
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