10000 Add some tests for github3.repos. · doismellburning/github3.py@564cc6c · GitHub
[go: up one dir, main page]

Skip to content

Commit 564cc6c

Browse files
committed
Add some tests for github3.repos.
I'm starting work on the Repository.create_* methods although I'm unsure why I didn't add them before.
1 parent fb064d1 commit 564cc6c

File tree

1 file changed

+95
-47
lines changed

1 file changed

+95
-47
lines changed

tests/test_repos.py

Lines changed: 95 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import github3
22
import re
3-
from base import expect, BaseTest, str_test
3+
from base import expect, BaseTest, str_test, expect_str
44
from datetime import datetime
55
from os import unlink, listdir
66
from github3.repos import (Repository, Branch, RepoCommit, RepoComment,
@@ -16,11 +16,15 @@ class TestRepository(BaseTest):
1616
def __init__(self, methodName='runTest'):
1717
super(TestRepository, self).__init__(methodName)
1818
self.repo = self.g.repository(self.sigm, self.todo)
19+
if self.auth:
20+
self.alt_repo = self._g.repository(self.gh3py, self.test_repo)
21+
self.auth_todo = self._g.repository(self.sigm, self.todo)
1922

2023
def test_repository(self):
2124
expect(self.repo).isinstance(Repository)
22-
expect(repr(self.repo)).isinstance(str_test)
25+
expect_str(repr(self.repo))
2326
expect(repr(self.repo)) != ''
27+
self.repo.__update__(self.repo.to_json())
2428

2529
def test_clone_url(self):
2630
expect(self.repo.clone_url).is_not_None()
@@ -296,34 +300,78 @@ def test_requires_auth(self):
296300
repo.update_label('Foo', 'abc123')
297301
repo.merge('development', 'master', 'Fails')
298302

303+
def test_create_blob(self):
304+
if not self.auth:
305+
return
306+
content = 'foo bar bogus'
307+
sha = self.alt_repo.create_blob(content, 'utf-8')
308+
expect_str(sha)
309+
blob = self.alt_repo.blob(sha)
310+
expect(blob).isinstance(Blob)
311+
expect(self.alt_repo.create_blob('', '')) == ''
312+
313+
def test_create_comment(self):
314+
if not self.auth:
315+
return
316+
sha = '499faa66a0f56235ee55bf295bac2f2f3c3f0a04'
317+
body = 'Spelling error: reposity -> repository'
318+
path = 'README.md'
319+
line = pos = 4
320+
comment = self.alt_repo.create_comment(body, sha, path, pos, line)
321+
expect(comment).isinstance(RepoComment)
322+
comment.delete()
323+
324+
def test_create_download(self):
325+
if not self.auth:
326+
return
327+
dl = self.alt_repo.create_download('test_dls.py', __file__)
328+
expect(dl).isinstance(Download)
329+
dl.delete()
330+
331+
def test_create_fork_org(self):
332+
if not self.auth:
333+
return
334+
r = self.auth_todo.create_fork(self.gh3py)
335+
expect(r).isinstance(Repository)
336+
r.delete()
337+
338+
def test_create_fork(self):
339+
if not self.auth:
340+
return
341+
repo = self._g.repository(self.gh3py, 'fork_this')
342+
r = repo.create_fork()
343+
expect(r).isinstance(Repository)
344+
r.delete()
345+
299346
def test_with_auth(self):
300-
if self.auth:
301-
repo = self._g.repository(self.sigm, self.todo)
302-
# Try somethings only I can test
303-
try:
304-
expect(repo.hook(74859)).isinstance(Hook)
305-
except github3.GitHubError:
306-
pass
307-
try:
308-
expect(repo.key(3069618)).isinstance(Key)
309-
except github3.GitHubError:
310-
pass
311-
try:
312-
expect(repo.pubsubhubbub(
313-
'subscribe',
314-
'https://github.com/sigmavirus24/github3.py/events',
315-
'https://httpbin.org/post'
316-
)).is_False()
317-
except github3.GitHubError:
318-
pass
319-
try:
320-
expect(repo.add_collaborator('jcordasc')).is_True()
321-
except github3.GitHubError:
322-
pass
323-
try:
324-
expect(repo.remove_collaborator('jcordasc')).is_True()
325-
except github3.GitHubError:
326-
pass
347+
if not self.auth:
348+
return
349+
repo = self.auth_todo
350+
# Try somethings only I can test
351+
try:
352+
expect(repo.hook(74859)).isinstance(Hook)
353+
except github3.GitHubError:
354+
pass
355+
try:
356+
expect(repo.key(3069618)).isinstance(Key)
357+
except github3.GitHubError:
358+
pass
359+
try:
360+
expect(repo.pubsubhubbub(
361+
'subscribe',
362+
'https://github.com/sigmavirus24/github3.py/events',
363+
'https://httpbin.org/post'
364+
)).is_False()
365+
except github3.GitHubError:
366+
pass
367+
try:
368+
expect(repo.add_collaborator('jcordasc')).is_True()
369+
except github3.GitHubError:
370+
pass
371+
try:
372+
expect(repo.remove_collaborator('jcordasc')).is_True()
373+
except github3.GitHubError:
374+
pass
327375

328376

329377
class TestBranch(BaseTest):
@@ -351,7 +399,7 @@ def __init__(self, methodName='runTest'):
351399
def _test_str_(self, val):
352400
expect(val).is_not_None()
353401
expect(val) > ''
354-
expect(val).isinstance(str_test)
402+
expect_str(val)
355403

356404
def test_content(self):
357405
expect(len(self.contents.content)) > 0
@@ -488,25 +536,25 @@ def test_commit(self):
488536
expect(self.tag.commit).isinstance(dict)
489537

490538
def test_name(self):
491-
expect(self.tag.name).isinstance(str_test)
539+
expect_str(self.tag.name)
492540

493541
def test_tarball_url(self):
494-
expect(self.tag.tarball_url).isinstance(str_test)
542+
expect_str(self.tag.tarball_url)
495543

496544
def test_zipball_url(self):
497-
expect(self.tag.zipball_url).isinstance(str_test)
545+
expect_str(self.tag.zipball_url)
498546

499547

500548
def __test_files__(fd, sha):
501549
expect(fd.additions) >= 0
502550
expect(fd.deletions) >= 0
503551
expect(fd.changes) == fd.additions + fd.deletions
504-
expect(fd.filename).isinstance(str_test)
505-
expect(fd.blob_url).isinstance(str_test)
506-
expect(fd.raw_url).isinstance(str_test)
507-
expect(fd.sha).isinstance(str_test)
508-
expect(fd.status).isinstance(str_test)
509-
expect(fd.patch).isinstance(str_test)
552+
expect_str(fd.filename)
553+
expect_str(fd.blob_url)
554+
expect_str(fd.raw_url)
555+
expect_str(fd.sha)
556+
expect_str(fd.status)
557+
expect_str(fd.patch)
510558

511559

512560
class TestRepoCommit(BaseTest):
@@ -564,7 +612,7 @@ def test_commits(self):
564612
self.expect_list_of_class(self.comp.commits, RepoCommit)
565613

566614
def test_diff_url(self):
567-
expect(self.comp.diff_url).isinstance(str_test)
615+
expect_str(self.comp.diff_url)
568616

569617
def test_files(self):
570618
expect(self.comp.files).isinstance(list)
@@ -574,13 +622,13 @@ def test_files(self):
574622
__test_files__(file, '')
575623

576624
def test_html_url(self):
577-
expect(self.comp.html_url).isinstance(str_test)
625+
expect_str(self.comp.html_url)
578626

579627
def test_patch_url(self):
580-
expect(self.comp.patch_url).isinstance(str_test)
628+
expect_str(self.comp.patch_url)
581629

582630
def test_permalink_url(self):
583-
expect(self.comp.permalink_url).isinstance(str_test)
631+
expect_str(self.comp.permalink_url)
584632

585633
def test_status(self):
586634
expect(self.comp.status) == 'ahead'
@@ -600,7 +648,7 @@ def __init__(self, methodName='runTest'):
600648

601649
def test_status(self):
602650
expect(self.status).isinstance(Status)
603-
expect(repr(self.status)).isinstance(str_test)
651+
expect_str(repr(self.status))
604652
expect(repr(self.status)) != ''
605653

606654
def test_created_at(self):
@@ -611,18 +659,18 @@ def test_creator(self):
611659
expect(self.status.creator.login) == self.sigm
612660

613661
def test_description(self):
614-
expect(self.status.description).isinstance(str_test)
662+
expect_str(self.status.description)
615663
expect(self.status.description) == 'Testing github3.py'
616664

617665
def test_id(self):
618666
expect(self.status.id) == 259373
619667

620668
def test_state(self):
621-
expect(self.status.state).isinstance(str_test)
669+
expect_str(self.status.state)
622670
expect(self.status.state) == 'success'
623671

624672
def test_target_url(self):
625-
expect(self.status.target_url).isinstance(str_test)
673+
expect_str(self.status.target_url)
626674
expect(self.status.target_url) == ('https://github.com/sigmavirus24/'
627675
'github3.py')
628676

0 commit comments

Comments
 (0)
0