mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-18 05:52:15 +00:00
Yet more test shenanigans
Can you tell I'm getting fed up?
This commit is contained in:
@@ -94,7 +94,6 @@ ROOT_URLCONF = 'PyRIGS.urls'
|
||||
WSGI_APPLICATION = 'PyRIGS.wsgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
|
||||
27
PyRIGS/tests/test_commands.py
Normal file
27
PyRIGS/tests/test_commands.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.template.defaultfilters import striptags
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
|
||||
from RIGS.models import Event
|
||||
from assets.models import Asset
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command", ['generateSampleAssetsData', 'generateSampleRIGSData', 'generateSampleUserData', 'deleteSampleData'])
|
||||
def test_production_exception(command):
|
||||
from django.core.management.base import CommandError
|
||||
with pytest.raises(CommandError, match=".*production"):
|
||||
call_command(command)
|
||||
|
||||
|
||||
def test_sample_data(settings):
|
||||
settings.DEBUG = True
|
||||
call_command('generateSampleData')
|
||||
assert Asset.objects.all().count() > 50
|
||||
assert Event.objects.all().count() > 100
|
||||
call_command('deleteSampleData')
|
||||
assert Asset.objects.all().count() == 0
|
||||
assert Event.objects.all().count() == 0
|
||||
# Cleanup
|
||||
call_command('flush', '--noinput')
|
||||
call_command('migrate')
|
||||
@@ -1,12 +1,15 @@
|
||||
from PyRIGS import urls
|
||||
from django.core.management import call_command
|
||||
import pytest
|
||||
from django.urls import URLPattern, URLResolver, reverse
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
from django.test.utils import override_settings
|
||||
from pytest_django.asserts import assertContains, assertRedirects, assertTemplateUsed, assertInHTML
|
||||
from django.core.management import call_command
|
||||
from django.template.defaultfilters import striptags
|
||||
from assets import models
|
||||
from django.urls import URLPattern, URLResolver
|
||||
from django.urls import reverse
|
||||
from django.urls.exceptions import NoReverseMatch
|
||||
from pytest_django.asserts import assertRedirects, assertContains, assertNotContains
|
||||
from pytest_django.asserts import assertTemplateUsed, assertInHTML
|
||||
|
||||
from PyRIGS import urls
|
||||
from RIGS.models import Event
|
||||
from assets.models import Asset
|
||||
|
||||
|
||||
def find_urls_recursive(patterns):
|
||||
@@ -34,13 +37,18 @@ def get_request_url(url):
|
||||
print("Couldn't test url " + pattern)
|
||||
|
||||
|
||||
@pytest.fixture(scope='class', autouse=True)
|
||||
def run_sample_data(django_db_blocker): # We need stuff setup so we don't get 404 errors everywhere
|
||||
@pytest.fixture(scope='module', autouse=True)
|
||||
def sample_data(django_db_blocker):
|
||||
with django_db_blocker.unblock():
|
||||
from django.conf import settings
|
||||
settings.DEBUG = True
|
||||
call_command('generateSampleData')
|
||||
assert Asset.objects.all().count() > 50
|
||||
assert Event.objects.all().count() > 100
|
||||
settings.DEBUG = False
|
||||
yield
|
||||
call_command('flush', '--noinput')
|
||||
call_command('migrate')
|
||||
|
||||
|
||||
def test_unauthenticated(client): # Nothing should be available to the unauthenticated
|
||||
@@ -73,8 +81,50 @@ def test_page_titles(admin_client):
|
||||
# print(response.content.decode(), file=open('output.html', 'w'))
|
||||
|
||||
|
||||
def test_delete_sample_data(settings):
|
||||
settings.DEBUG = True
|
||||
call_command('deleteSampleData')
|
||||
assert models.Asset.objects.all().count() == 0
|
||||
assert models.Supplier.objects.all().count() == 0
|
||||
def test_basic_access(client):
|
||||
client.logout()
|
||||
assert client.login(username="basic", password="basic")
|
||||
|
||||
url = reverse('asset_list')
|
||||
response = client.get(url)
|
||||
# Check edit and duplicate buttons NOT shown in list
|
||||
assertNotContains(response, 'Edit')
|
||||
assertNotContains(response,
|
||||
'Duplicate') # If this line is randomly failing, check the debug toolbar HTML hasn't crept in
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': 1})
|
||||
response = client.get(url)
|
||||
assertNotContains(response, 'Purchase Details')
|
||||
assertNotContains(response, 'View Revision History')
|
||||
|
||||
urlz = {'asset_history', 'asset_update', 'asset_duplicate'}
|
||||
for url_name in urlz:
|
||||
request_url = reverse(url_name, kwargs={'pk': 1})
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
request_url = reverse('supplier_create')
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
request_url = reverse('supplier_update', kwargs={'pk': 1})
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
client.logout()
|
||||
|
||||
|
||||
def test_keyholder_access(client):
|
||||
client.logout()
|
||||
assert client.login(username="keyholder", password="keyholder")
|
||||
|
||||
url = reverse('asset_list')
|
||||
response = client.get(url)
|
||||
# Check edit and duplicate buttons shown in list
|
||||
assertContains(response, 'Edit')
|
||||
assertContains(response, 'Duplicate')
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': 1})
|
||||
response = client.get(url)
|
||||
assertContains(response, 'Purchase Details')
|
||||
assertContains(response, 'View Revision History')
|
||||
client.logout()
|
||||
|
||||
Reference in New Issue
Block a user