Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Folder.DoesNotExist error in local deployment #3580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions perma_web/api/tests/test_link_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from datetime import timedelta
from django.core.files.uploadedfile import SimpleUploadedFile
from mock import patch
from conftest import _fix_json_fixtures


class LinkAuthorizationMixin():
Expand All @@ -22,7 +21,6 @@ class LinkAuthorizationMixin():
@classmethod
def setUpClass(cls):
super().setUpClass()
_fix_json_fixtures()


def setUp(self):
Expand Down Expand Up @@ -308,7 +306,6 @@ def test_should_reject_delete_with_capture_in_progress(self):
class LinkAuthorizationTransactionTestCase(LinkAuthorizationMixin, ApiResourceTransactionTestCase):

def setUp(self):
_fix_json_fixtures()
super(LinkAuthorizationTransactionTestCase, self).setUp()
self.post_data = {'url': self.server_url + "/test.html",
'title': 'This is a test page'}
Expand Down
3 changes: 0 additions & 3 deletions perma_web/api/tests/test_link_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from .utils import ApiResourceTestCase, ApiResourceTransactionTestCase, TEST_ASSETS_DIR, index_warc_file, raise_on_call, raise_after_call, return_on_call, MockResponse
from perma.models import Link, LinkUser, Folder
from conftest import _fix_json_fixtures


class LinkResourceTestMixin():
Expand All @@ -36,7 +35,6 @@ def _pass_fixtures(self, capsys):
@classmethod
def setUpClass(cls):
super().setUpClass()
_fix_json_fixtures()

def setUp(self):
super(LinkResourceTestMixin, self).setUp()
Expand Down Expand Up @@ -357,7 +355,6 @@ class LinkResourceTransactionTestCase(LinkResourceTestMixin, ApiResourceTransact
]

def setUp(self):
_fix_json_fixtures()
super(LinkResourceTransactionTestCase, self).setUp()
self.post_data = {
'url': self.server_url + "/test.html",
Expand Down
31 changes: 0 additions & 31 deletions perma_web/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import subprocess
from waffle import get_waffle_flag_model

from django.db.models import OuterRef, Exists
from django.conf import settings
from django.core.management import call_command
from django.urls import reverse
Expand Down Expand Up @@ -76,43 +75,13 @@ def live_server_ssl_cert(set_up_certs):
}


def _fix_json_fixtures():
# make sure cached_path is accurate, for Folders made from old fixtures
Folder.objects.update(
cached_path=Folder.objects.with_tree_fields().filter(
id=OuterRef('id')
).extra(
select={"path_string" : "array_to_string((__tree.tree_path), '-')"}
).values_list(
"path_string", flat=True
)[:1]
)

# make sure tree_root_id is accurate, for Folders made from old fixtures
from django.db import connection
cursor = connection.cursor()
cursor.execute("UPDATE perma_folder SET tree_root_id = CAST(SPLIT_PART(cached_path, '-', 1) AS INTEGER);")
assert not Folder.objects.filter(cached_path=False).exists()
assert not Folder.objects.filter(tree_root_id__isnull=True).exists()

# make sure cached_has_children is accurate, for Folders made from old fixtures
Folder.objects.update(
cached_has_children=Exists(
Folder.objects.filter(
parent_id=OuterRef('id')
)
)
)

def _load_json_fixtures():
call_command('loaddata', *[
'fixtures/users.json',
'fixtures/api_keys.json',
'fixtures/folders.json',
'fixtures/archive.json'
])
_fix_json_fixtures()



@pytest.fixture(scope='session')
Expand Down
Loading
Loading