Skip to content

Commit

Permalink
Add test that uses the get_filtered_defects function
Browse files Browse the repository at this point in the history
  • Loading branch information
JokeWaumans committed Aug 16, 2024
1 parent 38e9745 commit 13cbd66
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 2 deletions.
148 changes: 148 additions & 0 deletions tests/fake_json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"offset": 0,
"totalRows": 4,
"columns": [
"lastTriageComment",
"classification",
"checker",
"cid"
],
"rows": [
[
{
"key": "lastTriageComment",
"value": ""
},
{
"key": "classification",
"value": "Intentional"
},
{
"key": "checker",
"value": "MISRA 1"
},
{
"key": "cid",
"value": "189049"
},
{
"key": "lineNumber",
"value": "25"
},
{
"key": "displayFile",
"value": "/some/fake/file.c"
},
{
"key": "externalReference",
"value": "REFERENCE1"
},
{
"key": "status",
"value": "Triaged"
}
],
[
{
"key": "lastTriageComment",
"value": "Some fake comment"
},
{
"key": "classification",
"value": "Intentional"
},
{
"key": "checker",
"value": "MISRA 2"
},
{
"key": "cid",
"value": "189050"
},
{
"key": "lineNumber",
"value": "89"
},
{
"key": "displayFile",
"value": "/some/fake/file.c"
},
{
"key": "externalReference",
"value": ""
},
{
"key": "status",
"value": "Dismissed"
}
],
[
{
"key": "lastTriageComment",
"value": "Some fake comment"
},
{
"key": "classification",
"value": "Pending"
},
{
"key": "checker",
"value": "MISRA 3"
},
{
"key": "cid",
"value": "367264"
},
{
"key": "lineNumber",
"value": "10"
},
{
"key": "displayFile",
"value": "/fake/file.c"
},
{
"key": "externalReference",
"value": "REFERENCE3"
},
{
"key": "status",
"value": "Dismissed"
}
],
[
{
"key": "lastTriageComment",
"value": "Another comment"
},
{
"key": "classification",
"value": "Pending"
},
{
"key": "checker",
"value": "CHECK"
},
{
"key": "cid",
"value": "367265"
},
{
"key": "lineNumber",
"value": "34"
},
{
"key": "displayFile",
"value": "/fake/file.c"
},
{
"key": "externalReference",
"value": ""
},
{
"key": "status",
"value": "Triaged"
}
]
]
}
60 changes: 58 additions & 2 deletions tests/test_coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ def test_get_defects_call(self):
coverity_service = self.initialize_coverity_service(login=True)

with requests_mock.mock() as mocker:
with open("tests/columns_keys.json", "r") as content:
column_keys = json.loads(content.read())
mocker.get(self.column_keys_url, json=column_keys)
mocker.get(self.checkers_url, json=self.fake_checkers)
mocker.get(self.stream_url, json={"stream": "valid"})
Expand Down Expand Up @@ -133,6 +131,64 @@ def test_get_defects_call(self):
assert mocker.last_request.verify
assert mocker.last_request.headers["Authorization"] == requests.auth._basic_auth_str("user", "password")

def test_get_filtered_defects(self):
with open("tests/columns_keys.json", "r") as content:
column_keys = json.loads(content.read())

with open("tests/fake_json.json", "r") as content:
self.fake_json = json.loads(content.read())

self.fake_checkers = {
"checkerAttribute": {
"name": "checker",
"displayName": "Checker"
},
"checkerAttributedata": [
{
"key": "MISRA 1",
"value": "MISRA 1"
},
{
"key": "MISRA 2",
"value": "MISRA 2"
},
{
"key": "MISRA 3",
"value": "MISRA 3"
},
{
"key": "CHECK",
"value": "CHECK"
}
]
}
self.fake_stream = "test_stream"

# initialize what needed for the REST API
coverity_service = self.initialize_coverity_service(login=True)

with requests_mock.mock() as mocker:
mocker.get(self.column_keys_url, json=column_keys)
mocker.get(self.checkers_url, json=self.fake_checkers)
mocker.get(self.stream_url, json={"stream": "valid"})
test_post = mocker.post(self.issues_url, json=self.fake_json)

coverity_service.retrieve_checkers()
coverity_service.retrieve_column_keys()

sphinx_coverity_connector = mlx.coverity.SphinxCoverityConnector()
sphinx_coverity_connector.coverity_service = coverity_service
sphinx_coverity_connector.stream = self.fake_stream
node_filters = {'checker': 'MISRA', 'impact': None, 'kind': None,
'classification': 'Intentional,Bug,Pending,Unclassified', 'action': None,
'component': None, 'cwe': None, 'cid': None}
column_names = {'Comment', 'Checker', 'Classification', 'CID'}
fake_node = {"col": column_names,
"filters": node_filters}
defects = sphinx_coverity_connector.get_filtered_defects(fake_node)
breakpoint()
assert defects == self.fake_json

def test_failed_login(self):
fake_stream = "test_stream"

Expand Down

0 comments on commit 13cbd66

Please sign in to comment.