Skip to content
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
32 changes: 23 additions & 9 deletions contentcuration/contentcuration/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def setUp(self):
if not self.persist_bucket:
self.create_bucket()

def setUpBase(self):
if not self.persist_bucket:
self.create_bucket()
self.channel = testdata.channel()
self.user = testdata.user()
self.channel.editors.add(self.user)
self.channel.main_tree.refresh_from_db()

def tearDown(self):
if not self.persist_bucket:
self.delete_bucket()
Expand All @@ -116,6 +124,21 @@ def upload_temp_file(self, data, preset="document", ext="pdf"):
file_upload_url = str(reverse_lazy("api_file_upload"))
return fileobj_temp, self.admin_client().post(file_upload_url, {"file": f})

def sign_in(self, user=None):
if not user:
user = self.user
user.save()
self.client.force_login(user)

def get(self, url, data=None, follow=False, secure=False):
return self.client.get(
url,
data=data,
follow=follow,
secure=secure,
HTTP_USER_AGENT=settings.SUPPORTED_BROWSERS[0],
)


class StudioAPITestCase(APITestCase, BucketTestMixin):
@classmethod
Expand All @@ -131,15 +154,6 @@ def tearDown(self):
if not self.persist_bucket:
self.delete_bucket()


class BaseTestCase(StudioTestCase):
def setUp(self):
super(BaseTestCase, self).setUp()
self.channel = testdata.channel()
self.user = testdata.user()
self.channel.editors.add(self.user)
self.channel.main_tree.refresh_from_db()

def sign_in(self, user=None):
if not user:
user = self.user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest

from .base import BaseTestCase
from .base import StudioTestCase
from .testdata import exercise
from contentcuration import models as cc


class TestForwardAssessmentItemKeypairConstraint(BaseTestCase):
class TestForwardAssessmentItemKeypairConstraint(StudioTestCase):

def test_prevent_two_identical_keypairs(self):
contentnode = cc.ContentNode.objects.create(kind_id=exercise(), extra_fields={})
Expand Down
9 changes: 5 additions & 4 deletions contentcuration/contentcuration/tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import absolute_import

from django.urls import reverse
import urllib.parse

from .base import BaseTestCase
from django.urls import reverse

from .base import StudioTestCase


class AuthenticationTestCase(BaseTestCase):
class AuthenticationTestCase(StudioTestCase):
def setUp(self):
super(AuthenticationTestCase, self).setUp()
super(AuthenticationTestCase, self).setUpBase()
self.base_url = reverse("channel", kwargs={"channel_id": self.channel.pk})

def test_channel_admin_access(self):
Expand Down
20 changes: 12 additions & 8 deletions contentcuration/contentcuration/tests/test_contentnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
from builtins import zip

import pytest
from django.db import IntegrityError
from django.db.utils import DataError
from le_utils.constants import content_kinds
from mixer.backend.django import mixer
from mock import patch
from past.utils import old_div

from . import testdata
from .base import BaseTestCase
from .base import StudioTestCase
from .testdata import create_studio_file
from contentcuration.models import Channel
from contentcuration.models import ContentKind
Expand Down Expand Up @@ -132,9 +133,9 @@ def _check_node_copy(source, copy, original_channel_id=None, channel=None):
_check_node_copy(child_source, child_copy, original_channel_id, channel)


class NodeGettersTestCase(BaseTestCase):
class NodeGettersTestCase(StudioTestCase):
def setUp(self):
super(NodeGettersTestCase, self).setUp()
super(NodeGettersTestCase, self).setUpBase()

self.channel = testdata.channel()
self.topic, _created = ContentKind.objects.get_or_create(kind="Topic")
Expand Down Expand Up @@ -171,9 +172,9 @@ def test_get_node_details(self):
assert len(details["kind_count"]) > 0


class NodeOperationsTestCase(BaseTestCase):
class NodeOperationsTestCase(StudioTestCase):
def setUp(self):
super(NodeOperationsTestCase, self).setUp()
super(NodeOperationsTestCase, self).setUpBase()

self.channel = testdata.channel()
tree = TreeBuilder()
Expand Down Expand Up @@ -717,13 +718,13 @@ def recursive_print(node, indent=0):
)


class SyncNodesOperationTestCase(BaseTestCase):
class SyncNodesOperationTestCase(StudioTestCase):
"""
Checks that sync nodes updates properies.
"""

def setUp(self):
super(SyncNodesOperationTestCase, self).setUp()
super(SyncNodesOperationTestCase, self).setUpBase()

def test_sync_after_no_changes(self):
orig_video, cloned_video = self._setup_original_and_deriative_nodes()
Expand Down Expand Up @@ -844,7 +845,10 @@ def _assert_same_files(self, nodeA, nodeB):
assert fileA.language == fileB.language, "different language found"


class NodeCreationTestCase(BaseTestCase):
class NodeCreationTestCase(StudioTestCase):
def setUp(self):
return super(NodeCreationTestCase, self).setUpBase()

