@@ -23,7 +23,9 @@ def setUp(self):
2323 "email": "u@gogs.io",
2424 "avatar_url": "/avatars/1"
2525 },
26+ "name": "Hello-World",
2627 "full_name": "unknwon/Hello-World",
28+ "description": "Some description",
2729 "private": false,
2830 "fork": false,
2931 "parent": null,
@@ -48,7 +50,9 @@ def setUp(self):
4850 "email": "u@gogs.io",
4951 "avatar_url": "/avatars/1"
5052 },
53+ "name": "Hello-World",
5154 "full_name": "unknwon/Hello-World",
55+ "description": "Some description",
5256 "private": false,
5357 "fork": false,
5458 "parent": null,
@@ -72,6 +76,7 @@ def setUp(self):
7276 "email": "u@gogs.io",
7377 "avatar_url": "/avatars/1"
7478 },
79+ "name": "Hello-World-Again",
7580 "full_name": "unknwon/Hello-World-Again",
7681 "private": false,
7782 "fork": false,
@@ -88,6 +93,80 @@ def setUp(self):
8893 "pull": true
8994 }
9095 }]"""
96+ self .branch_json_str = """{
97+ "name": "master",
98+ "commit": {
99+ "id": "c17825309a0d52201e78a19f49948bcc89e52488",
100+ "message": "migrated to RC0.2",
101+ "url": "Not implemented",
102+ "author": {
103+ "name": "Joel Lonbeck",
104+ "email": "joel@neutrinographics.com",
105+ "username": "joel"
106+ },
107+ "committer": {
108+ "name": "Joel Lonbeck",
109+ "email": "joel@neutrinographics.com",
110+ "username": "joel"
111+ },
112+ "verification": {
113+ "verified": false,
114+ "reason": "gpg.error.not_signed_commit",
115+ "signature": "",
116+ "payload": ""
117+ },
118+ "timestamp": "2017-05-17T21:11:25Z"
119+ }
120+ }"""
121+ self .branches_list_json_str = """[{
122+ "name": "master",
123+ "commit": {
124+ "id": "c17825309a0d52201e78a19f49948bcc89e52488",
125+ "message": "migrated to RC0.2",
126+ "url": "Not implemented",
127+ "author": {
128+ "name": "Joel Lonbeck",
129+ "email": "joel@neutrinographics.com",
130+ "username": "joel"
131+ },
132+ "committer": {
133+ "name": "Joel Lonbeck",
134+ "email": "joel@neutrinographics.com",
135+ "username": "joel"
136+ },
137+ "verification": {
138+ "verified": false,
139+ "reason": "gpg.error.not_signed_commit",
140+ "signature": "",
141+ "payload": ""
142+ },
143+ "timestamp": "2017-05-17T21:11:25Z"
144+ }
145+ },{
146+ "name": "develop",
147+ "commit": {
148+ "id": "r03kd7cjr9a0d52201e78a19f49948bcc89e52488",
149+ "message": "another branch",
150+ "url": "Not implemented",
151+ "author": {
152+ "name": "Joel Lonbeck",
153+ "email": "joel@neutrinographics.com",
154+ "username": "joel"
155+ },
156+ "committer": {
157+ "name": "Joel Lonbeck",
158+ "email": "joel@neutrinographics.com",
159+ "username": "joel"
160+ },
161+ "verification": {
162+ "verified": false,
163+ "reason": "gpg.error.not_signed_commit",
164+ "signature": "",
165+ "payload": ""
166+ },
167+ "timestamp": "2017-05-17T21:11:25Z"
168+ }
169+ }]"""
91170 self .user_json_str = """{
92171 "id": 1,
93172 "username": "unknwon",
@@ -188,6 +267,7 @@ def setUp(self):
188267 "read_only": true
189268 }]"""
190269 self .expected_repo = gogs_client .GogsRepo .from_json (json .loads (self .repo_json_str ))
270+ self .expected_branch = gogs_client .GogsBranch .from_json (json .loads (self .branch_json_str ))
191271 self .expected_user = gogs_client .GogsUser .from_json (json .loads (self .user_json_str ))
192272 self .expected_hook = gogs_client .GogsRepo .Hook .from_json (json .loads (self .hook_json_str ))
193273 self .expected_org = gogs_client .GogsOrg .from_json (json .loads (self .org_json_str ))
@@ -258,6 +338,21 @@ def test_delete_repo1(self):
258338 last_call = responses .calls [1 ]
259339 self .assertEqual (last_call .request .url , self .path_with_token (uri2 ))
260340
341+ @responses .activate
342+ def test_get_branch (self ):
343+ uri = self .path ("/repos/username/repo/branches/branch" )
344+ responses .add (responses .GET , uri , body = self .branch_json_str , status = 200 )
345+ branch = self .client .get_branch (self .token , "username" , "repo" , "branch" )
346+ self .assert_branches_equal (branch , self .expected_branch )
347+
348+ @responses .activate
349+ def test_get_branches (self ):
350+ uri = self .path ("/repos/username/repo/branches" )
351+ responses .add (responses .GET , uri , body = self .branches_list_json_str , status = 200 )
352+ branches = self .client .get_branches (self .token , "username" , "repo" )
353+ self .assertEqual (len (branches ), 2 )
354+ self .assert_branches_equal (branches [0 ], self .expected_branch )
355+
261356 @responses .activate
262357 def test_create_user1 (self ):
263358 uri = self .path ("/admin/users" )
@@ -601,6 +696,16 @@ def assert_repos_equal(self, repo, expected):
601696 self .assertEqual (repo .permissions .push , expected .permissions .push )
602697 self .assertEqual (repo .permissions .pull , expected .permissions .pull )
603698
699+ def assert_branches_equal (self , branch , expected ):
700+ self .assertEqual (branch .name , expected .name )
701+ self .assert_commits_equal (branch .commit , expected .commit )
702+
703+ def assert_commits_equal (self , commit , expected ):
704+ self .assertEqual (commit .id , expected .id )
705+ self .assertEqual (commit .message , expected .message )
706+ self .assertEqual (commit .url , expected .url )
707+ self .assertEqual (commit .timestamp , expected .timestamp )
708+
604709 def assert_users_equals (self , user , expected ):
605710 self .assertEqual (user .id , expected .id )
606711 self .assertEqual (user .username , expected .username )
0 commit comments