Skip to content

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Mar 31, 2025

Scope and purpose

Fixes #1323.

Had troubles getting the Django test client stuff working, so this is example of how my tests look using RequestFactory and testing the views directly.

I have not yet figured out how to test htmx specific stuff, like first loading a page, then doing a htmx request to change only a portion of the site and assert that only that portion was updated.

The tests here are more normal tests, checking that values are correct for get requests, http codes, and that stuff is updated correctly in the database for create/update views. These tests are needed as well, but it doesnt really test the htmx functionality itself

This pull request

  • adds/changes/removes a dependency
  • changes the database
  • changes the API

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to Argus can be found in the
Development docs.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff and djLint, easiest by using pre-commit
  • The first line of the commit message continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See our how-to
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this results in changes to the database model: Updated the ER diagram

@stveit stveit self-assigned this Mar 31, 2025
Copy link

@stveit stveit added the nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes) label Mar 31, 2025
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.47%. Comparing base (cea52c4) to head (70c714e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1324      +/-   ##
==========================================
+ Coverage   78.76%   79.47%   +0.71%     
==========================================
  Files         141      141              
  Lines        5763     5763              
==========================================
+ Hits         4539     4580      +41     
+ Misses       1224     1183      -41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

duration = now - start_time
with patch("argus.htmx.incident.views.tznow", return_value=now):
response = incident_detail(self.request, incident.pk)
self.assertContains(response, str(duration))
Copy link
Contributor

Choose a reason for hiding this comment

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

Duration isn't styled properly yet so this is a temporary check. When it is styled properly I would like a generalized (ISO!) duration as well which can be used for checking the logic.

@hmpf hmpf requested a review from a team April 1, 2025 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nonews No news fragment is necessary for this PR (e.g. refactoring, cleanups, workflow/development changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for argus.htmx.incident.views

3 participants