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 that specify checksumtype in drpm upload #708

Merged
merged 1 commit into from Jul 7, 2017

Conversation

kdelee
Copy link
Contributor

@kdelee kdelee commented Jul 7, 2017

Includes tests in both API and CLI

Closes #585

@Ichimonji10
Let me know what you think.

While re-creating this issue, Pulp issue #2871 was discovered. The consequence of 2871 is that if a checksumtype is specified that does not match a specified checksum, no error is thrown, which is a problem.

Another consequence seems to be that, no matter what "checksumtype" is specified, "sha256" is chosen.

I have not filed a pulp-smash issue yet because it seems there is still some debate about what the problem is -- i.e. should all references be "checksumtype" or is it valid for some to be "checksum_type".

@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage remained the same at 62.204% when pulling 84aa309 on kdelee:test_upload_with_checksumtype into ef3cbb5 on PulpQE:master.

Copy link
Contributor

@Ichimonji10 Ichimonji10 left a comment

Choose a reason for hiding this comment

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

The API test targets the right Pulp functionality, but there's a few tweaks that can be made to the implementation of the test.

},
repo,
)
units = utils.search_units(self.cfg, repo, {}, api.safe_handler)
Copy link
Contributor

Choose a reason for hiding this comment

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

The default response handler is api.json_handler. If the default is used, then the calls to .json() can be omitted from the code below.

units = utils.search_units(self.cfg, repo, {}, api.safe_handler)

with self.subTest(comment='Test if DRPM uploaded.'):
self.assertEqual(len(units.json()), 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

When this assertion fails, the user will be faced with an error message like "assertion failed: 2 not equal to 1." The user won't know what units.json() is, though. This assertion gives the user a little extra information about what went wrong then the test fails:

self.assertEqual(len(units.json()), 1, units.json())

)
units = utils.search_units(self.cfg, repo, {}, api.safe_handler)

with self.subTest(comment='Test if DRPM uploaded.'):
Copy link
Contributor

Choose a reason for hiding this comment

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

What if len(units.json()) == 0? It's a pretty reasonable outcome. In that case, the assertion on the line below will fail... and the test will continue on to the next assertion, which will blow up on the units.json()[0] line. In this case, it's probably easier to just avoid subTest context managers:

self.assertEqual(len(units.json()), 1, units.json())
self.assertEqual(units.json()[0]['metadata']['filename'], DRPM)

client.run(
'pulp-admin rpm repo uploads drpm --repo-id {} --file {}'
.format(repo_id, drpm_file).split() +
'--checksum-type sha256'.split()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is funky. How about this?

'pulp-admin rpm repo uploads drpm --repo-id {} --file {} '
'--checksum-type sha256'
.format(repo_id, drpm_file).split()

@kdelee
Copy link
Contributor Author

kdelee commented Jul 7, 2017

@Ichimonji10
Great feedback, thanks. I'll work on those changes.

kdelee added a commit to kdelee/pulp-smash that referenced this pull request Jul 7, 2017
@kdelee kdelee force-pushed the test_upload_with_checksumtype branch from 84aa309 to e236ea2 Compare July 7, 2017 17:42
@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage remained the same at 62.204% when pulling e236ea2 on kdelee:test_upload_with_checksumtype into ef3cbb5 on PulpQE:master.

# Upload the DRPM into the repository. Pass --skip-existing.
proc = client.run(
('pulp-admin rpm repo uploads drpm --repo-id {} --file {} '
'--skip-existing')
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: These parentheses are redundant. Python will join these two fragments into a string before applying .format().

EDIT: This is something the other test method does too, right? My bad. Worry about it later if you like.

@kdelee
Copy link
Contributor Author

kdelee commented Jul 7, 2017

@Ichimonji10
Made those changes you suggested.

I have not done it, but I could refactor the API test that I based mine off of to be more like this one.

pulp_smash.tests.rpm.api_v2.UploadDrpmTestCase tests the return code (default code_handler does this, right?), and does the same thing with the units = utils.search_units(self.cfg, repo, {}, api.safe_handler) that I had done.

Does that sound like something that should be done in this PR or should I stick to the tests I was writing to close this issue?

@Ichimonji10
Copy link
Contributor

Ichimonji10 commented Jul 7, 2017

pulp_smash.tests.rpm.api_v2.test_upload_publish.UploadDrpmTestCase makes use of an anachronistic coding style. I'd love to see it refactored to look more like the new test case that you've written. Assertions on exact HTTP status codes aren't usually necessary. They just don't prove much. It's easier to let methods like code_handler or safe_handler assert than the status code is less than 400, and then make assertions on other behaviour, like whether a correct checksum was used.

Does that sound like something that should be done in this PR or should I stick to the tests I was writing to close this issue?

If I had my druthers, I'd refactor that existing test case in a separate commit. A refactor would be great regardless of how it lands.

Includes tests in both API and CLI

Closes pulp#585
@kdelee kdelee force-pushed the test_upload_with_checksumtype branch from e236ea2 to c1281cb Compare July 7, 2017 18:32
@kdelee
Copy link
Contributor Author

kdelee commented Jul 7, 2017

@Ichimonji10

Ready to merge now. Thanks for the feedback.
I will do the refactor in a different PR.

@coveralls
Copy link

coveralls commented Jul 7, 2017

Coverage Status

Coverage remained the same at 62.204% when pulling c1281cb on kdelee:test_upload_with_checksumtype into ef3cbb5 on PulpQE:master.

@Ichimonji10 Ichimonji10 merged commit c1281cb into pulp:master Jul 7, 2017
@kdelee kdelee deleted the test_upload_with_checksumtype branch July 7, 2017 19:35
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.

None yet

3 participants