Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for interfaces view #1768

Merged
merged 8 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
87 changes: 87 additions & 0 deletions tests/interfaces/test_single_interface.py
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(
abbiesims marked this conversation as resolved.
Show resolved Hide resolved
[
"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)
Loading