forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_github.py
More file actions
1455 lines (1170 loc) · 47.9 KB
/
test_github.py
File metadata and controls
1455 lines (1170 loc) · 47.9 KB
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
import pytest
from github3 import GitHubEnterprise, GitHubError
from github3.github import GitHub, GitHubStatus
from github3.projects import Project
from . import helper
def url_for(path=''):
"""Simple function to generate URLs with the base GitHub URL."""
return 'https://api.github.com/' + path.strip('/')
enterprise_url_for = helper.create_url_helper('https://enterprise.github3.com')
class TestGitHub(helper.UnitHelper):
described_class = GitHub
example_data = None
def test_add_email_addresses(self):
"""Verify request to add email addresses for a user."""
self.post_called_with(
url_for('user/emails'),
)
def test_add_email_addresses_with_empty_list(self):
"""Verify no request is sent for an empty list of addresses."""
self.instance.add_email_addresses([])
assert self.session.post.called is False
def test_authorization(self):
"""Show that a user can retrieve a specific authorization by id."""
self.instance.authorization(10)
self.session.get.assert_called_once_with(
url_for('authorizations/10'),
)
def test_authorize_without_scope(self):
"""Show an authorization can be created for a user without scope."""
self.instance.authorize('username', 'password')
self.session.temporary_basic_auth.assert_called_once_with(
'username', 'password'
)
self.post_called_with(
url_for('authorizations'),
data={'note': '', 'note_url': '', 'client_id': '',
'client_secret': ''}
)
def test_authorize(self):
"""Show an authorization can be created for a user."""
self.instance.authorize('username', 'password', ['user', 'repo'])
self.session.temporary_basic_auth.assert_called_once_with(
'username', 'password'
)
self.post_called_with(
url_for('authorizations'),
data={'note': '', 'note_url': '', 'client_id': '',
'client_secret': '', 'scopes': ['user', 'repo']}
)
def test_check_authorization(self):
"""Test an app's ability to check a authorization token."""
self.instance.set_client_id('client-id', 'client-secret')
self.instance.check_authorization('super-fake-access-token')
self.session.get.assert_called_once_with(
url_for('applications/client-id/tokens/super-fake-access-token'),
params={'client_id': None, 'client_secret': None},
auth=('client-id', 'client-secret')
)
def test_create_gist(self):
"""Test the request to create a gist."""
self.instance.create_gist('description', {
'example.py': {'content': '# example contents'}
})
self.post_called_with(
url_for('gists'),
data={
'description': 'description',
'files': {
'example.py': {
'content': '# example contents'
}
},
'public': True,
}
)
def test_create_key(self):
"""Test the request to create a key."""
self.instance.create_key('key_name', 'key text', read_only=False)
self.post_called_with(
url_for('user/keys'),
data={
'title': 'key_name',
'key': 'key text',
'read_only': False
}
)
def test_create_key_with_readonly(self):
""" Test the request to create a key with read only"""
self.instance.create_key('key_name', 'key text', read_only=True)
self.post_called_with(
url_for('user/keys'),
data={
'title': 'key_name',
'key': 'key text',
'read_only': True
}
)
def test_create_key_requires_a_key(self):
"""Test that no request is made with an empty key."""
self.instance.create_key('title', '')
assert self.session.post.called is False
def test_create_key_requires_a_title(self):
"""Test that no request is made with an empty title."""
self.instance.create_key('', 'key text')
assert self.session.post.called is False
def test_create_repository(self):
"""Test the request to create a repository."""
self.instance.create_repository('repo-name')
self.post_called_with(
url_for('user/repos'),
data={
'name': 'repo-name',
'description': '',
'homepage': '',
'private': False,
'has_issues': True,
'has_wiki': True,
'auto_init': False,
'gitignore_template': ''
}
)
def test_delete_email_addresses(self):
"""Verify the request to delete a user's email addresses."""
self.delete_called_with(
url_for('user/emails'),
)
def test_emojis(self):
"""Test the request to retrieve GitHub's emojis."""
self.instance.emojis()
self.session.get.assert_called_once_with(url_for('emojis'))
def test_feeds(self):
self.instance.feeds()
self.session.get.assert_called_once_with(url_for('feeds'))
def test_follow(self):
"""Test the request to follow a user."""
self.instance.follow('username')
self.session.put.assert_called_once_with(
url_for('user/following/username')
)
def test_follow_requires_a_username(self):
"""Test that GitHub#follow requires a username."""
self.instance.follow(None)
assert self.session.put.called is False
def test_gist(self):
"""Test the request to retrieve a specific gist."""
self.instance.gist(10)
self.session.get.assert_called_once_with(url_for('gists/10'))
def test_gitignore_template(self):
"""Test the request to retrieve a gitignore template."""
self.instance.gitignore_template('Python')
self.session.get.assert_called_once_with(
url_for('gitignore/templates/Python')
)
def test_gitignore_templates(self):
"""Test the request to retrieve gitignore templates."""
self.instance.gitignore_templates()
self.session.get.assert_called_once_with(
url_for('gitignore/templates')
)
def test_is_following(self):
"""Test the request to check if the user is following a user."""
self.instance.is_following('username')
self.session.get.assert_called_once_with(
url_for('user/following/username')
)
def test_is_starred(self):
"""Test the request to check if the user starred a repository."""
self.instance.is_starred('username', 'repository')
self.session.get.assert_called_once_with(
url_for('user/starred/username/repository')
)
def test_is_starred_requires_an_owner(self):
"""Test that GitHub#is_starred requires an owner."""
self.instance.is_starred(None, 'repo')
assert self.session.get.called is False
def test_is_starred_requires_a_repo(self):
"""Test that GitHub#is_starred requires an repo."""
self.instance.is_starred('username', None)
assert self.session.get.called is False
def test_issue(self):
"""Test the request to retrieve a single issue."""
self.instance.issue('owner', 'repo', 1)
self.session.get.assert_called_once_with(
url_for('repos/owner/repo/issues/1')
)
def test_issue_requires_username(self):
"""Test GitHub#issue requires a non-None username."""
self.instance.issue(None, 'foo', 1)
assert self.session.get.called is False
def test_issue_requires_repository(self):
"""Test GitHub#issue requires a non-None repository."""
self.instance.issue('foo', None, 1)
assert self.session.get.called is False
def test_issue_requires_positive_issue_id(self):
"""Test GitHub#issue requires positive issue id."""
self.instance.issue('foo', 'bar', -1)
assert self.session.get.called is False
def test_key(self):
"""Verify request for retrieving a user's key."""
self.instance.key(1)
self.session.get.assert_called_once_with(
url_for('user/keys/1')
)
def test_key_negative_id(self):
"""Verify request for retrieving a user's key."""
self.instance.key(-1)
self.session.get.called is False
def test_login(self):
"""Verify the request for user logging in."""
self.instance.login('user', 'password')
self.session.basic_auth.assert_called_once_with(
'user',
'password'
)
self.session.two_factor_auth_callback.assert_called_once_with(None)
def test_login_with_token(self):
"""Verify the request for user logging in."""
token = 'OauthToken'
def _callback(x):
return x
callback = _callback
self.instance.login(token=token, two_factor_callback=callback)
self.session.token_auth.assert_called_once_with(token)
self.session.two_factor_auth_callback.assert_called_once_with(
callback
)
def test_markdown(self):
"""Verify the request for rendering a markdown document."""
self.session.post.return_value = helper.mock.Mock(
ok=True
)
text = '##Hello'
mode = 'markdown'
self.instance.markdown(text=text, mode=mode)
self.post_called_with(
url_for('markdown'),
data={
'text': text,
'mode': mode
},
headers={},
)
def test_markdown_raw(self):
"""Verify the request for rendering a markdown document."""
self.session.post.return_value = helper.mock.Mock(
ok=True
)
text = 'Hello'
raw = True
self.instance.markdown(text=text, raw=raw)
self.session.post.assert_called_once_with(
url_for('markdown/raw'),
'Hello',
headers={
'content-type': 'text/plain'
}
)
def test_markdown_gfm(self):
"""Verify the request for rendering a markdown document."""
self.session.post.return_value = helper.mock.Mock(
ok=True
)
text = '##Hello'
mode = 'gfm'
context = 'sigmavirus24/github3.py'
self.instance.markdown(text=text, mode=mode, context=context)
self.post_called_with(
url_for('markdown'),
data={
'text': text,
'mode': mode,
'context': context
},
headers={},
)
def test_me(self):
"""Test the ability to retrieve the authenticated user's info."""
self.instance.me()
self.session.get.assert_called_once_with(url_for('user'))
def test_meta(self):
"""Verify the request for returning incoming service hooks data."""
self.instance.meta()
self.session.get.assert_called_once_with(
url_for('meta')
)
def test_octocat(self):
"""Verify the request for retrieving an easter egg."""
self.session.get.return_value = helper.mock.Mock(
ok=True, text='egg'
)
egg = self.instance.octocat(say='hello')
self.session.get.assert_called_once_with(
url_for('octocat'),
params={
's': 'hello'
}
)
assert egg == 'egg'
def test_octocat_response_not_ok(self):
"""Verify the request for retrieving an easter egg."""
self.session.get.return_value = helper.mock.Mock(
ok=False, text='egg'
)
egg = self.instance.octocat(say='hello')
assert egg == ''
def test_organization(self):
"""Verify the request for retrieving an organization."""
self.instance.organization(username='github3py')
self.session.get.assert_called_once_with(
url_for('orgs/github3py')
)
def test_project(self):
"""Test the ability to retrieve a project by its id."""
self.instance.project(400543)
self.session.get.assert_called_once_with(
url_for('projects/400543'),
headers=Project.CUSTOM_HEADERS
)
def test_project_card(self):
"""Test the ability to retrieve a project card by its id."""
self.instance.project_card(2665856)
self.session.get.assert_called_once_with(
url_for('projects/columns/cards/2665856'),
headers=Project.CUSTOM_HEADERS
)
def test_project_column(self):
"""Test the ability to retrieve a project column by its id."""
self.instance.project_column(957217)
self.session.get.assert_called_once_with(
url_for('projects/columns/957217'),
headers=Project.CUSTOM_HEADERS
)
def test_pubsubhubbub(self):
"""Verify the request for creating a pubsubhubbub hook."""
topic = (
'hub.topic',
'https://github.com/octocat/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
self.session.post.assert_called_once_with(
url_for('hub'),
body,
headers={
'Content-Type':
'application/x-www-form-urlencoded'
}
)
def test_pubsubhubbub_invalid_username(self):
"""Verify a valid call with invalid username does not call post."""
topic = (
'hub.topic',
'https://github.com/-octocat/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is False
def test_pubsubhubbub_valid_username(self):
"""Verify a valid call with valid username calls post."""
topic = (
'hub.topic',
'https://github.com/o-cto-ca-t/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is True
def test_pubsubhubbub_secret(self):
"""Verify the request for creating a pubsubhubbub hook."""
topic = (
'hub.topic',
'https://github.com/octocat/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', 'https://localhost/post'),
('hub.secret', 'secret')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
self.session.post.assert_called_once_with(
url_for('hub'),
body,
headers={
'Content-Type':
'application/x-www-form-urlencoded'
}
)
def test_pubsubhubbub_required_callback(self):
"""Verify the request for creating a pubsubhubbub hook."""
topic = (
'hub.topic',
'https://github.com/octocat/hello-world/events/push'
)
body = [('hub.mode', 'subscribe'),
topic,
('hub.callback', '')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is False
def test_pubsubhubbub_required_mode(self):
"""Verify the request for creating a pubsubhubbub hook."""
topic = (
'hub.topic',
'https://github.com/octocat/hello-world/events/push'
)
body = [('hub.mode', ''),
topic,
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is False
def test_pubsubhubbub_required_topic(self):
"""Verify the request for creating a pubsubhubbub hook."""
body = [('hub.mode', ''),
('hub.topic', ''),
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is False
def test_pubsubhubbub_topic_no_match(self):
"""Verify the request for creating a pubsubhubbub hook."""
body = [('hub.mode', 'subscribe'),
('hub.topic', ''),
('hub.callback', 'https://localhost/post')]
data = dict([(k[4:], v) for k, v in body])
self.instance.pubsubhubbub(**data)
assert self.session.post.called is False
def test_pull_request(self):
"""Verify the request for retrieving a pull request."""
self.instance.pull_request(owner='octocat',
repository='hello-world',
number=1)
self.session.get.assert_called_once_with(
url_for('repos/octocat/hello-world/pulls/1')
)
def test_pull_request_negative_id(self):
"""Verify the request for retrieving a pull request."""
self.instance.pull_request(owner='octocat',
repository='hello-world',
number=-1)
self.session.get.called is False
def test_repository(self):
"""Verify the GET request for a repository."""
self.instance.repository('user', 'repo')
self.session.get.assert_called_once_with(url_for('repos/user/repo'))
def test_repository_with_invalid_repo(self):
"""Verify there is no call made for invalid repo combos."""
self.instance.repository('user', None)
assert self.session.get.called is False
def test_repository_with_invalid_user(self):
"""Verify there is no call made for invalid username combos."""
self.instance.repository(None, 'repo')
assert self.session.get.called is False
def test_repository_with_invalid_user_and_repo(self):
"""Verify there is no call made for invalid user/repo combos."""
self.instance.repository(None, None)
assert self.session.get.called is False
def test_repository_with_id(self):
"""Test the ability to retrieve a repository by its id."""
self.instance.repository_with_id(10)
self.session.get.assert_called_once_with(url_for('repositories/10'))
def test_repository_with_id_requires_a_positive_id(self):
"""Test the ability to retrieve a repository by its id."""
self.instance.repository_with_id(-10)
assert self.session.get.called is False
def test_repository_with_id_accepts_a_string(self):
"""Test the ability to retrieve a repository by its id."""
self.instance.repository_with_id('10')
self.session.get.assert_called_once_with(url_for('repositories/10'))
def test_set_client_id(self):
"""Test the ability to set client id/secret."""
auth = ('id000000000000000000', 'secret99999999999999')
self.instance.set_client_id(*auth)
assert self.session.params['client_id'] == auth[0]
assert self.session.params['client_secret'] == auth[1]
def test_two_factor_login(self):
"""Test the ability to pass two_factor_callback."""
self.instance.login('username', 'password',
two_factor_callback=lambda *args: 'foo')
def test_can_login_without_two_factor_callback(self):
"""Test that two_factor_callback is not required."""
self.instance.login('username', 'password')
self.instance.login(token='token')
def test_unfollow(self):
"""Verify the request for unfollowing a user."""
self.instance.unfollow('sigmavirus24')
self.session.delete.assert_called_once_with(
url_for('user/following/sigmavirus24')
)
def test_unfollow_required_username(self):
"""Verify the request for unfollowing a user."""
self.instance.unfollow('')
self.session.delete.called is False
def test_unstar(self):
"""Verify the request for unstarring a repository."""
self.instance.unstar('sigmavirus24', 'github3.py')
self.session.delete.assert_called_once_with(
url_for('user/starred/sigmavirus24/github3.py')
)
def test_unstar_requires_username(self):
"""Verify the request for unstarring a repository."""
self.instance.unstar('', 'github3.py')
self.session.delete.called is False
def test_unstar_requires_repository(self):
"""Verify the request for unstarring a repository."""
self.instance.unstar('sigmavirus24', '')
self.session.delete.called is False
def test_unstar_requires_username_and_repository(self):
"""Verify the request for unstarring a repository."""
self.instance.unstar('', '')
self.session.delete.called is False
def test_update_me(self):
"""Verify the request to update the authenticated user's profile."""
blog='http://blog.example.com', company='Corp',
location='here')
self.patch_called_with(
url_for('user'),
'blog': 'http://blog.example.com', 'company': 'Corp',
'location': 'here', 'hireable': False}
)
def test_user(self):
"""Test that a user can retrieve information about any user."""
self.instance.user('username')
self.session.get.assert_called_once_with(
url_for('users/username'),
)
def test_user_with_id(self):
"""Test that any user's information can be retrieved by id."""
self.instance.user_with_id(10)
self.session.get.assert_called_once_with(url_for('user/10'))
def test_user_with_id_requires_a_positive_id(self):
"""Test that user_with_id requires a positive parameter."""
self.instance.user_with_id(-10)
assert self.session.get.called is False
def test_user_with_id_accepts_a_string(self):
"""Test that any user's information can be retrieved by id."""
self.instance.user_with_id('10')
self.session.get.assert_called_once_with(url_for('user/10'))
def test_set_user_agent_required_user_agent(self):
self.instance.set_user_agent('')
self.session.headers.update.called is False
def test_set_user_agent(self):
self.instance.set_user_agent('github3py')
self.session.headers.update.assert_called_once_with({
'User-Agent': 'github3py'
})
def test_star_required_username_and_repo(self):
assert self.instance.star(username='', repo='') is False
def test_star_required_repo(self):
assert self.instance.star(username='sigmavirus24', repo='') is False
def test_star_required_username(self):
assert self.instance.star(username='', repo='github3.py') is False
def test_star(self):
"""Verify the request for starring a repository."""
self.instance.star('sigmavirus24', 'github3.py')
self.session.put.assert_called_once_with(
url_for('user/starred/sigmavirus24/github3.py')
)
def test_zen(self):
"""Verify the request for returning a quote from Zen of Github."""
self.session.get.return_value = helper.mock.Mock(
status_code=200, text='hello'
)
self.instance.zen()
self.session.get.assert_called_once_with(
url_for('zen')
)
class TestGitHubIterators(helper.UnitIteratorHelper):
described_class = GitHub
example_data = None
def test_all_events(self):
"""Show that one can iterate over all public events."""
i = self.instance.all_events()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('events'),
params={'per_page': 100},
headers={}
)
def test_all_organizations(self):
"""Show that one can iterate over all organizations."""
i = self.instance.all_organizations()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('organizations'),
params={'per_page': 100},
headers={}
)
def test_all_organizations_per_page(self):
"""Show that one can iterate over all organizations with per_page."""
i = self.instance.all_organizations(per_page=25)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('organizations'),
params={'per_page': 25},
headers={}
)
def test_all_organizations_since(self):
"""Show that one can limit the organizations returned."""
since = 100000
i = self.instance.all_organizations(since=since)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('organizations'),
params={'per_page': 100, 'since': since},
headers={}
)
def test_all_repositories(self):
"""Show that one can iterate over all repositories."""
i = self.instance.all_repositories()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('repositories'),
params={'per_page': 100},
headers={}
)
def test_all_repositories_per_page(self):
"""Show that one can iterate over all repositories with per_page."""
i = self.instance.all_repositories(per_page=25)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('repositories'),
params={'per_page': 25},
headers={}
)
def test_all_repositories_since(self):
"""Show that one can limit the repositories returned."""
since = 100000
i = self.instance.all_repositories(since=since)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('repositories'),
params={'per_page': 100, 'since': since},
headers={}
)
def test_all_users(self):
"""Show that one can iterate over all users."""
i = self.instance.all_users()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('users'),
params={'per_page': 100},
headers={}
)
def test_all_users_per_page(self):
"""Show that one can iterate over all users with per_page."""
i = self.instance.all_users(per_page=25)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('users'),
params={'per_page': 25},
headers={}
)
def test_all_users_since(self):
"""Show that one can limit the users returned."""
since = 100000
i = self.instance.all_users(since=since)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('users'),
params={'per_page': 100, 'since': since},
headers={}
)
def test_authorizations(self):
"""
Show that an authenticated user can iterate over their authorizations.
"""
i = self.instance.authorizations()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('authorizations'),
params={'per_page': 100},
headers={}
)
def test_emails(self):
"""Show that an authenticated user can iterate over their emails."""
i = self.instance.emails()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('user/emails'),
params={'per_page': 100},
headers={}
)
def test_followers(self):
"""
Show that an authenticated user can iterate over their followers.
"""
i = self.instance.followers()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('user/followers'),
params={'per_page': 100},
headers={}
)
def test_followers_require_auth(self):
"""Show that one needs to authenticate to use #followers."""
self.session.has_auth.return_value = False
with pytest.raises(GitHubError):
self.instance.followers()
def test_followers_of(self):
"""Show that one can authenticate over the followers of a user."""
i = self.instance.followers_of('sigmavirus24')
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('users/sigmavirus24/followers'),
params={'per_page': 100},
headers={}
)
def test_following(self):
"""
Show that an authenticated user can iterate the users they are
following.
"""
i = self.instance.following()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('user/following'),
params={'per_page': 100},
headers={}
)
def test_following_require_auth(self):
"""Show that one needs to authenticate to use #following."""
self.session.has_auth.return_value = False
with pytest.raises(GitHubError):
self.instance.following()
def test_followed_by(self):
"""
Show that one can authenticate over the users followed by another.
"""
i = self.instance.followed_by('sigmavirus24')
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('users/sigmavirus24/following'),
params={'per_page': 100},
headers={}
)
def test_gists(self):
"""Show that an authenticated user can iterate over their gists."""
i = self.instance.gists()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('gists'),
params={'per_page': 100},
headers={}
)
def test_gists_by(self):
"""Show that an user's gists can be iterated over."""
i = self.instance.gists_by('sigmavirus24')
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('users/sigmavirus24/gists'),
params={'per_page': 100},
headers={}
)
def test_issues(self):
"""Show that an authenticated user can iterate over their issues."""
i = self.instance.issues()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('issues'),
params={'per_page': 100},
headers={}
)
def test_issues_with_params(self):
"""Show that issues can be filtered."""
params = {'filter': 'assigned', 'state': 'closed', 'labels': 'bug',
'sort': 'created', 'direction': 'asc',
'since': '2012-05-20T23:10:27Z'}
p = {'per_page': 100}
p.update(params)
i = self.instance.issues(**params)
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('issues'),
params=p,
headers={}
)
def test_keys(self):
"""
Show that an authenticated user can iterate over their public keys.
"""
i = self.instance.keys()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for('user/keys'),
params={'per_page': 100},
headers={}
)
def test_notifications(self):
"""
Show that an authenticated user can iterate over their notifications.
"""
i = self.instance.notifications()
self.get_next(i)