def test_basic(self): upload_date = datetime(2013, 6, 1, 10, 30, tzinfo=UTC) content_type = 'image/jpg' course_key = CourseLocator('org', 'class', 'run') location = course_key.make_asset_key('asset', 'my_file_name.jpg') thumbnail_location = course_key.make_asset_key( 'thumbnail', 'my_file_name_thumb.jpg') # pylint: disable=protected-access output = assets._get_asset_json("my_file", content_type, upload_date, location, thumbnail_location, True) self.assertEqual(output["display_name"], "my_file") self.assertEqual(output["date_added"], "Jun 01, 2013 at 10:30 UTC") self.assertEqual( output["url"], "/asset-v1:org+class+run+type@asset+block@my_file_name.jpg") self.assertEqual( output["external_url"], "lms_base_url/asset-v1:org+class+run+type@asset+block@my_file_name.jpg" ) self.assertEqual(output["portable_url"], "/static/my_file_name.jpg") self.assertEqual( output["thumbnail"], "/asset-v1:org+class+run+type@thumbnail+block@my_file_name_thumb.jpg" ) self.assertEqual(output["id"], six.text_type(location)) self.assertEqual(output['locked'], True) output = assets._get_asset_json("name", content_type, upload_date, location, None, False) self.assertIsNone(output["thumbnail"])
def post_asset_update(lock, course): """ Helper method for posting asset update. """ content_type = 'application/txt' upload_date = datetime(2013, 6, 1, 10, 30, tzinfo=UTC) asset_location = course.id.make_asset_key('asset', 'sample_static.html') url = reverse_course_url( 'assets_handler', course.id, kwargs={'asset_key_string': str(asset_location)} ) resp = self.client.post( url, # pylint: disable=protected-access json.dumps(assets._get_asset_json( "sample_static.html", content_type, upload_date, asset_location, None, lock)), "application/json" ) self.assertEqual(resp.status_code, 201) return json.loads(resp.content.decode('utf-8'))