@@ -36,12 +36,13 @@ class TestSearchIssues(unittest.TestCase):
36
36
module to mock the GitHub API and test the function in isolation.
37
37
38
38
Methods:
39
- test_search_issues: Test that search_issues returns the correct issues.
39
+ test_search_issues_with_owner_and_repository: Test that search_issues with owner/repo returns the correct issues.
40
+ test_search_issues_with_just_owner_or_org: Test that search_issues with just an owner/org returns the correct issues.
40
41
41
42
"""
42
43
43
- def test_search_issues (self ):
44
- """Test that search_issues returns the correct issues."""
44
+ def test_search_issues_with_owner_and_repository (self ):
45
+ """Test that search_issues with owner/repo returns the correct issues."""
45
46
46
47
# Set up the mock GitHub connection object
47
48
mock_issues = [
@@ -63,6 +64,30 @@ def test_search_issues(self):
63
64
issues = search_issues ("is:open" , mock_connection , owners_and_repositories )
64
65
self .assertEqual (issues , mock_issues )
65
66
67
+ def test_search_issues_with_just_owner_or_org (self ):
68
+ """Test that search_issues with just an owner/org returns the correct issues."""
69
+
70
+ # Set up the mock GitHub connection object
71
+ mock_issues = [
72
+ MagicMock (title = "Issue 1" ),
73
+ MagicMock (title = "Issue 2" ),
74
+ MagicMock (title = "Issue 3" ),
75
+ ]
76
+
77
+ # simulating github3.structs.SearchIterator return value
78
+ mock_search_result = MagicMock ()
79
+ mock_search_result .__iter__ .return_value = iter (mock_issues )
80
+ mock_search_result .ratelimit_remaining = 30
81
+
82
+ mock_connection = MagicMock ()
83
+ mock_connection .search_issues .return_value = mock_search_result
84
+
85
+ # Call search_issues and check that it returns the correct issues
86
+ org = {"owner" : "org1" }
87
+ owners = [org ]
88
+ issues = search_issues ("is:open" , mock_connection , owners )
89
+ self .assertEqual (issues , mock_issues )
90
+
66
91
67
92
class TestGetOwnerAndRepository (unittest .TestCase ):
68
93
"""Unit tests for the get_owners_and_repositories function.
@@ -84,7 +109,7 @@ def test_get_owners_with_owner_and_repo_in_query(self):
84
109
self .assertEqual (result [0 ].get ("owner" ), "owner1" )
85
110
self .assertEqual (result [0 ].get ("repository" ), "repo1" )
86
111
87
- def test_get_owner_and_repositories_with_repo_in_query (self ):
112
+ def test_get_owner_and_repositories_without_repo_in_query (self ):
88
113
"""Test get just owner."""
89
114
result = get_owners_and_repositories ("org:owner1" )
90
115
self .assertEqual (result [0 ].get ("owner" ), "owner1" )
0 commit comments