Skip to content

Commit

Permalink
Add info to the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Aug 22, 2024
1 parent 1a495ce commit 7096447
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def initialize_coverity_service(self, login=False):
return coverity_service

def test_session_by_stream_validation(self):
"""To test the session authentication, the function `validate_stream` is used."""
coverity_service = self.initialize_coverity_service(login=False)
with requests_mock.mock() as mocker:
mocker.get(self.stream_url, json={})
Expand All @@ -74,6 +75,7 @@ def test_session_by_stream_validation(self):

@patch("mlx.coverity_services.requests")
def test_stream_validation(self, mock_requests):
"""Test if the function `validate_stream` is called once with the correct url"""
mock_requests.return_value = MagicMock(spec=requests)

# Get the base url
Expand All @@ -87,6 +89,9 @@ def test_stream_validation(self, mock_requests):
mock_method.assert_called_with("https://scan.coverity.com/api/v2/streams/test_stream")

def test_retrieve_columns(self):
"""Test the function `retrieve_column_keys`.
Check if the the columns property is correctly initialized by checking if the name of a column returns
the correct key."""
with open(f"{TEST_FOLDER}/columns_keys.json", "r") as content:
column_keys = json.loads(content.read())
# initialize what needed for the REST API
Expand All @@ -103,6 +108,8 @@ def test_retrieve_columns(self):
assert coverity_service.columns["CID"] == "cid"

def test_retrieve_checkers(self):
"""Test the function `retrieve_checkers`. Check if the returned list of the checkers property is equal to the
keys of checkerAttributedata of the returned data of the request."""
self.fake_checkers = {
"checkerAttribute": {"name": "checker", "displayName": "Checker"},
"checkerAttributedata": [
Expand Down Expand Up @@ -130,6 +137,10 @@ def test_retrieve_checkers(self):
test_defect_filter_3,
])
def test_get_defects(self, filters, column_names, request_data):
"""Check get defects with different filters. Check if the response of `get_defects` is the same as expected.
The data is obtained from the filters.py file.
Due to the usage of set in `get_defects` (column_keys), the function `ordered` is used to compare the returned
data of the request where order does not matter."""
with open(f"{TEST_FOLDER}/columns_keys.json", "r") as content:
column_keys = json.loads(content.read())
self.fake_checkers = {
Expand Down Expand Up @@ -160,6 +171,8 @@ def test_get_defects(self, filters, column_names, request_data):
assert ordered(data) == ordered(request_data)

def test_get_filtered_defects(self):
"""Test `get_filtered_defects` of SphinxCoverityConnector. Check if `get_defects` is called once with the
correct arguments."""
sphinx_coverity_connector = SphinxCoverityConnector()
sphinx_coverity_connector.coverity_service = self.initialize_coverity_service(login=False)
sphinx_coverity_connector.stream = self.fake_stream
Expand All @@ -177,6 +190,7 @@ def test_get_filtered_defects(self):
mock_method.assert_called_once_with(self.fake_stream, fake_node["filters"], column_names)

def test_failed_login(self):
"""Test a failed login by mocking the status code when validating the stream."""
coverity_conf_service = CoverityDefectService("scan.coverity.com/")
stream_url = f"{coverity_conf_service.api_endpoint}/streams/{self.fake_stream}"

Expand Down

0 comments on commit 7096447

Please sign in to comment.