Commit Graph

28 Commits

Author SHA1 Message Date
Stanislav Levin
36d5c0e74f
tests: Check urlpatterns after cleanups (#9400)
According to docs:
https://docs.python.org/3/library/unittest.html#unittest.TestCase.addClassCleanup

> Add a function to be called after tearDownClass() to cleanup resources
  used during the test class. Functions will be called in reverse order to
  the order they are added (LIFO).

This was revealed with recent change in pytest (`8.2.0`):
> pytest-dev/pytest#11728: For unittest-based tests, exceptions during
  class cleanup (as raised by functions registered with
  TestCase.addClassCleanup) are now reported instead of silently failing.

`check_urlpatterns` is called before `cleanup_url_patterns` and fails
(problem was hidden by `pytest < 8.2.0`).

`doClassCleanups` can be used instead to check after-cleanup state:

https://docs.python.org/3/library/unittest.html#unittest.TestCase.doClassCleanups

> This method is called unconditionally after tearDownClass(), or after
  setUpClass() if setUpClass() raises an exception.

  It is responsible for calling all the cleanup functions added by
  addClassCleanup(). If you need cleanup functions to be called prior to
  tearDownClass() then you can call doClassCleanups() yourself.

Fixes: https://github.com/encode/django-rest-framework/issues/9399

Signed-off-by: Stanislav Levin <slev@altlinux.org>
2024-05-07 13:05:03 +06:00
Peter Thomassen
d38aab39e4
Remove unused code 2024-04-30 18:28:22 +02:00
willbeaufoy
354ae73ffb
Make APIClient.force_authenticate() work with user=None (#8212)
* Fix testing with token

* Add unit test

* Split unit test into 3

* Fix linting error
2022-09-15 09:35:48 +01:00
hashlash
df92e57ad6
Added test client support for HTTP 307 and 308 redirects (#8419)
* Add retain test data on follow=True

* Simplify TestAPITestClient.test_follow_redirect

Inspired from Django's ClientTest.test_follow_307_and_308_redirect

* Add 307 308 follow redirect test
2022-03-24 09:57:42 +00:00
Carlton Gibson
2d9eee5d02 Adjusted URLPatternsTestCase to use addClassCleanup() from Django 4.0.
Refs faba5b702a.

addClassCleanup() is available from Python 3.8, which is the minimum supported
Python from Django 4.0.
2021-09-22 10:23:47 +02:00
Adam Johnson
410575dace
Replace all url() calls with path() or re_path() (#7512)
* url() is deprecated in Django 3.1

* update given feedbacks on url() is deprecated in Django 3.1

* Fix test_urlpatterns.py to continue testing mixed re_path() and path()

* Fix one missed reference

Co-authored-by: sanjusci <sanju.sci9@gmail.com>
2020-09-08 15:32:27 +01:00
Carlton Gibson
0407a0df8a
Dropped Python 2 compatibility. (#6615)
Thanks to Jon Dufresne (@jdufresne) for review.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Rizwan Mansuri <Rizwan@webbyfox.com>
2019-04-30 17:53:44 +02:00
Ryan P Kilby
b65967711c Formalize URLPatternsTestCase (#5703)
* Add formalized URLPatternsTestCase

* Update versioning tests w/ new URLPatternsTestCase

* Cleanup router tests urlpatterns

* Add docs for URLPatternsTestCase
2018-01-02 11:14:25 +01:00
Ryan P Kilby
0ec915e623 Force content_type inclusion in APIRequestFactory 2017-08-31 05:45:12 -04:00
Ryan P Kilby
eb88687e28 Test RequestFactory with empty body 2017-08-22 15:02:18 -04:00
Asif Saifuddin Auvi
baea07c511 converted testing test asserts to pytest (#4949)
* converted testing test asserts to pytest

* moved 3rd arg from test_empty_post_uses_default_boolean_value test assert
2017-03-10 09:00:00 +00:00
Tom Christie
5677d063d8 Do not treat empty non-form input as HTML. (#4566) 2016-10-12 15:46:24 +01:00
Mathieu Pillard
07efbdb45e Fix APIClient.get() when path contains unicode arguments (#4458) 2016-09-02 17:00:03 +01:00
Dmitry Dygalo
e1768bdc16 Fixed various typos (#4366) 2016-08-08 09:32:22 +01:00
Tom Christie
994e1ba927 Django 1.10 support. (#4158)
* Added TEMPLATES setting to tests
* Remove deprecated view-string in URL conf
* Replace 'urls = ...' in test classes with override_settings('ROOT_URLCONF=...')
* Refactor UsingURLPatterns to use override_settings(ROOT_URLCONF=...) style
* Get model managers and names in a version-compatible manner.
* Apply override_settings to a TestCase, not a mixin class
* Use '.callback' property instead of private attributes when inspecting urlpatterns
* Pass 'user' to template explicitly
* Correct sorting of import statements.
* Remove unused TEMPLATE_LOADERS setting, in favor of TEMPLATES.
* Remove code style issue
* BaseFilter test requires a concrete model
* Resolve tox.ini issues
* Resolve isort differences between local and tox environments
2016-06-01 15:31:00 +01:00
Tom Christie
132eab7bbd Raise helpful error when erronously including nested data in multipart post requests with test client. Closes #2919. 2015-07-14 14:49:44 +01:00
José Padilla
7351a3f6ca Sort imports with isort 2015-06-25 16:55:51 -04:00
Xavier Ordoquy
9f1805f2f0 Removed unused imports. 2015-06-11 00:51:33 +02:00
Xavier Ordoquy
1e51230f1b Remove django.conf.urls.pattern as it'll be removed in Django 2.0 2015-06-11 00:45:23 +02:00
Tom Christie
8825b258ca Clean up import ordering 2014-12-12 13:22:24 +00:00
Tom Christie
e3b16c8bc6 Python 3 test fix 2014-12-12 13:16:18 +00:00
Tom Christie
78312d44d1 Client.logout() also clears any force_authenticate 2014-12-12 13:13:08 +00:00
Jones Chi
2dfe75c23a Fix follow does not work on APIClient
Handle follow just like Django's Client.
2014-10-06 15:10:35 +08:00
Tom Christie
bf09c32de8 Code linting and added runtests.py 2014-08-19 13:28:07 +01:00
Tom Christie
e385a7b8eb Merge master 2014-08-19 10:11:10 +01:00
Xavier Ordoquy
7b4463f739 Merge remote-tracking branch 'reference/2.4.0' into feature/pytest
Conflicts:
	rest_framework/runtests/urls.py
	tests/test_response.py
	tox.ini
2014-05-01 08:01:38 +02:00
Xavier Ordoquy
1797a74e82 Merge remote-tracking branch 'pelme/pytest' into feature/pytest
Conflicts:
	.travis.yml
	rest_framework/runtests/runtests.py
	tests/test_filters.py
	tests/test_pagination.py
	tox.ini
2014-04-17 09:53:44 +02:00
Andreas Pelme
971578ca34 Support for running the test suite with py.test
* Get rid of runtests.py
 * Moved test code  from rest_framework/tests and rest_framework/runtests to tests
 * Invoke py.test from setup.py
 * Invoke py.test from Travis
 * Invoke py.test from tox
 * Changed setUpClass to be just plain setUp in test_permissions.py
 * Updated contribution guideline to show how to invoke py.test
2014-03-02 12:40:30 +01:00