1
1
import github3
2
2
import re
3
- from base import expect , BaseTest , str_test
3
+ from base import expect , BaseTest , str_test , expect_str
4
4
from datetime import datetime
5
5
from os import unlink , listdir
6
6
from github3 .repos import (Repository , Branch , RepoCommit , RepoComment ,
@@ -16,11 +16,15 @@ class TestRepository(BaseTest):
16
16
def __init__ (self , methodName = 'runTest' ):
17
17
super (TestRepository , self ).__init__ (methodName )
18
18
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 )
19
22
20
23
def test_repository (self ):
21
24
expect (self .repo ).isinstance (Repository )
22
- expect (repr (self .repo )). isinstance ( str_test )
25
+ expect_str (repr (self .repo ))
23
26
expect (repr (self .repo )) != ''
27
+ self .repo .__update__ (self .repo .to_json ())
24
28
25
29
def test_clone_url (self ):
26
30
expect (self .repo .clone_url ).is_not_None ()
@@ -296,34 +300,78 @@ def test_requires_auth(self):
296
300
repo .update_label ('Foo' , 'abc123' )
297
301
repo .merge ('development' , 'master' , 'Fails' )
298
302
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
+
299
346
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
327
375
328
376
329
377
class TestBranch (BaseTest ):
@@ -351,7 +399,7 @@ def __init__(self, methodName='runTest'):
351
399
def _test_str_ (self , val ):
352
400
expect (val ).is_not_None ()
353
401
expect (val ) > ''
354
- expect (val ). isinstance ( str_test )
402
+ expect_str (val )
355
403
356
404
def test_content (self ):
357
405
expect (len (self .contents .content )) > 0
@@ -488,25 +536,25 @@ def test_commit(self):
488
536
expect (self .tag .commit ).isinstance (dict )
489
537
490
538
def test_name (self ):
491
- expect (self .tag .name ). isinstance ( str_test )
539
+ expect_str (self .tag .name )
492
540
493
541
def test_tarball_url (self ):
494
- expect (self .tag .tarball_url ). isinstance ( str_test )
542
+ expect_str (self .tag .tarball_url )
495
543
496
544
def test_zipball_url (self ):
497
- expect (self .tag .zipball_url ). isinstance ( str_test )
545
+ expect_str (self .tag .zipball_url )
498
546
499
547
500
548
def __test_files__ (fd , sha ):
501
549
expect (fd .additions ) >= 0
502
550
expect (fd .deletions ) >= 0
503
551
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 )
510
558
511
559
512
560
class TestRepoCommit (BaseTest ):
@@ -564,7 +612,7 @@ def test_commits(self):
564
612
self .expect_list_of_class (self .comp .commits , RepoCommit )
565
613
566
614
def test_diff_url (self ):
567
- expect (self .comp .diff_url ). isinstance ( str_test )
615
+ expect_str (self .comp .diff_url )
568
616
569
617
def test_files (self ):
570
618
expect (self .comp .files ).isinstance (list )
@@ -574,13 +622,13 @@ def test_files(self):
574
622
__test_files__ (file , '' )
575
623
576
624
def test_html_url (self ):
577
- expect (self .comp .html_url ). isinstance ( str_test )
625
+ expect_str (self .comp .html_url )
578
626
579
627
def test_patch_url (self ):
580
- expect (self .comp .patch_url ). isinstance ( str_test )
628
+ expect_str (self .comp .patch_url )
581
629
582
630
def test_permalink_url (self ):
583
- expect (self .comp .permalink_url ). isinstance ( str_test )
631
+ expect_str (self .comp .permalink_url )
584
632
585
633
def test_status (self ):
586
634
expect (self .comp .status ) == 'ahead'
@@ -600,7 +648,7 @@ def __init__(self, methodName='runTest'):
600
648
601
649
def test_status (self ):
602
650
expect (self .status ).isinstance (Status )
603
- expect (repr (self .status )). isinstance ( str_test )
651
+ expect_str (repr (self .status ))
604
652
expect (repr (self .status )) != ''
605
653
606
654
def test_created_at (self ):
@@ -611,18 +659,18 @@ def test_creator(self):
611
659
expect (self .status .creator .login ) == self .sigm
612
660
613
661
def test_description (self ):
614
- expect (self .status .description ). isinstance ( str_test )
662
+ expect_str (self .status .description )
615
663
expect (self .status .description ) == 'Testing github3.py'
616
664
617
665
def test_id (self ):
618
666
expect (self .status .id ) == 259373
619
667
620
668
def test_state (self ):
621
- expect (self .status .state ). isinstance ( str_test )
669
+ expect_str (self .status .state )
622
670
expect (self .status .state ) == 'success'
623
671
624
672
def test_target_url (self ):
625
- expect (self .status .target_url ). isinstance ( str_test )
673
+ expect_str (self .status .target_url )
626
674
expect (self .status .target_url ) == ('https://github.com/sigmavirus24/'
627
675
'github3.py' )
628
676
0 commit comments