-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da455d1
commit 65e82cf
Showing
4 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,15 @@ def setUp(self): | |
"email": "[email protected]", | ||
"avatar_url": "/avatars/1" | ||
}""" | ||
self.token = gogs_client.Token("mytoken") | ||
self.token_json_str = """{ | ||
"name": "new token", | ||
"sha1": "mytoken" | ||
}""" | ||
self.username_password = gogs_client.UsernamePassword( | ||
"auth_username", "password") | ||
self.expected_repo = gogs_client.GogsRepo.from_json(json.loads(self.repo_json_str)) | ||
self.expected_user = gogs_client.GogsUser.from_json(json.loads(self.user_json_str)) | ||
self.token = gogs_client.Token.from_json(json.loads(self.token_json_str)) | ||
|
||
@responses.activate | ||
def test_create_repo1(self): | ||
|
@@ -238,6 +242,31 @@ def test_authenticated_user(self): | |
user = self.client.authenticated_user(self.token) | ||
self.assert_users_equals(user, self.expected_user) | ||
|
||
@responses.activate | ||
def test_ensure_token(self): | ||
uri = self.path("/users/{}/tokens".format(self.username_password.username)) | ||
responses.add(responses.GET, uri, body="[]", status=200) | ||
responses.add(responses.POST, uri, body=self.token_json_str, status=200) | ||
responses.add(responses.GET, uri, body="["+self.token_json_str+"]", status=200) | ||
token = self.client.ensure_token(self.username_password, self.token.name, self.username_password.username) | ||
self.assert_tokens_equals(token, self.token) | ||
token = self.client.ensure_token(self.username_password, self.token.name, self.username_password.username) | ||
self.assert_tokens_equals(token, self.token) | ||
|
||
@responses.activate | ||
def test_ensure_auth_token(self): | ||
uri = self.path("/user") | ||
responses.add(responses.GET, uri, body=self.user_json_str, status=200) | ||
uri = self.path("/users/{}/tokens".format(self.expected_user.username)) | ||
responses.add(responses.GET, uri, body="[]", status=200) | ||
responses.add(responses.POST, uri, body=self.token_json_str, status=200) | ||
tokens = self.client.get_tokens(self.username_password) | ||
self.assertEqual(tokens, []) | ||
tokeninfo = self.client.create_token(self.username_password, self.token.name) | ||
self.assert_tokens_equals(tokeninfo, self.token) | ||
token = self.client.ensure_token(self.username_password, self.token.name) | ||
self.assert_tokens_equals(token, self.token) | ||
|
||
# helper methods | ||
|
||
@staticmethod | ||
|
@@ -277,6 +306,10 @@ def assert_users_equals(self, user, expected): | |
self.assertEqual(user.email, expected.email) | ||
self.assertEqual(user.avatar_url, expected.avatar_url) | ||
|
||
def assert_tokens_equals(self, token, expected): | ||
self.assertEqual(token.name, expected.name) | ||
self.assertEqual(token.token, expected.token) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |