-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/34 introduce unit tests for model folder (#42)
* Unit tests using Pytest for model folder
- Loading branch information
1 parent
d1ac0f6
commit 8799012
Showing
15 changed files
with
429 additions
and
70 deletions.
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
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
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
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
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
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
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,67 @@ | ||
# | ||
# Copyright 2024 ABSA Group Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from living_documentation_generator.model.config_repository import ConfigRepository | ||
|
||
|
||
def test_load_from_json_with_valid_input_loads_correctly(): | ||
config_repository = ConfigRepository() | ||
organization_name = "organizationABC" | ||
repository_name = "repositoryABC" | ||
query_labels = ["feature", "bug"] | ||
projects_title_filter = ["project1"] | ||
other_value = "other-value" | ||
repository_json = { | ||
"organization-name": organization_name, | ||
"repository-name": repository_name, | ||
"query-labels": query_labels, | ||
"projects-title-filter": projects_title_filter, | ||
"other-field": other_value, | ||
} | ||
|
||
actual = config_repository.load_from_json(repository_json) | ||
|
||
assert actual | ||
assert organization_name == config_repository.organization_name | ||
assert repository_name == config_repository.repository_name | ||
assert query_labels == config_repository.query_labels | ||
assert projects_title_filter == config_repository.projects_title_filter | ||
|
||
|
||
def test_load_from_json_with_missing_key_logs_error(mocker): | ||
config_repository = ConfigRepository() | ||
mock_log_error = mocker.patch("living_documentation_generator.model.config_repository.logger.error") | ||
repository_json = {"non-existent-key": "value"} | ||
|
||
actual = config_repository.load_from_json(repository_json) | ||
|
||
assert actual is False | ||
mock_log_error.assert_called_once_with( | ||
"The key is not found in the repository JSON input: %s.", mocker.ANY, exc_info=True | ||
) | ||
|
||
|
||
def test_load_from_json_with_wrong_structure_input_logs_error(mocker): | ||
config_repository = ConfigRepository() | ||
mock_log_error = mocker.patch("living_documentation_generator.model.config_repository.logger.error") | ||
repository_json = "not a dictionary" | ||
|
||
actual = config_repository.load_from_json(repository_json) | ||
|
||
assert actual is False | ||
mock_log_error.assert_called_once_with( | ||
"The repository JSON input does not have a dictionary structure: %s.", mocker.ANY, exc_info=True | ||
) |
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,47 @@ | ||
# | ||
# Copyright 2024 ABSA Group Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from github.Issue import Issue | ||
|
||
from living_documentation_generator.model.consolidated_issue import ConsolidatedIssue | ||
|
||
|
||
# generate_page_filename | ||
|
||
|
||
def test_generate_page_filename_correct_behaviour(): | ||
mock_issue = Issue(None, None, {"number": 1, "title": "Issue Title"}, completed=True) | ||
consolidated_issue = ConsolidatedIssue("organization/repository", mock_issue) | ||
|
||
actual = consolidated_issue.generate_page_filename() | ||
|
||
assert "1_issue_title.md" == actual | ||
|
||
|
||
def test_generate_page_filename_with_none_title(mocker): | ||
mock_log_error = mocker.patch("living_documentation_generator.model.consolidated_issue.logger.error") | ||
mock_issue = Issue(None, None, {"number": 1, "title": None}, completed=True) | ||
consolidated_issue = ConsolidatedIssue("organization/repository", mock_issue) | ||
|
||
actual = consolidated_issue.generate_page_filename() | ||
|
||
assert "1.md" == actual | ||
mock_log_error.assert_called_once_with( | ||
"Issue page filename generation failed for Issue %s/%s (%s). Issue does not have a title.", | ||
"organization", | ||
"repository", | ||
1, | ||
exc_info=True, | ||
) |
Oops, something went wrong.