-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for interfaces view (#1768)
* add tests for interfaces view * fix failing tests * chore: update interfaces test * fix python lint * fix failing test * remove unused variable
- Loading branch information
1 parent
621e9ab
commit 8cd8170
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,4 @@ PyGithub==2.2.0 | |
black==24.3.0 | ||
flake8==6.1.0 | ||
Flask-Caching==2.1.0 | ||
responses==0.22.0 | ||
responses==0.22.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import json | ||
from unittest.mock import patch | ||
from unittest import TestCase | ||
|
||
import responses | ||
from webapp.app import app | ||
from webapp.integrations.logic import Interfaces | ||
|
||
|
||
class TestSingleInterface(TestCase): | ||
|
||
def setUp(self): | ||
app.config["TESTING"] = True | ||
app.config["DEBUG"] = True | ||
self.client = app.test_client() | ||
self.test_interfaces = Interfaces() | ||
# mock_github_client = patch("webapp.integrations.logic.github_client") | ||
|
||
self.github_interfaces_url = "".join( | ||
[ | ||
"https://api.github.com/repos/canonical/", | ||
"charm-relation-interfaces/contents/interfaces", | ||
] | ||
) | ||
self.charmhub_api_get_requirers = "".join( | ||
[ | ||
"https://api.charmhub.io/v2/charms/find?", | ||
"q=&category=&publisher=&requires=test_interface", | ||
] | ||
) | ||
self.charmhub_api_get_providers = "".join( | ||
[ | ||
"https://api.charmhub.io/v2/charms/find?", | ||
"q=&category=&publisher=&provides=test_interface", | ||
] | ||
) | ||
|
||
@responses.activate | ||
def test_single_interface(self): | ||
responses.add( | ||
responses.Response( | ||
method="GET", | ||
url=f"{self.github_interfaces_url}/test_interface", | ||
body="test_interface", | ||
status=200, | ||
) | ||
) | ||
responses.add( | ||
responses.Response( | ||
method="GET", | ||
url=self.charmhub_api_get_requirers, | ||
body=json.dumps({"results": ["test_interface1"]}), | ||
status=200, | ||
) | ||
) | ||
responses.add( | ||
responses.Response( | ||
method="GET", | ||
url=self.charmhub_api_get_providers, | ||
body=json.dumps({"results": ["test_interface2"]}), | ||
status=200, | ||
) | ||
) | ||
response = self.client.get("/integrations/test_interface.json") | ||
self.assertEqual(response.status_code, 200) | ||
self.assertDictEqual( | ||
response.json, | ||
{ | ||
"other_charms": { | ||
"providers": ["test_interface2"], | ||
"requirers": ["test_interface1"], | ||
} | ||
}, | ||
) | ||
|
||
@patch("webapp.integrations.logic.Interfaces") | ||
@patch("webapp.app.app.store_api.find") | ||
def test_repo_has_no_interface(self, mock_find, mock_interfaces): | ||
mock_find.return_value = { | ||
"results": ["mock_providers", "mock_requirers"] | ||
} | ||
|
||
mock_interface_logic = mock_interfaces() | ||
mock_interface_logic.get_interface_list.return_value = [] | ||
response = self.client.get("/integrations/test_interface.json") | ||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b"other_charms", response.data) |