22
22
23
23
"""Integration tests for 'adabot/update_cp_org_libraries.py'"""
24
24
25
+ import json
26
+
25
27
import pytest # pylint: disable=unused-import
26
28
27
29
from adabot .lib import common_funcs
31
33
# pylint: disable=unused-argument
32
34
def mock_list_repos (* args , ** kwargs ):
33
35
"""Function to monkeypatch `common_funcs.list_repos()` for a shorter set of repos."""
34
- return [
35
- github_requests .get ("/repos/adafruit/Adafruit_CircuitPython_TestRepo" ).json ()
36
- ]
36
+ repos = []
37
+ result = github_requests .get (
38
+ "/search/repositories" ,
39
+ params = {
40
+ "q" : "Adafruit_CircuitPython user:adafruit archived:false fork:true" ,
41
+ "per_page" : 100 ,
42
+ "sort" : "updated" ,
43
+ "order" : "asc" ,
44
+ },
45
+ )
46
+
47
+ if result .ok :
48
+ repos .extend (
49
+ repo
50
+ for repo in result .json ()["items" ]
51
+ if (
52
+ repo ["owner" ]["login" ] == "adafruit"
53
+ and (
54
+ repo ["name" ].startswith ("Adafruit_CircuitPython" )
55
+ or repo ["name" ] == "circuitpython"
56
+ )
57
+ )
58
+ )
59
+
60
+ repo_names = [repo ["name" ] for repo in repos ]
61
+
62
+ if kwargs .get ("include_repos" , False ):
63
+ for repo in kwargs ["include_repos" ]:
64
+ if repo not in repo_names :
65
+ add_repo = github_requests .get ("/repos/adafruit/" + repo )
66
+ if add_repo .ok :
67
+ repos .append (add_repo .json ())
68
+ else :
69
+ print ("list_repos(): Failed to retrieve '{}'" .format (repo ))
70
+
71
+ if len (repos ) > 5 :
72
+ repos = repos [:5 ]
73
+
74
+ return repos
37
75
38
76
39
77
# pylint: disable=unused-argument
@@ -54,7 +92,7 @@ def test_update_cp_org_libraries(monkeypatch):
54
92
monkeypatch .setattr (common_funcs , "list_repos" , mock_list_repos )
55
93
monkeypatch .setattr (update_cp_org_libraries , "get_contributors" , mock_get_contribs )
56
94
57
- update_cp_org_libraries .main ()
95
+ update_cp_org_libraries .main (loglevel = "INFO" )
58
96
59
97
60
98
# pylint: disable=invalid-name
@@ -66,8 +104,8 @@ def test_update_cp_org_libraries_output_file(monkeypatch, tmp_path, capsys):
66
104
67
105
tmp_output_file = tmp_path / "output_test.txt"
68
106
69
- update_cp_org_libraries .main (output_file = tmp_output_file )
107
+ update_cp_org_libraries .main (loglevel = "INFO" , output_file = tmp_output_file )
70
108
71
- captured = capsys . readouterr ()
109
+ output = tmp_output_file . read_text ()
72
110
73
- assert tmp_output_file . read_text () == captured . out
111
+ assert json . loads ( output )
0 commit comments