Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove coupling of tests to cui #8389

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions src/backend/InvenTree/InvenTree/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.conf import settings
from django.http import Http404
from django.test import tag
from django.urls import reverse

from error_report.models import Error
Expand All @@ -11,8 +10,6 @@
from InvenTree.unit_test import InvenTreeTestCase


# TODO change test to not rely on CUI
@tag('cui')
class MiddlewareTests(InvenTreeTestCase):
"""Test for middleware functions."""

Expand All @@ -32,22 +29,15 @@ def test_AuthRequiredMiddleware(self):
# logout
self.client.logout()

# check that static files go through
# TODO @matmair re-enable this check
# self.check_path('/static/css/inventree.css', 302)

# check that account things go through
self.check_path(reverse('account_login'))

# logout goes directly to login
self.check_path(reverse('account_logout'))
# check that account things are rereouted
self.check_path(reverse('account_login'), 302)

# check that frontend code is redirected to login
response = self.check_path(reverse('stats'), 302)
self.assertEqual(response.url, '/accounts/login/?next=/stats/')

# check that a 401 is raised
self.check_path(reverse('settings.js'), 401)
response = self.check_path(reverse('index'), 302)
self.assertEqual(response.url, '/accounts/login/?next=/')

def test_token_auth(self):
"""Test auth with token auth."""
Expand All @@ -58,16 +48,16 @@ def test_token_auth(self):
# logout
self.client.logout()
# this should raise a 401
self.check_path(reverse('settings.js'), 401)

# request with token
self.check_path(reverse('settings.js'), HTTP_Authorization=f'Token {token}')
self.check_path(reverse('api-license'), 401)

# Request with broken token
self.check_path(reverse('settings.js'), 401, HTTP_Authorization='Token abcd123')
self.check_path(reverse('api-license'), 401, HTTP_Authorization='Token abcd123')

# should still fail without token
self.check_path(reverse('settings.js'), 401)
self.check_path(reverse('api-license'), 401)

# request with token
self.check_path(reverse('api-license'), HTTP_Authorization=f'Token {token}')

def test_error_exceptions(self):
"""Test that ignored errors are not logged."""
Expand All @@ -80,7 +70,7 @@ def check(excpected_nbr=0):

# Test normal setup
check()
response = self.client.get(reverse('part-detail', kwargs={'pk': 9999}))
response = self.client.get(reverse('api-part-detail', kwargs={'pk': 9999}))
self.assertEqual(response.status_code, 404)
check()

Expand All @@ -92,13 +82,8 @@ def check(excpected_nbr=0):

# Test setup without ignored errors
settings.IGNORED_ERRORS = []
response = self.client.get(reverse('part-detail', kwargs={'pk': 9999}))
self.assertEqual(response.status_code, 404)
check(1)

# Test manual logging
try:
raise Http404
except Http404:
log_error('testpath')
check(2)
check(1)
4 changes: 1 addition & 3 deletions src/backend/InvenTree/InvenTree/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.contrib.auth import get_user_model
from django.core import mail
from django.core.exceptions import ValidationError
from django.test import TestCase, override_settings, tag
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone

Expand Down Expand Up @@ -1493,8 +1493,6 @@ def test_generation(self):
self.assertEqual(resp.wsgi_request.user, self.user)


# TODO - refactor to not use CUI
@tag('cui')
class MaintenanceModeTest(InvenTreeTestCase):
"""Unit tests for maintenance mode."""

Expand Down
4 changes: 3 additions & 1 deletion src/backend/InvenTree/InvenTree/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@
frontendpatterns += [
path(
'accounts/login/',
RedirectView.as_view(url=settings.FRONTEND_URL_BASE, permanent=False),
RedirectView.as_view(
url=f'/{settings.FRONTEND_URL_BASE}', permanent=False
),
name='account_login',
)
]
Expand Down
2 changes: 2 additions & 0 deletions src/backend/InvenTree/build/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def test_url(self):
b1 = Build.objects.get(pk=1)
if settings.ENABLE_CLASSIC_FRONTEND:
self.assertEqual(b1.get_absolute_url(), '/build/1/')
else:
self.assertEqual(b1.get_absolute_url(), '/platform/manufacturing/build-order/1')

def test_is_complete(self):
"""Test build completion status"""
Expand Down
4 changes: 1 addition & 3 deletions src/backend/InvenTree/users/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.apps import apps
from django.contrib.auth.models import Group
from django.test import TestCase, tag
from django.test import TestCase
from django.urls import reverse

from common.settings import set_global_setting
Expand Down Expand Up @@ -166,8 +166,6 @@ def do_request(self, endpoint, filters, status_code=200):
self.assertEqual(response.status_code, status_code)
return response.data

# TODO: Find out why this depends on CUI
@tag('cui')
def test_owner(self):
"""Tests for the 'owner' model."""
# Check that owner was created for user
Expand Down
Loading