def test_content_tag_creation(self):
"""
Verfies tag creation works
Expand Down
6 changes: 3 additions & 3 deletions contentcuration/contentcuration/tests/test_createchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
from django.urls import reverse_lazy

from .base import BaseTestCase
from .base import StudioTestCase
from .testdata import create_studio_file
from contentcuration import models

Expand Down Expand Up @@ -44,7 +44,7 @@ def add_field_defaults_to_node(node):
###


class CreateChannelTestCase(BaseTestCase):
class CreateChannelTestCase(StudioTestCase):
@classmethod
def setUpClass(cls):
super(CreateChannelTestCase, cls).setUpClass()
Expand All @@ -58,7 +58,7 @@ def setUpClass(cls):
}

def setUp(self):
super(CreateChannelTestCase, self).setUp()
super(CreateChannelTestCase, self).setUpBase()
self.topic = models.ContentKind.objects.get(kind="topic")
self.license = models.License.objects.all()[0]
self.fileinfo_audio = create_studio_file("abc", preset='audio', ext='mp3')
Expand Down
6 changes: 3 additions & 3 deletions contentcuration/contentcuration/tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

from le_utils.constants import content_kinds

from .base import BaseTestCase
from .base import StudioTestCase
from .testdata import create_temp_file
from contentcuration.models import AssessmentItem
from contentcuration.models import Channel
from contentcuration.utils.publish import mark_all_nodes_as_published
from contentcuration.utils.sync import sync_channel


class SyncTestCase(BaseTestCase):
class SyncTestCase(StudioTestCase):
"""
Test channel and node sync operations.
"""

def setUp(self):
super(SyncTestCase, self).setUp()
super(SyncTestCase, self).setUpBase()
self.derivative_channel = Channel.objects.create(name="testchannel")
self.channel.main_tree.copy_to(self.derivative_channel.main_tree)
self.derivative_channel.main_tree.refresh_from_db()
Expand Down
6 changes: 3 additions & 3 deletions contentcuration/contentcuration/tests/test_zipcontentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import tempfile
import zipfile

from .base import BaseTestCase
from .base import StudioTestCase


class ZipFileTestCase(BaseTestCase):
class ZipFileTestCase(StudioTestCase):

def setUp(self):
super(ZipFileTestCase, self).setUp()
super(ZipFileTestCase, self).setUpBase()
self.zipfile_url = '/zipcontent/'

self.temp_files = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from contentcuration.models import File
from contentcuration.models import Task
from contentcuration.tests.base import BaseAPITestCase
from contentcuration.tests.base import BaseTestCase
from contentcuration.tests.base import StudioTestCase
from contentcuration.tests.testdata import tree
from contentcuration.utils.garbage_collect import clean_up_contentnodes
Expand Down Expand Up @@ -209,6 +208,10 @@ def test_delete_all_contentnodes_in_orphanage_tree(self):
assert ContentNode.objects.filter(parent_id=settings.ORPHANAGE_ROOT_ID).count() == 0

def test_deletes_associated_files(self):

# Delete all test data files created by StudioTestCase's setUp.
File.objects.all().delete()

c = _create_expired_contentnode()
f = File.objects.create(
contentnode_id=c.pk,
Expand Down Expand Up @@ -349,7 +352,11 @@ def test_doesnt_delete_file_referenced_by_orphan_and_nonorphan_nodes(self):
assert default_storage.exists("storage/a/a/aaa.jpg")


class CleanUpFeatureFlagsTestCase(BaseTestCase):
class CleanUpFeatureFlagsTestCase(StudioTestCase):

def setUp(self):
return super(CleanUpFeatureFlagsTestCase, self).setUpBase()

def test_clean_up(self):
key = "feature_flag_does_not_exist"
self.user.feature_flags = {
Expand Down
11 changes: 6 additions & 5 deletions contentcuration/contentcuration/tests/utils/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from django.db.models import Max
from django.test import SimpleTestCase

from ..base import BaseTestCase
from ..base import StudioTestCase
from contentcuration.models import ContentNode
from contentcuration.utils.nodes import calculate_resource_size
from contentcuration.utils.nodes import ResourceSizeHelper
from contentcuration.utils.nodes import SlowCalculationError
from contentcuration.utils.nodes import STALE_MAX_CALCULATION_SIZE


class ResourceSizeHelperTestCase(BaseTestCase):
class ResourceSizeHelperTestCase(StudioTestCase):
def setUp(self):
super(ResourceSizeHelperTestCase, self).setUp()
super(ResourceSizeHelperTestCase, self).setUpBase()
self.root = self.channel.main_tree
self.helper = ResourceSizeHelper(self.root)

Expand Down Expand Up @@ -115,12 +115,13 @@ def db_get_size():
self.assertIsInstance(report_exception.mock_calls[0][1][0], SlowCalculationError)


class CalculateResourceSizeIntegrationTestCase(BaseTestCase):
class CalculateResourceSizeIntegrationTestCase(StudioTestCase):
"""
Integration test case
"""

def setUp(self):
super(CalculateResourceSizeIntegrationTestCase, self).setUp()
super(CalculateResourceSizeIntegrationTestCase, self).setUpBase()
self.root = self.channel.main_tree

def test_small(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ class CreateChannelTestCase(StudioTestCase):
"""

def setUp(self):
super(CreateChannelTestCase, self).setUp()
super(CreateChannelTestCase, self).setUpBase()
self.channel_data = {
"id": uuid.uuid4().hex,
"name": "Test channel for creation",
Expand Down