Some tests keep failing on a freshly installed NetBox instance #5611

Closed
opened 2025-12-29 19:30:09 +01:00 by adam · 2 comments
Owner

Originally created by @peteeckel on GitHub (Nov 4, 2021).

NetBox version

v3.0.9

Python version

3.8

Steps to Reproduce

Run python3 manage.py test on a freshly installed NetBox instance.

Versions installed:

CentOS 7.9
PostgreSQL 11.12
Python 3.8.6
Django 3.2.9

No plugins installed, everything should be plain vanilla. Installation done in a virtual environment in /opt/netbox.

Expected Behavior

All tests succeed.

Observed Behavior

All tests using test_list_objects_anonymous and test_get_objects_anonymous fail. The reason is that the return code from the test call is 302 (Found) instead of 200 (OK) in all cases.

As far as I can see that is happening for all view tests.

(netbox) [root@dns netbox]# ./netbox/manage.py test 
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
(netbox) [root@dns netbox]# ./netbox/manage.py test netbox 
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.............................................................................................................................................................................F....F......................F....F......................F....F......................F....F.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F....F...........................................F....F............................................F....F............................................F....F......................F....F...............................F....F...................F.....F...........................................F....F............................................F....F..........................F....F......................F....F......................F....F......................F....F......................F....F............................................F....F.......................F....F...........................................F....F.......................F....F......................F....F......................F....F............................................F....F.......................F....F......................F....F......................F....F......................F....F................................................................................................................................F...........................................................................................................................................................sssssssssssss...............................F....F......................F....F.......................F....F......................F....F...................F........................F....F......................F....F...FFFFFF...............................................................................................................................................................................................................................................................................................................................................................................................................................F....F......................F....F......................F....F......................F....F......................F....F......................F....F......................F....F...................F....F......................F....F......................F....F......................F....F...............................................................................................F....F......................F....F......s...........................................................s...................................................................................................................................................................................................................................................................................................................................F....F........................F....F......................F....F.........................F....F......................F....F....
======================================================================
FAIL: test_get_object_anonymous (circuits.tests.test_views.CircuitTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/netbox/lib/python3.8/site-packages/django/test/utils.py", line 387, in inner
    return func(*args, **kwargs)
  File "/vagrant/netbox/utilities/testing/views.py", line 62, in test_get_object_anonymous
    self.assertHttpStatus(response, 200)
  File "/vagrant/netbox/utilities/testing/base.py", line 68, in assertHttpStatus
    self.assertEqual(response.status_code, expected_status, err_message)
AssertionError: 302 != 200 : Expected HTTP status 200; received 302: No data

======================================================================
FAIL: test_list_objects_anonymous (circuits.tests.test_views.CircuitTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/netbox/lib/python3.8/site-packages/django/test/utils.py", line 387, in inner
    return func(*args, **kwargs)
  File "/vagrant/netbox/utilities/testing/views.py", line 401, in test_list_objects_anonymous
    self.assertHttpStatus(response, 200)
  File "/vagrant/netbox/utilities/testing/base.py", line 68, in assertHttpStatus
    self.assertEqual(response.status_code, expected_status, err_message)
AssertionError: 302 != 200 : Expected HTTP status 200; received 302: No data

[...]
Originally created by @peteeckel on GitHub (Nov 4, 2021). ### NetBox version v3.0.9 ### Python version 3.8 ### Steps to Reproduce Run `python3 manage.py test` on a freshly installed NetBox instance. Versions installed: CentOS 7.9 PostgreSQL 11.12 Python 3.8.6 Django 3.2.9 No plugins installed, everything should be plain vanilla. Installation done in a virtual environment in /opt/netbox. ### Expected Behavior All tests succeed. ### Observed Behavior All tests using `test_list_objects_anonymous` and `test_get_objects_anonymous` fail. The reason is that the return code from the test call is 302 (Found) instead of 200 (OK) in all cases. As far as I can see that is happening for **all** view tests. ``` (netbox) [root@dns netbox]# ./netbox/manage.py test System check identified no issues (0 silenced). ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK (netbox) [root@dns netbox]# ./netbox/manage.py test netbox Creating test database for alias 'default'... System check identified no issues (0 silenced). .............................................................................................................................................................................F....F......................F....F......................F....F......................F....F.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................F....F...........................................F....F............................................F....F............................................F....F......................F....F...............................F....F...................F.....F...........................................F....F............................................F....F..........................F....F......................F....F......................F....F......................F....F......................F....F............................................F....F.......................F....F...........................................F....F.......................F....F......................F....F......................F....F............................................F....F.......................F....F......................F....F......................F....F......................F....F................................................................................................................................F...........................................................................................................................................................sssssssssssss...............................F....F......................F....F.......................F....F......................F....F...................F........................F....F......................F....F...FFFFFF...............................................................................................................................................................................................................................................................................................................................................................................................................................F....F......................F....F......................F....F......................F....F......................F....F......................F....F......................F....F...................F....F......................F....F......................F....F......................F....F...............................................................................................F....F......................F....F......s...........................................................s...................................................................................................................................................................................................................................................................................................................................F....F........................F....F......................F....F.........................F....F......................F....F.... ====================================================================== FAIL: test_get_object_anonymous (circuits.tests.test_views.CircuitTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/netbox/lib/python3.8/site-packages/django/test/utils.py", line 387, in inner return func(*args, **kwargs) File "/vagrant/netbox/utilities/testing/views.py", line 62, in test_get_object_anonymous self.assertHttpStatus(response, 200) File "/vagrant/netbox/utilities/testing/base.py", line 68, in assertHttpStatus self.assertEqual(response.status_code, expected_status, err_message) AssertionError: 302 != 200 : Expected HTTP status 200; received 302: No data ====================================================================== FAIL: test_list_objects_anonymous (circuits.tests.test_views.CircuitTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/netbox/lib/python3.8/site-packages/django/test/utils.py", line 387, in inner return func(*args, **kwargs) File "/vagrant/netbox/utilities/testing/views.py", line 401, in test_list_objects_anonymous self.assertHttpStatus(response, 200) File "/vagrant/netbox/utilities/testing/base.py", line 68, in assertHttpStatus self.assertEqual(response.status_code, expected_status, err_message) AssertionError: 302 != 200 : Expected HTTP status 200; received 302: No data [...] ```
adam added the type: bug label 2025-12-29 19:30:09 +01:00
adam closed this issue 2025-12-29 19:30:09 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 4, 2021):

Some of the tests assume default values for certain configuration parameters, and will fail if these are changed. Tests are intended to be run using the provided configuration.testing.py file as the active configuration. Do you see any errors when using the stock configuration file?

It should be feasible to rewrite the relevant tests using override_settings() to avoid this, it just hasn't been a priority.

@jeremystretch commented on GitHub (Nov 4, 2021): Some of the tests assume default values for certain configuration parameters, and will fail if these are changed. Tests are intended to be run using the provided `configuration.testing.py` file as the active configuration. Do you see any errors when using the stock configuration file? It should be feasible to rewrite the relevant tests using `override_settings()` to avoid this, it just hasn't been a priority.
Author
Owner

@peteeckel commented on GitHub (Nov 4, 2021):

Thanks, that was the right hint - in fact it is fairly obvious once you get aware of it: In my production configuration, LOGIN_REQUIRED is set to True, which is why all the anonymous requests are redirected to the login request (hence the `302 Found' status).

@peteeckel commented on GitHub (Nov 4, 2021): Thanks, that was the right hint - in fact it is fairly obvious once you get aware of it: In my production configuration, `LOGIN_REQUIRED` is set to `True`, which is why all the anonymous requests are redirected to the login request (hence the `302 Found' status).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5611