-
Notifications
You must be signed in to change notification settings - Fork 406
/
Copy pathtest_repos_repo.py
1770 lines (1536 loc) · 73.8 KB
/
test_repos_repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Integration tests for Repositories."""
import datetime
import itertools
import pytest
import github3
import github3.exceptions as exc
from . import helper
class TestRepository(helper.IntegrationHelper):
"""Integration tests for the Repository object."""
def test_add_collaborator(self):
"""Test the ability to add a collaborator to a repository."""
self.basic_login()
cassette_name = self.cassette_name("add_collaborator")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("gh3test", "my-new-repo")
assert repository
assert repository.add_collaborator("sigmavirus24")
repository.remove_collaborator("sigmavirus24")
def test_assignees(self):
"""Test the ability to retrieve assignees of issues on a repo."""
cassette_name = self.cassette_name("assignees")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("kennethreitz", "requests")
assert repository is not None
for assignee in repository.assignees():
assert isinstance(assignee, github3.users.ShortUser)
def test_blob(self):
"""Test the ability to retrieve blob on a repository."""
cassette_name = self.cassette_name("blob")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
blob = repository.blob("e1bacfb242c7dee1d24aef52df23d7a3f7442ea3")
assert isinstance(blob, github3.git.Blob)
def test_branch(self):
"""Test the ability to retrieve a single branch in a repository."""
cassette_name = self.cassette_name("branch")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
branch = repository.branch("develop")
assert isinstance(branch, github3.repos.branch.Branch)
assert "enabled" in branch.original_protection
def test_branches(self):
"""Test the ability to retrieve the branches in a repository."""
cassette_name = self.cassette_name("branches")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for branch in repository.branches():
assert isinstance(branch, github3.repos.branch.ShortBranch)
def test_project(self):
"""Test the ability to retrieve a single repository project."""
self.token_login()
cassette_name = self.cassette_name("project")
with self.recorder.use_cassette(cassette_name):
organization = self.gh.organization("testgh3py")
repository = organization.create_repository("test_project")
assert repository is not None
created_project = repository.create_project(
"test-project", body="test body"
)
project = repository.project(created_project.id)
assert isinstance(project, github3.projects.Project)
repository.delete()
def test_projects(self):
"""Test the ability to retrieve an repository's projects."""
self.token_login()
cassette_name = self.cassette_name("projects")
with self.recorder.use_cassette(cassette_name):
organization = self.gh.organization("testgh3py")
repository = organization.create_repository("test_project")
assert repository is not None
repository.create_project("test-project-0", body="test body")
repository.create_project("test-project-1", body="test body")
for project in repository.projects():
assert isinstance(project, github3.projects.Project)
repository.delete()
def test_protected_branches(self):
"""Test the ability to retrieve protected branches in a repository."""
self.token_login()
cassette_name = self.cassette_name("branches_protected")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
assert all(
isinstance(b, github3.repos.branch.ShortBranch)
for b in repository.branches(protected=True)
)
def test_code_frequency(self):
"""Test the ability to retrieve the code frequency in a repo."""
cassette_name = self.cassette_name("code_frequency")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for code_freq in repository.code_frequency():
assert isinstance(code_freq, list)
assert len(code_freq) > 0
def test_collaborators(self):
"""Test the ability to retrieve the collaborators on a repository."""
self.token_login()
cassette_name = self.cassette_name("collaborators")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for collaborator in repository.collaborators():
assert isinstance(collaborator, github3.users.Collaborator)
def test_comments(self):
"""Test the ability to retrieve comments on a repository."""
cassette_name = self.cassette_name("comments")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for comment in repository.comments():
assert isinstance(comment, github3.repos.comment.RepoComment)
def test_commit_activity(self):
"""Test the ability to retrieve commit activity on a repo."""
cassette_name = self.cassette_name("commit_activity")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for activity in repository.commit_activity():
assert isinstance(activity, dict)
def test_commit_comment(self):
"""Test the ability to retrieve single commit comment."""
cassette_name = self.cassette_name("commit_comment")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
comment = repository.commit_comment(1380832)
assert isinstance(comment, github3.repos.comment.RepoComment)
def test_commits(self):
"""Test the ability to retrieve commits on a repository."""
cassette_name = self.cassette_name("commits")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for commit in repository.commits(number=25):
assert isinstance(commit, github3.repos.commit.ShortCommit)
def test_compare_commits(self):
"""Test the ability to compare two commits."""
cassette_name = self.cassette_name("compare_commits")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
base = "a811e1a270f65eecb65755eca38d888cbefcb0a7"
head = "76dcc6cb4b9860034be81b7e58adc286a115aa97"
comparison = repository.compare_commits(base, head)
assert isinstance(comparison, github3.repos.comparison.Comparison)
def test_compare_commits_consistency(self):
"""Test that Comparison commits matches original_commits"""
cassette_name = self.cassette_name("compare_commits_consistency")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
base = "a811e1a270f65eecb65755eca38d888cbefcb0a7"
head = "76dcc6cb4b9860034be81b7e58adc286a115aa97"
comparison = repository.compare_commits(base, head)
self.assertListEqual(
list(comparison.commits()), comparison.original_commits
)
def test_compare_commits_large(self):
"""Test the ability to compare two commits with many changes."""
cassette_name = self.cassette_name("compare_commits_large")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
base = "1.0.0"
head = "3.2.0"
comparison = repository.compare_commits(base, head)
assert isinstance(comparison, github3.repos.comparison.Comparison)
iter_count = sum(1 for _ in comparison.commits())
assert comparison.total_commits == iter_count
def test_contributor_statistics(self):
"""Test the ability to retrieve contributor statistics for a repo."""
cassette_name = self.cassette_name("contributor_statistics")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for stat in repository.contributor_statistics():
assert isinstance(stat, github3.repos.stats.ContributorStats)
def test_contributors(self):
"""Test the ability to retrieve the contributors to a repository."""
cassette_name = self.cassette_name("contributors")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for contributor in repository.contributors():
assert isinstance(contributor, github3.users.Contributor)
assert isinstance(contributor.contributions, int)
def test_create_blob(self):
"""Test the ability to create a blob on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_blob")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
content = "VGVzdCBibG9i\n"
encoding = "base64"
sha = "30f2c645388832f70d37ab2b47eb9ea527e5ae7c"
assert repository.create_blob(content, encoding) == sha
def test_create_comment(self):
"""Test the ability to create a comment on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_comment")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
body = (
"Early morning commits are a good idea. "
"It is just me. Me migrating unit/integration tests."
)
sha = "1ad1d8309317a4240d5f17b23a2e7dab25e4cb10"
assert isinstance(
repository.create_comment(body, sha),
github3.repos.comment.RepoComment,
)
def test_create_commit(self):
"""Test the ability to create a commit."""
self.token_login()
cassette_name = self.cassette_name("create_commit")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
data = {
"message": "My commit message",
"author": {
"name": "Matt Chung",
"email": "[email protected]",
"date": "2015-12-03T16:13:30+12:00",
},
"parents": ["679358c79005523246ec3f460410ceda6b94e006"],
"tree": "6857122c4eff3ea461516c066f6bb1eba206d694",
}
commit = repository.create_commit(**data)
assert isinstance(commit, github3.git.Commit)
def test_create_commit_with_empty_committer(self):
"""Show that UnProcessableEntity is raised with empty comitter."""
self.token_login()
cassette_name = self.cassette_name(
"create_commit_with_" "empty_committer"
)
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
data = {
"message": "My commit message",
"author": {
"name": "Matt Chung",
"email": "[email protected]",
"date": "2015-12-03T16:13:30+12:00",
},
"committer": {},
"parents": ["679358c79005523246ec3f460410ceda6b94e006"],
"tree": "6857122c4eff3ea461516c066f6bb1eba206d694",
}
with pytest.raises(exc.UnprocessableEntity):
repository.create_commit(**data)
def test_create_empty_blob(self):
"""Test the ability to create an empty blob on a repository."""
self.basic_login()
cassette_name = self.cassette_name("create_empty_blob")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
assert repository is not None
blob_sha = repository.create_blob("", "utf-8")
assert blob_sha is not None
assert blob_sha != ""
def test_create_deployment(self):
"""Test the ability to create a deployment for a repository."""
self.basic_login()
cassette_name = self.cassette_name("create_deployment")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "delete_contents")
assert repository is not None
deployment = repository.create_deployment("0.1.0")
assert isinstance(deployment, github3.repos.deployment.Deployment)
def test_create_file(self):
"""Test the ability to create a file on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_file")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "delete_contents")
data = {
"path": "hello.txt",
"message": "my commit message",
"content": b"my new file contents",
"branch": "master",
"committer": {
"name": "Matt Chung",
"email": "[email protected]",
},
}
created_file = repository.create_file(**data)
created_file["content"].delete("Delete hello.txt")
assert isinstance(
created_file["content"], github3.repos.contents.Contents
)
assert isinstance(created_file["commit"], github3.git.Commit)
def test_create_fork(self):
"""Test the ability to fork a repository."""
self.token_login()
betamax_kwargs = {"match_requests_on": ["method", "uri", "json-body"]}
cassette_name = self.cassette_name("create_fork")
with self.recorder.use_cassette(cassette_name, **betamax_kwargs):
repository = self.gh.repository("kennethreitz", "requests")
forked_repo = repository.create_fork()
assert isinstance(forked_repo, github3.repos.Repository)
org_forked_repo = repository.create_fork("github3py")
assert isinstance(org_forked_repo, github3.repos.Repository)
def test_create_hook(self):
"""Test the ability to create a hook for a repository."""
self.token_login()
cassette_name = self.cassette_name("create_hook")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
data = {
"name": "web",
"config": {
"url": "http://example.com/webhook",
"content_type": "json",
},
}
hook = repository.create_hook(**data)
assert isinstance(hook, github3.repos.hook.Hook)
def test_create_issue(self):
"""Test the ability to create an issue for a repository."""
self.auto_login()
cassette_name = self.cassette_name("create_issue")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
data = {
"title": "Create Issue Integration Test",
"body": "Delete me after",
"assignee": "itsmemattchung",
}
issue = repository.create_issue(**data)
assert isinstance(issue, github3.issues.issue.ShortIssue)
def test_create_issue_multiple_assignees(self):
"""
Test the ability to create an issue with multiple assignees
for a repository.
"""
self.token_login()
cassette_name = self.cassette_name("create_issue_multiple_assignees")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
data = {
"title": "Create Issue Integration Test",
"body": "Delete me after",
"assignees": ["itsmemattchung", "sigmavirus24"],
}
issue = repository.create_issue(**data)
assert isinstance(issue, github3.issues.issue.ShortIssue)
def test_create_issue_both_assignee_and_assignees(self):
"""
Test the ability to create an issue with both assignee
and assignees.
"""
self.token_login()
cassette_name = self.cassette_name(
"create_issue_both_assignee_and_assignees"
)
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
data = {
"title": "Create Issue Integration Test",
"body": "Delete me after",
"assignee": "itsmemattchung",
"assignees": ["itsmemattchung", "sigmavirus24"],
}
with pytest.raises(exc.UnprocessableEntity):
repository.create_issue(**data)
def test_create_key(self):
"""Test the ability to deploy a key."""
self.token_login()
cassette_name = self.cassette_name("create_key")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
key = (
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZn4/RGE9YQrfjq7wSr"
"YkdtKH3r1rEIkx/4Nv1AG/PqE4AWKSVzKkqhurnqKtctVCLtU9pNFIjl/"
"XvNluTW3zrfqKjgaDdiBtWwecWzSbQqugfzmwFqCE4smJkP8e7+e9Fd1k"
"GOGyqVJLBLfIUdEbHN3Ws40Z9OXgrJ/tiNdg1HHgAOjpknCMrQI8NDP9o"
"9CLuE/AfNVzRNOzpf/rrdZ4YW4kcDhbcQ8X7DGCnbvY9wUp3lDmSvVy6z"
"olYwLziYqsGjw0kLHvIzHdbGCjp+50iZSBrm29AlWa9eRsGskiUTIk6SA"
"Q8Fm5qKNkCtPYQ6YmjRiKyDtsMoqfjzDkyEPLv mattchung@Matts-Ma"
"cBook-Air.local"
)
data = {"title": "Deploy Key", "key": key}
key = repository.create_key(**data)
assert isinstance(key, github3.users.Key)
def test_create_label(self):
"""Test the ability to create a label on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_label")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "delete_contents")
label = repository.create_label("fakelabel", "fad8c7")
label.delete()
assert isinstance(label, github3.issues.label.Label)
def test_create_milestone(self):
"""Test the ability to create a milestone on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_milestone")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "delete_contents")
milestone = repository.create_milestone("foo")
milestone.delete()
assert isinstance(milestone, github3.issues.milestone.Milestone)
def test_create_project(self):
"""Test the ability to create a project on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_repo_project")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "delete_contents")
project = repository.create_project(
"test-project", body="test body"
)
project.delete()
assert isinstance(project, github3.projects.Project)
def test_create_pull(self):
"""Test the ability to create a pull request on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_pull")
with self.recorder.use_cassette(cassette_name):
original_repository = self.gh.repository(
"github3py", "github3.py"
)
repository = original_repository.create_fork(
organization="testgh3py"
)
pull_request = repository.create_pull(
title="Update forked repo",
base="master",
head="testgh3py:develop",
body="Testing the ability to create a pull request",
)
repository.delete()
assert isinstance(pull_request, github3.pulls.ShortPullRequest)
def test_create_pull_head_repo(self):
"""Test the ability to create a pull request by fully specifying the organization, repository, and branch."""
self.token_login()
cassette_name = self.cassette_name("create_pull")
with self.recorder.use_cassette(cassette_name):
original_repository = self.gh.repository(
"github3py", "github3.py"
)
repository = original_repository.create_fork(
organization="testgh3py"
)
pull_request = repository.create_pull(
title="Update forked repo",
base="master",
head="develop",
head_repo="testgh3py/github3.py",
body="Testing the ability to create a pull request",
)
repository.delete()
assert isinstance(pull_request, github3.pulls.ShortPullRequest)
def test_create_pull_from_issue(self):
"""Verify creation of a pull request from an issue."""
self.token_login()
cassette_name = self.cassette_name("create_pull_from_issue")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
issue = repository.create_issue("Test create pull from issue")
pull_request = repository.create_pull_from_issue(
issue=issue.number, base="master", head="sigmavirus24:master"
)
assert isinstance(pull_request, github3.pulls.ShortPullRequest)
def test_create_ref(self):
"""Verify the ability to create a reference on a repository."""
self.auto_login()
cassette_name = self.cassette_name("create_ref")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
master = repository.commit("master")
ref = repository.create_ref(
f"refs/tags/test-tag-{master.sha[:6]}", master
)
assert isinstance(ref, github3.git.Reference)
ref.delete()
def test_create_branch_ref(self):
"""Verify the ability to create a branch on a repository."""
self.auto_login()
cassette_name = self.cassette_name("create_branch_ref")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
master = repository.commit("master")
ref = repository.create_branch_ref(
f"test-branch-{master.sha[:6]}", master
)
assert isinstance(ref, github3.git.Reference)
ref.delete()
def test_create_release(self):
"""Test the ability to create a release on a repository."""
self.token_login()
cassette_name = self.cassette_name("create_release")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "charade")
assert repository is not None
release = repository.create_release(
"1.0.3.test",
"f1d4e150be7070adfbbdca164328d69723e096ec",
"Test release",
)
release.delete()
assert isinstance(release, github3.repos.release.Release)
def test_create_status(self):
"""Test the ability to create a status object on a commit."""
self.token_login()
cassette_name = self.cassette_name("create_status")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
status = repository.create_status(
sha="24893ec07db2a12073703258f0089f105906d2e4",
state="failure",
)
assert isinstance(status, github3.repos.status.Status)
def test_create_tag(self):
"""Test the ability to create an annotated tag on a repository."""
self.basic_login()
cassette_name = self.cassette_name("create_tag")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
assert repository is not None
tag = repository.create_tag(
tag="tag-name-redux",
message="Test annotated tag creation",
sha="5145c9682d46d714c31ae0b5fbe30a83039a96e5",
obj_type="commit",
tagger={
"name": "Ian Cordasco",
"email": "[email protected]",
"date": "2015-11-01T14:09:00Z",
},
)
assert isinstance(tag, github3.git.Tag)
def test_delete(self):
"""Test that a repository can be deleted."""
self.basic_login()
cassette_name = self.cassette_name("delete")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.create_repository(
"gh3test", "delete-me-in-seconds"
)
assert repository is not None
assert repository.delete() is True
def test_delete_key(self):
"""Test the ability to delete a key from a repository."""
self.token_login()
cassette_name = self.cassette_name("delete_key")
with open("tests/id_rsa.pub") as fd:
key_contents = fd.read()
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
key = repository.create_key("Key Name", key_contents)
assert repository.delete_key(key.id) is True
def test_delete_subscription(self):
"""Test the ability to delete a subscription from a repository."""
self.token_login()
cassette_name = self.cassette_name("delete_subscription")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.create_repository("gh3-delete-me")
repository.subscribe()
assert repository.delete_subscription() is True
def test_deployment(self):
"""Test that a deployment can be retrieved by its id."""
cassette_name = self.cassette_name("deployment")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
deployment = repository.deployment(797)
assert isinstance(deployment, github3.repos.deployment.Deployment)
def test_deployments(self):
"""Test that a repository's deployments may be retrieved."""
cassette_name = self.cassette_name("deployments")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
for d in repository.deployments():
assert isinstance(d, github3.repos.deployment.Deployment)
def test_directory_contents(self):
"""Test that a directory's contents can be retrieved."""
cassette_name = self.cassette_name("directory_contents")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
contents = repository.directory_contents("github3/search/")
for filename, content in contents:
assert content.name == filename
assert isinstance(content, github3.repos.contents.Contents)
def test_directory_contents_for_a_file(self):
"""Verify we raise a sensical exception for a directory's contents."""
cassette_name = self.cassette_name("not_really_directory_contents")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
with pytest.raises(github3.exceptions.UnprocessableResponseBody):
repository.directory_contents("README.rst")
def test_edit(self):
"""Test the ability to edit a repository."""
self.token_login()
cassette_name = self.cassette_name("edit")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
assert repository.edit("github3py") is True
def test_archive_a_repository(self):
"""Verify we can archive a repository."""
self.token_login()
cassette_name = self.cassette_name("archive_a_repository")
with self.recorder.use_cassette(cassette_name):
organization = self.gh.organization("testgh3py")
repository = organization.create_repository("archive-me")
assert repository.archived is False
repository.edit(name="i-have-been-archived", archived=True)
assert repository.archived is True
repository.delete()
def test_edit_has_projects(self):
self.token_login()
cassette_name = self.cassette_name("edit_has_projects")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository(
"jacquerie", "flask-shell-bpython"
)
assert repository.has_projects is True
repository.edit("flask-shell-bpython", has_projects=False)
assert repository.has_projects is False
def test_events(self):
"""Test that a user can iterate over the events from a repository."""
cassette_name = self.cassette_name("events")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
events = list(repository.events(number=100))
assert len(events) > 0
for event in events:
assert isinstance(event, github3.events.Event)
def test_file_contents(self):
"""Test that a file's contents can be retrieved."""
cassette_name = self.cassette_name("file_contents")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
contents = repository.file_contents("github3/repos/repo.py")
assert isinstance(contents, github3.repos.contents.Contents)
assert contents.content is not None
assert contents.decoded is not None
def test_forks(self):
"""Test that a user can iterate over the forks of a repository."""
cassette_name = self.cassette_name("forks")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
forks = list(repository.forks())
assert len(forks) > 0
for fork in forks:
assert isinstance(fork, github3.repos.ShortRepository)
def test_git_commit(self):
"""Test the ability to retrieve a commit from a repository."""
cassette_name = self.cassette_name("git_commit")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
commit = repository.git_commit(
"9ea7482560c9e70c66019f7981aa1727caf888e0"
)
assert isinstance(commit, github3.git.Commit)
def test_hook(self):
"""Test the ability to retrieve a hook from a repository."""
self.token_login()
cassette_name = self.cassette_name("hook")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "github3.py")
hook_id = next(repository.hooks()).id
hook = repository.hook(hook_id)
assert isinstance(hook, github3.repos.hook.Hook)
def test_hooks(self):
"""Test that a user can iterate over the hooks of a repository."""
self.basic_login()
cassette_name = self.cassette_name("hooks")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
assert repository is not None
hooks = list(repository.hooks())
assert len(hooks) > 0
for hook in hooks:
assert isinstance(hook, github3.repos.hook.Hook)
def test_ignore(self):
"""Test that a user can ignore the notifications on a repository."""
self.basic_login()
cassette_name = self.cassette_name("ignore")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository(
"jnewland", "gmond_python_modules"
)
assert repository is not None
subscription = repository.ignore()
assert subscription.ignored is True
def test_invitations(self):
"""Test that a user can iterate over the invitations to a repo."""
self.token_login()
cassette_name = self.cassette_name("invitations")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository(
"jacquerie", "flask-shell-bpython"
)
invitations = list(repository.invitations())
assert len(invitations) > 0
for invitation in invitations:
assert isinstance(invitation, github3.repos.invitation.Invitation)
def test_is_assignee(self):
"""
Test the ability to check if a user can be assigned issues on a
repository.
"""
cassette_name = self.cassette_name("is_assignee")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
is_assignee = repository.is_assignee("sigmavirus24")
assert is_assignee is True
def test_is_collaborator(self):
"""
Test the ability to check if a user is a collaborator on a
repository.
"""
self.token_login()
cassette_name = self.cassette_name("is_collaborator")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository.is_collaborator("sigmavirus24") is True
def test_issue(self):
"""Test the ability to retrieve an issue from a repository."""
cassette_name = self.cassette_name("issue")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
issue = repository.issue(525)
assert isinstance(issue, github3.issues.issue.Issue)
def test_issue_with_multiple_assignees(self):
"""Test the ability to retrieve an issue from a repository."""
cassette_name = self.cassette_name("issue_multiple_assignees")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
issue = repository.issue(637)
assert isinstance(issue, github3.issues.issue.Issue)
assert isinstance(issue.assignees, list)
def test_imported_issue(self):
"""Test the ability to retrieve an imported issue by id."""
self.token_login()
cassette_name = self.cassette_name("imported_issue")
with self.recorder.use_cassette(cassette_name):
issue = {
"title": "foo",
"body": "bar",
"created_at": "2014-03-16T17:15:42Z",
}
repository = self.gh.create_repository("testgh3py", "test_import")
imported_issue = repository.import_issue(**issue)
imported_issue = repository.imported_issue(imported_issue.id)
repository.delete()
assert isinstance(
imported_issue, github3.repos.issue_import.ImportedIssue
)
def test_imported_issues(self):
"""Test the ability to retrieve imported issues."""
self.token_login()
cassette_name = self.cassette_name("imported_issues")
with self.recorder.use_cassette(cassette_name):
issues = [
{
"title": "foo",
"body": "bar",
"created_at": "2014-03-16T17:15:42Z",
"comments": [{"body": "fake comments"}],
}
]
repository = self.gh.create_repository("testgh3py", "test_import")
for issue in issues:
repository.import_issue(**issue)
imported_issues = list(repository.imported_issues())
assert len(imported_issues) > 0
for imported_issue in imported_issues:
assert isinstance(
imported_issue, github3.repos.issue_import.ImportedIssue
)
def test_import_issue(self):
"""Test the ability to import an issue."""
self.token_login()
cassette_name = self.cassette_name("import_issue")
with self.recorder.use_cassette(cassette_name):
issue = {
"title": "foo",
"body": "bar",
"created_at": "2014-03-16T17:15:42Z",
}
repository = self.gh.create_repository("testgh3py", "test_import")
imported_issue = repository.import_issue(**issue)
repository.delete()
assert isinstance(
imported_issue, github3.repos.issue_import.ImportedIssue
)
def test_import_issue_with_comments(self):
"""
Test the ability to import an issue with comments on a repoitory.
"""
self.token_login()
cassette_name = self.cassette_name("import_issue_with_comments")
with self.recorder.use_cassette(cassette_name):
issue = {
"title": "foo",
"body": "bar",
"created_at": "2014-03-16T17:15:42Z",
"comments": [{"body": "fake comments"}],
}
repository = self.gh.create_repository(
"testgh3py", "test_import_issue_with_comments"
)
imported_issue = repository.import_issue(**issue)
repository.delete()
assert isinstance(
imported_issue, github3.repos.issue_import.ImportedIssue
)
def test_issue_events(self):
"""Test that a user can iterate over issue events in a repo."""
cassette_name = self.cassette_name("issue_events")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "github3.py")
assert repository is not None
events = list(repository.issue_events(number=50))
for ev in events:
assert isinstance(ev, github3.issues.event.RepositoryIssueEvent)
def test_issues_sorts_ascendingly(self):
"""Test that issues will be returned in ascending order."""
cassette_name = self.cassette_name("issues_ascending")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "betamax")
assert repository is not None
issues = list(repository.issues(direction="asc"))
assert len(issues) > 0
last_issue = None
for issue in issues:
assert isinstance(issue, github3.issues.ShortIssue)
if last_issue:
assert last_issue.number < issue.number
last_issue = issue
def test_issues_accepts_state_all(self):
"""Test that the state parameter accepts 'all'."""
cassette_name = self.cassette_name("issues_state_all")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("sigmavirus24", "betamax")
assert repository is not None
for issue in repository.issues(state="all"):
assert issue.state in ("open", "closed")
def test_key(self):
"""Test the retrieval of a single key."""
self.basic_login()
cassette_name = self.cassette_name("key")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
assert repository is not None
key = (
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZn4/RGE9YQrfjq7wSr"
"YkdtKH3r1rEIkx/4Nv1AG/PqE4AWKSVzKkqhurnqKtctVCLtU9pNFIjl/"
"XvNluTW3zrfqKjgaDdiBtWwecWzSbQqugfzmwFqCE4smJkP8e7+e9Fd1k"
"GOGyqVJLBLfIUdEbHN3Ws40Z9OXgrJ/tiNdg1HHgAOjpknCMrQI8NDP9o"
"9CLuE/AfNVzRNOzpf/rrdZ4YW4kcDhbcQ8X7DGCnbvY9wUp3lDmSvVy6z"
"olYwLziYqsGjw0kLHvIzHdbGCjp+50iZSBrm29AlWa9eRsGskiUTIk6SA"
"Q8Fm5qKNkCtPYQ6YmjRiKyDtsMoqfjzDkyEPLv mattchung@Matts-Ma"
"cBook-Air.local"
)
data = {"title": "Deploy Key", "key": key}
created_key = repository.create_key(**data)
key = repository.key(created_key.id)
key.delete()
assert isinstance(key, github3.users.Key)
def test_keys(self):
"""Test that the user can retrieve all deploy keys."""
self.basic_login()
cassette_name = self.cassette_name("keys")
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository("github3py", "fork_this")
assert repository is not None
key = (
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZn4/RGE9YQrfjq7wSr"
"YkdtKH3r1rEIkx/4Nv1AG/PqE4AWKSVzKkqhurnqKtctVCLtU9pNFIjl/"
"XvNluTW3zrfqKjgaDdiBtWwecWzSbQqugfzmwFqCE4smJkP8e7+e9Fd1k"
"GOGyqVJLBLfIUdEbHN3Ws40Z9OXgrJ/tiNdg1HHgAOjpknCMrQI8NDP9o"
"9CLuE/AfNVzRNOzpf/rrdZ4YW4kcDhbcQ8X7DGCnbvY9wUp3lDmSvVy6z"
"olYwLziYqsGjw0kLHvIzHdbGCjp+50iZSBrm29AlWa9eRsGskiUTIk6SA"
"Q8Fm5qKNkCtPYQ6YmjRiKyDtsMoqfjzDkyEPLv mattchung@Matts-Ma"
"cBook-Air.local"
)
data = {"title": "Deploy Key", "key": key}
created_key = repository.create_key(**data)
keys = list(repository.keys())
created_key.delete()
assert len(keys) > 0
for key in keys:
assert isinstance(key, github3.users.Key)
def test_label(self):
"""Test that a user can retrieve a repository's label."""
cassette_name = self.cassette_name("label")