forked from Fediversity/Fediversity
Add test for configform
This commit is contained in:
parent
393ea1e5ff
commit
68c216bcb3
1 changed files with 75 additions and 0 deletions
75
panel/src/panel/tests/test_configurationform.py
Normal file
75
panel/src/panel/tests/test_configurationform.py
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.urls import reverse
|
||||||
|
from panel.models import Configuration, MastodonConfig, PixelfedConfig, PeertubeConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigurationFormTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# Create user
|
||||||
|
self.username = 'testuser'
|
||||||
|
self.password = 'securepassword123'
|
||||||
|
self.user = User.objects.create_user(
|
||||||
|
username=self.username, password=self.password)
|
||||||
|
|
||||||
|
# Retrieve configuration form url
|
||||||
|
self.config_url = reverse('configuration_form')
|
||||||
|
|
||||||
|
# Create configuration attributes
|
||||||
|
self.mastodon_config = MastodonConfig.objects.create(enable=False)
|
||||||
|
self.pixelfed_config = PixelfedConfig.objects.create(enable=False)
|
||||||
|
self.peertube_config = PeertubeConfig.objects.create(enable=False)
|
||||||
|
|
||||||
|
# Create configuration object
|
||||||
|
self.config = Configuration.objects.create(
|
||||||
|
operator=self.user,
|
||||||
|
enable=False,
|
||||||
|
domain='fediversity_eu',
|
||||||
|
mastodon=self.mastodon_config,
|
||||||
|
pixelfed=self.pixelfed_config,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_configuration_form_submission(self):
|
||||||
|
# Log in
|
||||||
|
self.client.login(username=self.username, password=self.password)
|
||||||
|
|
||||||
|
# Get configuration page
|
||||||
|
response = self.client.get(self.config_url)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
form_data = {
|
||||||
|
'domain': 'fediversity_eu',
|
||||||
|
'mastodon_enable': True,
|
||||||
|
'pixelfed_enable': False,
|
||||||
|
'peertube_enable': True,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Post config data
|
||||||
|
response = self.client.post(self.config_url, data=form_data)
|
||||||
|
|
||||||
|
# Check if configuration is saved succesfully
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
self.config.refresh_from_db()
|
||||||
|
|
||||||
|
# Check if new values are saved correctly
|
||||||
|
self.assertTrue(self.config.mastodon.enable)
|
||||||
|
self.assertFalse(self.config.pixelfed.enable)
|
||||||
|
self.assertTrue(self.config.peertube.enable)
|
||||||
|
|
||||||
|
def test_invalid_configuration_form(self):
|
||||||
|
# Log in
|
||||||
|
self.client.login(username=self.username, password=self.password)
|
||||||
|
|
||||||
|
# Send invalid form
|
||||||
|
form_data = {
|
||||||
|
'domain': '',
|
||||||
|
'mastodon_enable': True,
|
||||||
|
'pixelfed_enable': False,
|
||||||
|
'peertube_enable': True,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(self.config_url, data=form_data)
|
||||||
|
|
||||||
|
# Check for error
|
||||||
|
self.assertFormError(response, 'form', 'domain',
|
||||||
|
'This field is required.')
|
Loading…
Add table
Reference in a new issue