2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

re-enable registration tests

This commit is contained in:
Matthias Mair
2025-01-09 00:10:17 +01:00
parent af4f0a48ed
commit 31e25eb50b

View File

@ -1,7 +1,5 @@
"""Test the sso and auth module functionality.""" """Test the sso and auth module functionality."""
import unittest
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import Group, User from django.contrib.auth.models import Group, User
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -143,6 +141,9 @@ class EmailSettingsContext:
class TestAuth(InvenTreeAPITestCase): class TestAuth(InvenTreeAPITestCase):
"""Test authentication functionality.""" """Test authentication functionality."""
reg_url = '/api/auth/v1/auth/signup'
test_email = 'tester@example.com'
def test_buildin_token(self): def test_buildin_token(self):
"""Test the built-in token authentication.""" """Test the built-in token authentication."""
self.logout() self.logout()
@ -165,41 +166,29 @@ class TestAuth(InvenTreeAPITestCase):
def email_args(self, user=None, email=None): def email_args(self, user=None, email=None):
"""Generate registration arguments.""" """Generate registration arguments."""
return { return {
'username': user or 'user1', 'username': user or 'user2',
'email': email or 'test@example.com', 'email': email or self.test_email,
'password1': '#asdf1234', 'password': '#asdf1234',
'password2': '#asdf1234',
} }
@unittest.skip
def test_registration(self): def test_registration(self):
"""Test the registration process.""" """Test the registration process."""
self.logout() self.logout()
# Duplicate username # Duplicate username
resp = self.post( resp = self.post(
'/api/auth/registration/', self.reg_url, self.email_args(user='testuser'), expected_code=400
self.email_args(user='testuser'),
expected_code=400,
)
self.assertIn(
'A user with that username already exists.', resp.data['username']
) )
self.assertIn('A user with that username already exists.', str(resp.json()))
# Registration is disabled # Registration is disabled
resp = self.post( self.post(self.reg_url, self.email_args(), expected_code=403)
'/api/auth/registration/', self.email_args(), expected_code=400
)
self.assertIn('Registration is disabled.', resp.data['non_field_errors'])
# Enable registration - now it should work # Enable registration - now it should work
with EmailSettingsContext(): with EmailSettingsContext():
resp = self.post( resp = self.post(self.reg_url, self.email_args(), expected_code=200)
'/api/auth/registration/', self.email_args(), expected_code=201 self.assertEqual(resp.json()['data']['user']['email'], self.test_email)
)
self.assertIn('key', resp.data)
@unittest.skip
def test_registration_email(self): def test_registration_email(self):
"""Test that LOGIN_SIGNUP_MAIL_RESTRICTION works.""" """Test that LOGIN_SIGNUP_MAIL_RESTRICTION works."""
self.logout() self.logout()
@ -220,15 +209,13 @@ class TestAuth(InvenTreeAPITestCase):
# Wrong email format # Wrong email format
resp = self.post( resp = self.post(
'/api/auth/registration/', self.reg_url,
self.email_args(email='admin@invenhost.com'), self.email_args(email='admin@invenhost.com'),
expected_code=400, expected_code=400,
) )
self.assertIn('The provided email domain is not approved.', resp.data['email']) self.assertIn('The provided email domain is not approved.', str(resp.json()))
# Right format should work # Right format should work
with EmailSettingsContext(): with EmailSettingsContext():
resp = self.post( resp = self.post(self.reg_url, self.email_args(), expected_code=200)
'/api/auth/registration/', self.email_args(), expected_code=201 self.assertEqual(resp.json()['data']['user']['email'], self.test_email)
)
self.assertIn('key', resp.data)