Skip to content

Commit caa7e60

Browse files
makorsaarushtools
authored andcommitted
fix(tests): fix local development tests through docker
1 parent 5bde5cd commit caa7e60

6 files changed

Lines changed: 54 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
{
4949
"name": "Set up packages",
50-
"run": "set -e\n\nsudo apt-get update\nsudo apt-get install -y libfreetype6-dev\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
50+
"run": "set -e\n\nsudo apt-get update\nsudo apt-get install -y libfreetype6-dev\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
5151
},
5252
{
5353
"name": "Copy secret.py",
@@ -94,7 +94,7 @@
9494
},
9595
{
9696
"name": "Set up packages",
97-
"run": "set -e\n\nsudo apt-get update\nsudo apt-get install -y libfreetype6-dev\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
97+
"run": "set -e\n\nsudo apt-get update\nsudo apt-get install -y libfreetype6-dev\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
9898
},
9999
{
100100
"name": "Copy secret.py",
@@ -203,7 +203,7 @@
203203
},
204204
{
205205
"name": "Set up packages",
206-
"run": "set -e\n\nsudo apt-get update\nsudo apt-get install -y libfreetype6-dev\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml pytest-django\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
206+
"run": "set -e\n\nsudo apt-get update\nsudo apt-get install -y libfreetype6-dev\n\npip install -U pip setuptools wheel\npip install -U \\\n pre-commit coveralls pyyaml\npip install -U -r requirements.txt\n\necho \"PATH=$PATH\" >> $GITHUB_ENV\n"
207207
},
208208
{
209209
"name": "Copy secret.py",

ci/spec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ env:
6060
6161
pip install -U pip setuptools wheel
6262
pip install -U \
63-
pre-commit coveralls pyyaml pytest-django
63+
pre-commit coveralls pyyaml
6464
pip install -U -r requirements.txt
6565
6666
echo "PATH=$PATH" >> $GITHUB_ENV

docs/source/developing/testing.rst

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,46 @@ For most modules, the unit tests go in ``intranet/apps/<module>/tests.py``. Curr
1111

1212
.. _running-tests:
1313

14-
Running Tests
15-
=============
14+
Running Tests Locally
15+
=====================
16+
17+
Tests should be run inside the Docker development environment. Make sure your Docker containers are running first:
18+
19+
.. code-block:: bash
20+
21+
cd config/docker
22+
docker compose up -d
23+
24+
Running Tests with Django's Test Runner (Recommended)
25+
-----------------------------------------------------
26+
27+
The recommended way to run tests is using Django's built-in test runner, which is what CI uses:
28+
29+
.. code-block:: bash
30+
31+
# Run all tests (this may take some time!)
32+
docker exec intranet_django python ./manage.py test --noinput
33+
34+
# Run tests for a specific app (in this case, polls)
35+
docker exec intranet_django python ./manage.py test intranet.apps.polls --noinput
36+
37+
# Run a specific test file (in this case, auth)
38+
docker exec intranet_django python ./manage.py test intranet.apps.auth.tests.TurnstileFieldTest --noinput
39+
40+
# Run with verbose output, useful for debugging
41+
docker exec intranet_django python ./manage.py test intranet.apps.polls --noinput -v 2
42+
43+
Interactive Testing Shell
44+
-------------------------
45+
46+
If you want to run multiple test commands, you can open an interactive shell with Docker:
47+
48+
.. code-block:: bash
49+
50+
docker exec -it intranet_django sh
1651
17-
To actually execute tests, run ``pytest`` inside your dev environment. If you want to only test a specific app, you can run ``pytest <apps_name>``. Do note that this deletes and re-creates the db from scratch each time, so you may want to pass the ``-k`` option when developing tests as it significantly reduces run-time.
52+
# then inside the container, run tests:
53+
./manage.py test intranet.apps.polls --noinput
1854
1955
Coverage
2056
========
@@ -42,8 +78,8 @@ The first is calling methods directly; the second is making a GET or POST reques
4278
The best tests utilize both. After you do either/both of these to call the code, you should use assertions to see if the code behaved as expected.
4379
A list of assertion options can be found `here <https://docs.python.org/3/library/unittest.html#assert-methods>`_.
4480
A useful tool for making requests to the view is ``self.client``. More documentation on that can be found
45-
`here <https://docs.djangoproject.com/en/3.2/topics/testing/tools/>`_. Alternatively, just search through Ion's
46-
testing files for examples of using `self.client`.
81+
`here <https://docs.djangoproject.com/en/stable/topics/testing/tools/>`_. Alternatively, just search through Ion's
82+
testing files for examples of using ``self.client``.
4783

4884
Good Testing Examples
4985
=====================
@@ -57,8 +93,8 @@ Ion has lots of tests; the following are examples of very well-written ones. Not
5793
References
5894
==========
5995

60-
- `Django Testing Guide <https://docs.djangoproject.com/en/3.2/topics/testing>`_.
61-
- `Python unittest documentation <https://docs.python.org/3/library/unittest.html>`_.
62-
- `Code Coverage <https://coveralls.io/github/tjcsl/ion>`_.
63-
- `Python Unit Testing Frameworkgood <https://docs.python.org/3/library/unittest.html#assert-methods>`_.
64-
- `Testing Exceptions <https://docs.djangoproject.com/en/3.2/topics/testing/tools/#exceptions>`_.
96+
- `Django Testing Guide <https://docs.djangoproject.com/en/stable/topics/testing/>`_
97+
- `Python unittest documentation <https://docs.python.org/3/library/unittest.html>`_
98+
- `Code Coverage <https://coveralls.io/github/tjcsl/ion>`_
99+
- `Python Unit Testing Assert Methods <https://docs.python.org/3/library/unittest.html#assert-methods>`_
100+
- `Testing Exceptions <https://docs.djangoproject.com/en/stable/topics/testing/tools/#exceptions>`_

intranet/settings/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,10 @@ def get_oidc_private_key():
665665
# "REQUEST_APPROVAL_PROMPT": "auto",
666666
}
667667
OAUTH2_PROVIDER_APPLICATION_MODEL = "oauth.CSLApplication"
668+
OAUTH2_PROVIDER_ACCESS_TOKEN_MODEL = "oauth2_provider.AccessToken"
669+
OAUTH2_PROVIDER_REFRESH_TOKEN_MODEL = "oauth2_provider.RefreshToken"
670+
OAUTH2_PROVIDER_ID_TOKEN_MODEL = "oauth2_provider.IDToken"
671+
OAUTH2_PROVIDER_GRANT_MODEL = "oauth2_provider.Grant"
668672

669673

670674
INSTALLED_APPS = [
@@ -842,7 +846,6 @@ def get_log(name): # pylint: disable=redefined-outer-name; 'name' is used as th
842846
("debug_toolbar.panels.templates.TemplatesPanel", False),
843847
("debug_toolbar.panels.cache.CachePanel", False),
844848
("debug_toolbar.panels.signals.SignalsPanel", False),
845-
("debug_toolbar.panels.logging.LoggingPanel", True),
846849
("debug_toolbar.panels.redirects.RedirectsPanel", False),
847850
("debug_toolbar.panels.profiling.ProfilingPanel", False),
848851
]

pyproject.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ ignore = [
118118
"F403",
119119
]
120120

121-
[tool.ruff.lint.flake8-pytest-style]
122-
fixture-parentheses = false
123-
mark-parentheses = false
124-
parametrize-names-type = "tuple"
125-
parametrize-values-type = "tuple"
126-
127121
[tool.ruff.format]
128122
docstring-code-format = true
129123
line-ending = "lf"

pytest.ini

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)