-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Rewrite application Tests using Factory-Boy #116
Conversation
We'll use our factories to seed the DB with fake data as well as testing lets declare our factories in the app dir instead of under /tests
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.
I can't leave a comment inine for this becuase there's no diff for /users/factories.py
, but we don't need to define factory fields on fields that already have a default. Our class
class UserFactory(DjangoModelFactory):
username = Faker("user_name")
email = Faker("email")
name = Faker("name")
@post_generation
def password(self, create: bool, extracted: Sequence[Any], **kwargs):
# bla
is functionally the same as
class UserFactory(DjangoModelFactory):
username = Faker("user_name")
email = Faker("email")
name = Faker("name")
@post_generation
def password(self, create: bool, extracted: Sequence[Any], **kwargs):
# bla
is_staff = False
is_active = True
date_joined = datetime.datetime.now()
last_login = None
because of the model defaults on is_staff
, etc. We can still explicitly overide them if we need to create an admin user, or fake a user who has already logged in, or whatever..
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.
Thanks for working on this. I've left a couple of comments inline
Codecov Report
@@ Coverage Diff @@
## master #116 +/- ##
==========================================
- Coverage 78.88% 76.02% -2.87%
==========================================
Files 25 28 +3
Lines 341 392 +51
==========================================
+ Hits 269 298 +29
- Misses 72 94 +22
Continue to review full report at Codecov.
|
Thanks for your comments @chris48s. Today I'm going to review each one and resolve it. Nice day! 😊 |
@chris48s - I am. I have just been snowed under. Should be able to get to it before the weekend. |
No pressure :) |
@BethanyG I want to help with tests! How we can work together? |
@chris48s Sorry, I didn't notice I closed the PR! 😓 |
@mayela - We could always use more tests and more testing coverage!! I'll open an issue, and we can go from there.... also -- you can always open issues here in the repo for things you think we need to put in place, and if it's work you want to work on..just assign the issue to yourself. We can always discuss details/use cases as we go. 😄 I went ahead and re-wrote the existing (and sorta pathetic) |
Thanks for tagging me; I will take a look! |
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.
Thanks so much, @chris48s -- I admittedly had to look up https://factoryboy.readthedocs.io/en/latest/, but this LGTM!
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.
Nearly there on this one - team effort :)
It looks like your build is failing with AssertionError: '' != 'WEB'
Is that due to #125 ?
If so and you don't want to address the bug in this PR, how about we comment the assertion or use the same technique as I did in 49eca65 and keep the test but mark it as a skip()
or expectedFailure()
for now?
response = self.client.patch(url, data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data['description'], data['description']) | ||
self.assertEqual(response.data['tags'][0]["name"], data['tags'][0]) |
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 happened to the assertions about tags here? (not necessarily wrong to bin them - its just not explained anywhere, I don't think)
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.
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.
as for binning the tags..I was solving an issue with the ordering being different coming back in data
.. and then decided I didn't want to. But I should do at least one test case with tags, so I can add it back in.
url = '/api/v1/resources/96eec6e2-59f4-11ea-9149-dca9047779fe/' | ||
records = create_batch(ResourceFactory, 10) | ||
new_resource = create(ResourceFactory, guid='96f4dd16-59f4-11ea-9149-dca9047779fe') | ||
url = f'/api/v1/resources/{new_resource.guid}/' |
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.
Because you're using new_resource.guid
, we don't actually need to hard-code the guid. This could just be:
new_resource = create(ResourceFactory)
url = f'/api/v1/resources/{new_resource.guid}/'
Also, same comment for test_view_one_resource()
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.
Good point. Dunno what I was thinking there...I did that elsewhere, but brain farted here. Fixed in the new push. Thank for catching!
I think its because I opened the PR: I can't approve my own PR (even though 3 of us have now pushed to the branch) |
…ses, added tag test back into patch_one_resource.
@chris48s - do you wanna have one last look and then push the big, green button? Thank you so much for your patience and work on this!. 🌟 |
LGTM 👍 |
Closes #48
Done so far:
userauth
app to use theUserFactory
(theuser
app tests generated by cookiecutter already had aUserFactory
class) instead of fixturesCustomTagFactory
class and sketched out what theTaggedItemsFactory
needs to look likeThe remaining tasks are:
ResourceFactory
class and finish offTaggedItemsFactory
resources
app to use the tag/resource factories instead of fixtures.We might also look at generating init data (#115) in this PR, or we could leave it for another PR.
@BethanyG - I'll mark up the diff with some notes explaining what I've done so far a bit more. I'll leave it with you to have a look at this PR, work on the
ResourceFactory
andresources
tests and push some more commits to this branch.