Add unit tests for integration config form
Review Request #10830 — Created Jan. 17, 2020 and submitted
Add test scenarios that include checking if
the integration config form saves properly,
and gets/sets key values for the enabled and
name form fields included in the form.All unit tests pass including with the new ones
All unit tests pass including with the new ones.
Description | From | Last Updated |
---|---|---|
Can you add a docstring at the top of the file? Just a one-line summary. Unit tests for <full class … |
chipx86 | |
Please add the bug number to the "Bugs" field on the review request. |
david | |
Please move the last part of your description (about tests passing) to the "Testing Done" field. That also needs a … |
david | |
The lines in the description should wrap at 79 columns. Currently the first is 87 columns. As a tip, you'll … |
chipx86 | |
There's a particular order that imports need to be grouped in (blank lines separating them): Python-provided modules Third-party modules (from … |
chipx86 | |
Mind naming this request_factory? We try to avoid abbreviations, since it's harder to search for them, and isn't self-descriptive. |
chipx86 | |
Let's rename this to just form. class_under_test isn't actually very self-describing. |
chipx86 | |
This will be a lot easier to read and maintain (and fit under 79 characters) as: self.form = IntegrationConfigForm( integration=self.integration, … |
chipx86 | |
E501 line too long (100 > 79 characters) |
reviewbot | |
E501 line too long (106 > 79 characters) |
reviewbot | |
These docstrings are shown when running the test suite, and since there's usually so many (thousands in Review Board!), it's … |
chipx86 | |
Rather than testing whether this returns a value, how about testing that it's the exact value we're expecting? |
chipx86 | |
E501 line too long (97 > 79 characters) |
reviewbot | |
It's confusing that there's two name for this... We try to stick with the singular form, assertEqual. (We don't always … |
chipx86 | |
E501 line too long (109 > 79 characters) |
reviewbot | |
E501 line too long (97 > 79 characters) |
reviewbot | |
E501 line too long (90 > 79 characters) |
reviewbot | |
E501 line too long (112 > 79 characters) |
reviewbot | |
We never want to use the u prefix on any strings. We get those automatically from the from __future__ import … |
chipx86 | |
Please add a class docstring for this (can be the same as your module docstring). |
david | |
This line should have a comma at the end. |
david | |
Missing a period at the end of this. |
chipx86 | |
This is missing a period at the end. |
chipx86 | |
Super minor nit, but it's common to have a blank line after the super() call. Helps to think of code … |
chipx86 | |
I think the docstrings here aren't really descriptive enough. I'm having trouble understanding from them what we're testing. The first … |
chipx86 | |
Oh, just realized. You'll want assertIsInstance here. It's a nice alternative, because if the test fails, it'll provide more useful … |
chipx86 | |
Looks like this is wrapping too early. It should be closer to 79 characters. Same with the ones below. |
chipx86 | |
E501 line too long (89 > 79 characters) |
reviewbot | |
E501 line too long (86 > 79 characters) |
reviewbot |
-
-
Can you add a docstring at the top of the file? Just a one-line summary.
Unit tests for <full class path>.
is good. -
There's a particular order that imports need to be grouped in (blank lines separating them):
- Python-provided modules
- Third-party modules (from the perspective of the project you're working with)
- Project's own modules
And these must all be in alphabetical order. Skip any groups that don't have modules.
So in your case, the
django
ones would be in its own group at the top, then a blank line, then thedjblets
ones. Alphabetical. -
Mind naming this
request_factory
? We try to avoid abbreviations, since it's harder to search for them, and isn't self-descriptive. -
-
This will be a lot easier to read and maintain (and fit under 79 characters) as:
self.form = IntegrationConfigForm( integration=self.integration, request=self.request, instance=None, data={ 'enabled': True, 'name': self.mock_name, })
Note also the keyword arguments. Being explicit here is really good when there's a lot of arguments going on.
Also also, note the
self.mock_name
. No need to reference the class name directly.I think we're only using that name once, so we can probably even nuke the class attribute.
-
These docstrings are shown when running the test suite, and since there's usually so many (thousands in Review Board!), it's very important that they're explicit. They should always include the thing being tested. So you'd probably want something like:
"""Testing IntegrationConfigForm.config returns the configuration instance"""
Or
IntegrationConfigForm.get_key_value()
below, etc. -
Rather than testing whether this returns a value, how about testing that it's the exact value we're expecting?
-
It's confusing that there's two name for this... We try to stick with the singular form,
assertEqual
. (We don't always get it right -- there's a few stragglers in the codebase.) -
We never want to use the
u
prefix on any strings. We get those automatically from thefrom __future__ import unicode_literals
at the top on Python 2.x, and it's the default for 3.x.
- Summary:
-
add unit tests for integration config formAdd unit tests for integration config form
- Description:
-
~ Add test scenarios that include checking if the form saves properly,
~ gets and sets key values for the enabled and name form fields. ~ Add test scenarios that include checking if the integration config form saves properly,
~ and gets/sets key values for the enabled and name form fields included with the form. All unit tests pass including with the new ones
- Commit:
-
11b3fc8d837d748a935ee2275cc61925dda4a61dd8827527d6f9952b2957652aad39b7df3bb3ac03
Checks run (2 succeeded)
- Description:
-
Add test scenarios that include checking if the integration config form saves properly,
and gets/sets key values for the enabled and name form fields included with the form. - - All unit tests pass including with the new ones
- Testing Done:
-
+ All unit tests pass including with the new ones.
- Bugs:
- Commit:
-
d8827527d6f9952b2957652aad39b7df3bb3ac032d515c2efe536005fdd774e17ac6d98b22bafdd8
Checks run (2 succeeded)
-
This is coming along nicely! I have a few suggestions on docstrings, to help make them more self-descriptive.
-
-
-
Super minor nit, but it's common to have a blank line after the
super()
call. Helps to think of code like paragraphs. One paragraph is "We're calling the parent method and setting up all of its state." Next paragraph is "We're setting up the basic objects needed to work with integrations." Paragraph after is "We're setting up state for the form." -
I think the docstrings here aren't really descriptive enough. I'm having trouble understanding from them what we're testing.
The first test says it's testing a default field, but the first thing we check is actually a value provided to the form (form data filled in by a user and POSTed to the page). I think this is really testing that "get_key_value() returns values from form data"
The second, I don't think "default field" makes any sense in the context. I think it's more that "set_key_value() overrides form data"?
The third is more correct but maybe vague? How about "set_key_value() sets custom non-field data"?
- Commit:
-
2d515c2efe536005fdd774e17ac6d98b22bafdd8e5e2792b3dcb7e4f27853327128335b7c51a9fd5
Checks run (2 succeeded)
-
Juuuust about there!
-
The lines in the description should wrap at 79 columns. Currently the first is 87 columns.
As a tip, you'll usually get a column limit when composing a Git commit in your editor, helping to stay under this limit. If you modify the commit after the review request is posted, you can update the information on the review request from the commit by passing
-g yes
when running yourrbt post -u
. -
Oh, just realized. You'll want
assertIsInstance
here. It's a nice alternative, because if the test fails, it'll provide more useful information about the types. -
Looks like this is wrapping too early. It should be closer to 79 characters.
Same with the ones below.
- Description:
-
~ Add test scenarios that include checking if the integration config form saves properly,
~ and gets/sets key values for the enabled and name form fields included with the form. ~ Add test scenarios that include checking
~ if the integration config form saves properly, + and gets/sets key values for the enabled and + name form fields included in the form. - Commit:
-
e5e2792b3dcb7e4f27853327128335b7c51a9fd5ab3079815c30d07e4c2da234e95fcb6d60e26bf2
- Description:
-
~ Add test scenarios that include checking
~ if the integration config form saves properly, ~ and gets/sets key values for the enabled and ~ Add test scenarios that include checking if
~ the integration config form saves properly, ~ and gets/sets key values for the enabled and name form fields included in the form. + + All unit tests pass including with the new ones
- Commit:
-
ab3079815c30d07e4c2da234e95fcb6d60e26bf26096d6a66cde26f7a73203a901e75bd30527c719