mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-19 22:42:17 +00:00
Revert to old method of sample data gen
bulk_create is super quick, but no autoincrement on sqlite is killer when trying to run tests.
This commit is contained in:
@@ -5,15 +5,18 @@ from django.urls.exceptions import NoReverseMatch
|
||||
|
||||
from RIGS.models import Event
|
||||
from assets.models import Asset
|
||||
from django.db import connection
|
||||
|
||||
|
||||
@pytest.mark.parametrize("command", ['generateSampleAssetsData', 'generateSampleRIGSData', 'generateSampleUserData', 'deleteSampleData'])
|
||||
@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)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_sample_data(settings):
|
||||
settings.DEBUG = True
|
||||
call_command('generateSampleData')
|
||||
@@ -22,6 +25,3 @@ def test_sample_data(settings):
|
||||
call_command('deleteSampleData')
|
||||
assert Asset.objects.all().count() == 0
|
||||
assert Event.objects.all().count() == 0
|
||||
# Cleanup
|
||||
call_command('flush', '--noinput')
|
||||
call_command('migrate')
|
||||
|
||||
@@ -10,6 +10,7 @@ from pytest_django.asserts import assertTemplateUsed, assertInHTML
|
||||
from PyRIGS import urls
|
||||
from RIGS.models import Event
|
||||
from assets.models import Asset
|
||||
from django.db import connection
|
||||
|
||||
|
||||
def find_urls_recursive(patterns):
|
||||
@@ -46,11 +47,9 @@ def sample_data(django_db_blocker):
|
||||
assert Asset.objects.all().count() > 50
|
||||
assert Event.objects.all().count() > 100
|
||||
settings.DEBUG = False
|
||||
yield
|
||||
call_command('flush', '--noinput')
|
||||
call_command('migrate')
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_unauthenticated(client): # Nothing should be available to the unauthenticated
|
||||
for url in find_urls_recursive(urls.urlpatterns):
|
||||
request_url = get_request_url(url)
|
||||
@@ -67,6 +66,7 @@ def test_unauthenticated(client): # Nothing should be available to the unauthen
|
||||
assertRedirects(response, expected_url)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_page_titles(admin_client):
|
||||
for url in filter((lambda u: "embed" not in u.name), find_urls_recursive(urls.urlpatterns)):
|
||||
request_url = get_request_url(url)
|
||||
@@ -81,6 +81,7 @@ def test_page_titles(admin_client):
|
||||
# print(response.content.decode(), file=open('output.html', 'w'))
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_basic_access(client):
|
||||
client.logout()
|
||||
assert client.login(username="basic", password="basic")
|
||||
@@ -92,14 +93,14 @@ def test_basic_access(client):
|
||||
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})
|
||||
url = reverse('asset_detail', kwargs={'pk': Asset.objects.first().pk})
|
||||
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})
|
||||
request_url = reverse(url_name, kwargs={'pk': Asset.objects.first().pk})
|
||||
response = client.get(request_url, follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
@@ -113,6 +114,7 @@ def test_basic_access(client):
|
||||
client.logout()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_keyholder_access(client):
|
||||
client.logout()
|
||||
assert client.login(username="keyholder", password="keyholder")
|
||||
@@ -123,7 +125,7 @@ def test_keyholder_access(client):
|
||||
assertContains(response, 'Edit')
|
||||
assertContains(response, 'Duplicate')
|
||||
|
||||
url = reverse('asset_detail', kwargs={'pk': 1})
|
||||
url = reverse('asset_detail', kwargs={'pk': Asset.objects.first().pk})
|
||||
response = client.get(url)
|
||||
assertContains(response, 'Purchase Details')
|
||||
assertContains(response, 'View Revision History')
|
||||
|
||||
Reference in New Issue
Block a user