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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.'): |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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()
@Ichimonji10 |
84aa309
to
e236ea2
Compare
# Upload the DRPM into the repository. Pass --skip-existing. | ||
proc = client.run( | ||
('pulp-admin rpm repo uploads drpm --repo-id {} --file {} ' | ||
'--skip-existing') |
There was a problem hiding this comment.
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.
@Ichimonji10 I have not done it, but I could refactor the API test that I based mine off of to be more like this one.
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
e236ea2
to
c1281cb
Compare
Ready to merge now. Thanks for the feedback. |
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".