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 ngclient to coverage report #1564

Merged
merged 4 commits into from
Sep 8, 2021

Conversation

sechkova
Copy link
Contributor

@sechkova sechkova commented Sep 3, 2021

Fixes #1499, #1552

Description of the changes being introduced by the pull request:
Add ngclient tests for: requests_fetcher.py, trusted_metadata_set.py and updater.py.

Add ngclient to the total coverage report after we've reached 97%.

Please verify and check that the pull request fulfills the following
requirements
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

Add test_read_timeout to test for
urllib3.ReadTimeoutError -> tuf.SlowRetrievalError.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
@coveralls
Copy link

coveralls commented Sep 3, 2021

Pull Request Test Coverage Report for Build 1196971876

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 98.066%

Totals Coverage Status
Change from base Build 1196859362: 0.4%
Covered Lines: 3758
Relevant Lines: 3797

💛 - Coveralls

Copy link
Collaborator

@MVrachev MVrachev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are good additions in this pr and the new tests are understandable.
I have only a couple of small suggestions.

I have only one question/suggestion: I see you applied black on test_updater_ng.py.
Have you also enabled linting checks on test_updater_ng.py when calling tox -e lint?
Also, there are other test modules where we haven't applied black and lining - test_apy.py, test_metadata_serialization.py and test_trusted_metadata_set.py (I am not sure for that one).

Comment on lines 171 to 175
# root is invalid
root = Metadata.from_bytes(self.metadata["root"])
root.signed.version += 1
with self.assertRaises(exceptions.RepositoryError):
test_func(root.to_bytes())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's not immediately clear why root is valid here, because the exception itself is too general.
Maybe change the comment on line 171 to something like:
root cannot be verified, because signature has changed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating the exception to be more specific is an option too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the exception to UnsignedMetadataError: 61e8f40

# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served
# by the SimpleHTTPServer launched here. The test cases of 'test_updater.py'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# by the SimpleHTTPServer launched here. The test cases of 'test_updater.py'
# by the SimpleHTTPServer launched here. The test cases of 'test_updater._ng.py'

self.repository_updater.download_target(targetinfo, self.destination_directory)

def test_updating_root(self):
self._modify_repository_root(lambda root: None, bump_version=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modification function lambda root: None won't do any changes on root right?
Wanted to make sure we only wanted to test here bumping the version and resigning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I needed a modification function doing nothing.

Modify root tests to cover both loading inital
root metadata and updating it.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Add tests covering missing branches of the Updater
code. Inlcude ngclient in the total coverage report.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
@sechkova
Copy link
Contributor Author

sechkova commented Sep 7, 2021

I have only one question/suggestion: I see you applied black on test_updater_ng.py.
Have you also enabled linting checks on test_updater_ng.py when calling tox -e lint?
Also, there are other test modules where we haven't applied black and lining - test_apy.py, test_metadata_serialization.py and test_trusted_metadata_set.py (I am not sure for that one).

I applied black mostly because the file was still using the old code style with 2 spaces but it also needed some beautifying. The rest of the test files are much better formatted. I think the common agreement is that we won't apply the code checkers that strictly on the tests (yet), while running black while editing them probably won't hurt if it seems needed.

@sechkova
Copy link
Contributor Author

sechkova commented Sep 7, 2021

I modified some comments as suggested in the reviews, you can have another look.

Copy link
Member

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- I am trying rewrite the whole testing scheme in #1569, but this PR gets us to some level of code coverage right now and mine does not.

@jku jku linked an issue Sep 8, 2021 that may be closed by this pull request
@jku jku merged commit ea9acf2 into theupdateframework:develop Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ngclient coverage: SlowRetrievalError testing ngclient Updater: write tests to handling coverage report
4 participants