Skip to content

Commit

Permalink
test: [EDXOLDMNG-116] fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Dec 20, 2022
1 parent b1b3b2d commit d0ea28b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cms/djangoapps/contentstore/views/tests/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from xmodule.contentstore.django import contentstore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.xml_importer import import_course_from_xml # lint-amnesty, pylint: disable=wrong-import-order

TEST_DATA_DIR = settings.COMMON_TEST_DATA_ROOT
Expand All @@ -43,6 +44,7 @@ class AssetsTestCase(CourseTestCase):
"""
def setUp(self):
super().setUp()
self.course = CourseFactory(default_store='split')
self.url = reverse_course_url('assets_handler', self.course.id)

def upload_asset(self, name="asset-1", asset_type='text'):
Expand Down Expand Up @@ -513,15 +515,15 @@ def setUp(self):

response = self.client.post(self.url, {"name": self.asset_name, "file": self.asset})
self.assertEqual(response.status_code, 200)
self.uploaded_url = json.loads(response.content.decode('utf-8'))['asset']['url']
self.uploaded_id = json.loads(response.content.decode('utf-8'))['asset']['id']

self.asset_location = AssetKey.from_string(self.uploaded_url)
self.asset_location = AssetKey.from_string(self.uploaded_id)
self.content = contentstore().find(self.asset_location)

def test_delete_asset(self):
""" Tests the happy path :) """
test_url = reverse_course_url(
'assets_handler', self.course.id, kwargs={'asset_key_string': str(self.uploaded_url)})
'assets_handler', self.course.id, kwargs={'asset_key_string': self.uploaded_id})
resp = self.client.delete(test_url, HTTP_ACCEPT="application/json")
self.assertEqual(resp.status_code, 204)

Expand All @@ -533,7 +535,7 @@ def test_delete_image_type_asset(self):
# upload image
response = self.client.post(self.url, {"name": "delete_image_test", "file": image_asset})
self.assertEqual(response.status_code, 200)
uploaded_image_url = json.loads(response.content.decode('utf-8'))['asset']['url']
uploaded_image_url = json.loads(response.content.decode('utf-8'))['asset']['id']

# upload image thumbnail
response = self.client.post(self.url, {"name": "delete_image_thumb_test", "file": thumbnail_image_asset})
Expand Down Expand Up @@ -566,7 +568,7 @@ def test_delete_asset_with_invalid_asset(self):
def test_delete_asset_with_invalid_thumbnail(self):
""" Tests the sad path :( """
test_url = reverse_course_url(
'assets_handler', self.course.id, kwargs={'asset_key_string': str(self.uploaded_url)})
'assets_handler', self.course.id, kwargs={'asset_key_string': self.uploaded_id})
self.content.thumbnail_location = StaticContent.get_location_from_path('/c4x/edX/toy/asset/invalid')
contentstore().save(self.content)
resp = self.client.delete(test_url, HTTP_ACCEPT="application/json")
Expand Down

0 comments on commit d0ea28b

Please sign in to comment.