Ejemplo 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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def test_reset_token(self):
        """Test the github utility reset_token method."""
        auth_dict = build_auth_dict()
        url = TOKEN_URL.format(**auth_dict)
        data = {'access_token': self.user_oauth_token}
        responses.add(responses.PATCH,
                      url,
                      json=data,
                      headers=HEADERS,
                      status=200)
        responses.add(responses.PATCH, 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 == ''