tests: always clean media files
This commit is contained in:
parent
2e58ce9b02
commit
a35727acc1
|
@ -1,12 +1,24 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.files.storage import default_storage
|
||||
|
||||
import django_webtest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(request):
|
||||
def clean_media():
|
||||
for path in ('uploads', 'assets', 'page-pictures', 'pwa'):
|
||||
if os.path.exists(default_storage.path(path)):
|
||||
shutil.rmtree(default_storage.path(path))
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(request, clean_media):
|
||||
wtm = django_webtest.WebTestMixin()
|
||||
wtm._patch_settings()
|
||||
request.addfinalizer(wtm._unpatch_settings)
|
||||
|
|
|
@ -2,7 +2,6 @@ import base64
|
|||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
import mock
|
||||
|
||||
|
@ -30,12 +29,6 @@ pytestmark = pytest.mark.django_db
|
|||
|
||||
TESTS_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
|
||||
|
||||
@pytest.fixture
|
||||
def clean_media():
|
||||
for path in ('uploads', 'assets'):
|
||||
if os.path.exists(default_storage.path(path)):
|
||||
shutil.rmtree(default_storage.path(path))
|
||||
return None
|
||||
|
||||
def login(app, username='admin', password='admin'):
|
||||
login_page = app.get('/login/')
|
||||
|
@ -742,11 +735,10 @@ def test_asset_management_anchor(app, admin_user):
|
|||
# delete
|
||||
resp = resp.click(href=re.compile('delete.*test.png'))
|
||||
resp = resp.form.submit()
|
||||
assert resp.location.endswith('?page=3')
|
||||
resp = resp.follow()
|
||||
assert 'test.png' not in resp.text
|
||||
|
||||
def test_asset_management_search(app, admin_user, clean_media):
|
||||
def test_asset_management_search(app, admin_user):
|
||||
app = login(app)
|
||||
|
||||
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'test.png')
|
||||
|
@ -767,7 +759,7 @@ def test_asset_management_search(app, admin_user, clean_media):
|
|||
resp = resp.form.submit()
|
||||
assert resp.text.count('<tr class="asset') == 2
|
||||
|
||||
def test_asset_slots_management(app, admin_user, clean_media):
|
||||
def test_asset_slots_management(app, admin_user):
|
||||
app = login(app)
|
||||
assert Asset.objects.count() == 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue