Skip to content

Commit

Permalink
companies: Fix update_companies_job_app_score
Browse files Browse the repository at this point in the history
  • Loading branch information
dejafait committed Dec 26, 2024
1 parent f5863b0 commit d281681
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ def handle(self, **options):
nb_updated = (
models.Company.objects.with_computed_job_app_score()
# Do not update if nothing changes (NULL values have to be handled separately because NULL)
.exclude(
Q(job_app_score=F("computed_job_app_score"))
| Q(job_app_score__isnull=True) & Q(computed_job_app_score__isnull=True)
)
.exclude(Q(job_app_score=F("computed_job_app_score")) & Q(computed_job_app_score__isnull=False))
.exclude(Q(job_app_score__isnull=True) & Q(computed_job_app_score__isnull=True))
.update(job_app_score=F("computed_job_app_score"))
)
self.stdout.write(f"Updated {nb_updated} companies in {time.perf_counter() - start:.3f} seconds")
18 changes: 18 additions & 0 deletions tests/companies/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ def test_update_companies_job_app_score():

assert company_1.job_app_score is None
assert company_2.job_app_score is not None
assert (
company_2.job_app_score
== company_2.job_applications_received.count() / company_2.job_description_through.count()
)

# Deleting job descriptions should bring score back to None.
for jd in company_2.job_description_through.all():
jd.delete()
stdout = io.StringIO()
management.call_command("update_companies_job_app_score", stdout=stdout)
# company_2 changed
assert "Updated 1 companies" in stdout.getvalue()

company_1.refresh_from_db()
company_2.refresh_from_db()

assert company_1.job_app_score is None
assert company_2.job_app_score is None


@freeze_time("2023-05-01")
Expand Down

0 comments on commit d281681

Please sign in to comment.