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

[INTERNAL] Migrate more tests to use fixtures #418

Merged
merged 2 commits into from
Dec 15, 2022
Merged

Conversation

kfdm
Copy link
Collaborator

@kfdm kfdm commented Dec 15, 2022

Previously we had several tests that used the Django ORM to populate data. Using fixtures should give us more reproducible test.

kfdm added 2 commits December 15, 2022 15:40
Rewrite our alert rule tests to use our fixtures. This means that we no
longer need to do as much setup in the individual test cases and can
focus more on the specific logic we're testing.

Because we're using a rule from a fixture, we also need to update our
test template a bit.
Update our CLI tests to use our fixtures to ensure reproducible tests.
We'll use cli- as a prefix for our objects to ensure they don't otherwise
conflict with out fixture values.
@kfdm kfdm requested a review from a team as a code owner December 15, 2022 06:53
@kfdm kfdm self-assigned this Dec 15, 2022
Copy link
Contributor

@vincent-olivert-riera vincent-olivert-riera left a comment

Choose a reason for hiding this comment

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

I made one question, but overall looks good to me, so... approved 👍🏻

service = models.Service.objects.create(name="TestService")
_ = models.Project.objects.create(name="TestProject", service=service, shard=shard)
management.call_command("register-job", "TestProject", "example", 1234)
management.call_command("register-job", "test-project", "example", 1234)
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll use cli- as a prefix for our objects to ensure they don't otherwise conflict with out fixture values.

In the test_register_job function we are using test-project and example. Shouldn't we do the same as in the test_register_host function and use cli-project and cli.example.com?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in one we're registering to an existing project (from the fixture) and one we are creating new jobs from the test. For the ones created by the test I added the cli- prefix. Should I try to reword things to be a bit more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

So in one we're registering to an existing project (from the fixture) and one we are creating new jobs from the test. For the ones created by the test I added the cli- prefix.

I see 👍🏻

Should I try to reword things to be a bit more clear?

No, I think it's fine as it is.

@kfdm kfdm merged commit 3363e91 into line:master Dec 15, 2022
@kfdm kfdm deleted the test-cleanup branch December 15, 2022 07:41
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.

2 participants