Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit ee75aff

Browse files
Merge pull request #88 from edx/ammar/sandbox-fixes
sandbox fixes
2 parents 9b01667 + cbc5b4b commit ee75aff

15 files changed

+330
-36
lines changed

VEDA/settings/production.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# Keep track of the names of settings that represent dicts. Instead of overriding the values in base.py,
1919
# the values read from disk should UPDATE the pre-configured dicts.
20-
DICT_UPDATE_KEYS = ('DATABASES', 'JWT_AUTH')
20+
DICT_UPDATE_KEYS = ('DATABASES',)
2121

2222
# Remove the items that should be used to update dicts, and apply them separately rather
2323
# than pumping them into the local vars.
@@ -28,3 +28,10 @@
2828
vars()[key].update(value)
2929

3030
vars().update(CONFIG_DATA)
31+
32+
JWT_AUTH = {
33+
'JWT_SECRET_KEY': CONFIG_DATA['val_secret_key'],
34+
'JWT_ISSUER': '{}/oauth2'.format(CONFIG_DATA['lms_base_url'].rstrip('/')),
35+
'JWT_AUDIENCE': CONFIG_DATA['val_client_id'],
36+
'JWT_VERIFY_AUDIENCE': True,
37+
}

VEDA/tests/test_utils.py

+51
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
22
Tests common utils
33
"""
4+
import glob
45
import os
6+
import shutil
57
import tempfile
68
from unittest import TestCase
79

@@ -204,3 +206,52 @@ def test_scrub_query_params(self, url, params_to_scrub, expected_url):
204206
utils.scrub_query_params(url, params_to_scrub),
205207
expected_url
206208
)
209+
210+
211+
class DeleteDirectoryContentsTests(TestCase):
212+
"""
213+
Tests for `delete_directory_contents` util function.
214+
"""
215+
def setUp(self):
216+
"""
217+
Tests setup.
218+
"""
219+
# create a temp directory with temp directories and files in it
220+
self.temp_dir = tempfile.mkdtemp()
221+
dir_paths = map(lambda index: '{}/dir{}'.format(self.temp_dir, index), range(5))
222+
for dir_path in dir_paths:
223+
os.makedirs(dir_path)
224+
__, file_path = tempfile.mkstemp(
225+
suffix='.txt',
226+
dir=dir_path
227+
)
228+
with open(file_path, 'w') as outfile:
229+
outfile.write(str(TEST_CONFIG))
230+
231+
# create a temp file in root temp directory
232+
with open('{}/{}'.format(self.temp_dir, 'temp_file.text'), 'w') as outfile:
233+
outfile.write(str(TEST_CONFIG))
234+
235+
def tearDown(self):
236+
"""
237+
Reverse the setup
238+
"""
239+
shutil.rmtree(self.temp_dir)
240+
241+
def test_delete_directory_contents(self):
242+
"""
243+
Tests that utils.scrub_query_params works as expected.
244+
"""
245+
# Verify that directory is not empty
246+
self.assertEqual(
247+
len(glob.glob('{path}/*'.format(path=self.temp_dir))),
248+
6
249+
)
250+
251+
utils.delete_directory_contents(self.temp_dir)
252+
253+
# Verify that directory is empty
254+
self.assertEqual(
255+
glob.glob('{path}/*'.format(path=self.temp_dir)),
256+
[]
257+
)

VEDA/utils.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
22
Common utils.
33
"""
4+
import glob
45
import os
6+
import shutil
57
import urllib
68
import urlparse
79
import yaml
@@ -39,7 +41,7 @@ def build_url(*urls, **query_params):
3941
Returns:
4042
absolute url
4143
"""
42-
url = '/'.join(item.strip('/') for item in urls)
44+
url = '/'.join(item.strip('/') for item in urls if item)
4345
if query_params:
4446
url = '{}?{}'.format(url, urllib.urlencode(query_params))
4547

@@ -104,3 +106,21 @@ def scrub_query_params(url, params_to_scrub):
104106
parsed.path,
105107
**new_query_params
106108
)
109+
110+
111+
def delete_directory_contents(path):
112+
"""
113+
Deletes everything inside a directory. Do nothing if path is not a directory.
114+
115+
Arguments:
116+
path (str): path to a directory.
117+
"""
118+
if not os.path.isdir(path):
119+
return
120+
121+
for file_path in glob.glob('{path}/*'.format(path=path.rstrip('/'))):
122+
if os.path.isdir(file_path):
123+
shutil.rmtree(file_path)
124+
125+
if os.path.isfile(file_path):
126+
os.remove(file_path)

VEDA_OS01/fixtures/encodes.json

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
[
2+
{
3+
"model": "VEDA_OS01.destination",
4+
"pk": 1,
5+
"fields": {
6+
"destination_name": "Low Bandwidth Override (AWS S3)",
7+
"destination_active": true,
8+
"destination_nick": "LBO"
9+
}
10+
},
11+
{
12+
"model": "VEDA_OS01.destination",
13+
"pk": 2,
14+
"fields": {
15+
"destination_name": "Youtube - Review",
16+
"destination_active": true,
17+
"destination_nick": "YTR"
18+
}
19+
},
20+
{
21+
"model": "VEDA_OS01.destination",
22+
"pk": 3,
23+
"fields": {
24+
"destination_name": "Youtube - Primary",
25+
"destination_active": true,
26+
"destination_nick": "YT1"
27+
}
28+
},
29+
{
30+
"model": "VEDA_OS01.destination",
31+
"pk": 4,
32+
"fields": {
33+
"destination_name": "Amazon AWS",
34+
"destination_active": true,
35+
"destination_nick": "S31"
36+
}
37+
},
38+
{
39+
"model": "VEDA_OS01.encode",
40+
"pk": 1,
41+
"fields": {
42+
"encode_destination": 4,
43+
"encode_name": "Desktop - High",
44+
"profile_active": true,
45+
"encode_suffix": "DTH",
46+
"encode_filetype": "mp4",
47+
"encode_bitdepth": "27",
48+
"encode_resolution": "720",
49+
"product_spec": "desktop_mp4"
50+
}
51+
},
52+
{
53+
"model": "VEDA_OS01.encode",
54+
"pk": 2,
55+
"fields": {
56+
"encode_destination": 4,
57+
"encode_name": "HLS",
58+
"profile_active": true,
59+
"encode_suffix": "HLS",
60+
"encode_filetype": "HLS",
61+
"encode_bitdepth": "0",
62+
"encode_resolution": "0",
63+
"product_spec": "hls"
64+
}
65+
},
66+
{
67+
"model": "VEDA_OS01.encode",
68+
"pk": 3,
69+
"fields": {
70+
"encode_destination": 1,
71+
"encode_name": "Low Bandwidth Override",
72+
"profile_active": true,
73+
"encode_suffix": "LBO",
74+
"encode_filetype": "mp4",
75+
"encode_bitdepth": "27",
76+
"encode_resolution": "360",
77+
"product_spec": "override"
78+
}
79+
},
80+
{
81+
"model": "VEDA_OS01.encode",
82+
"pk": 4,
83+
"fields": {
84+
"encode_destination": 4,
85+
"encode_name": "Mobile - Low",
86+
"profile_active": true,
87+
"encode_suffix": "MB2",
88+
"encode_filetype": "mp4",
89+
"encode_bitdepth": "27",
90+
"encode_resolution": "360",
91+
"product_spec": "mobile_low"
92+
}
93+
},
94+
{
95+
"model": "VEDA_OS01.encode",
96+
"pk": 5,
97+
"fields": {
98+
"encode_destination": 4,
99+
"encode_name": "mp3",
100+
"profile_active": true,
101+
"encode_suffix": "AUD",
102+
"encode_filetype": "mp3",
103+
"encode_bitdepth": "192",
104+
"encode_resolution": "0",
105+
"product_spec": "audio_mp3"
106+
}
107+
},
108+
{
109+
"model": "VEDA_OS01.encode",
110+
"pk": 6,
111+
"fields": {
112+
"encode_destination": 3,
113+
"encode_name": "Youtube - Primary",
114+
"profile_active": true,
115+
"encode_suffix": "100",
116+
"encode_filetype": "mp4",
117+
"encode_bitdepth": "18",
118+
"encode_resolution": "1080",
119+
"product_spec": "youtube"
120+
}
121+
},
122+
{
123+
"model": "VEDA_OS01.encode",
124+
"pk": 7,
125+
"fields": {
126+
"encode_destination": 2,
127+
"encode_name": "Youtube - Review",
128+
"profile_active": true,
129+
"encode_suffix": "RVW",
130+
"encode_filetype": "mp4",
131+
"encode_bitdepth": "18",
132+
"encode_resolution": "1080",
133+
"product_spec": "review"
134+
}
135+
},
136+
{
137+
"model": "VEDA_OS01.encode",
138+
"pk": 8,
139+
"fields": {
140+
"encode_destination": 4,
141+
"encode_name": "Mobile - High",
142+
"profile_active": false,
143+
"encode_suffix": "MB1",
144+
"encode_filetype": "mp4",
145+
"encode_bitdepth": "30",
146+
"encode_resolution": "540",
147+
"product_spec": "mobile_high"
148+
}
149+
},
150+
{
151+
"model": "VEDA_OS01.encode",
152+
"pk": 9,
153+
"fields": {
154+
"encode_destination": 4,
155+
"encode_name": "WEBM - Desktop High",
156+
"profile_active": false,
157+
"encode_suffix": "DTH",
158+
"encode_filetype": "webm",
159+
"encode_bitdepth": "1000",
160+
"encode_resolution": "720",
161+
"product_spec": "desktop_webm"
162+
}
163+
}
164+
]

VEDA_OS01/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class Destination(models.Model):
540540
destination_nick = models.CharField('Nickname (3 Char.)', max_length=3, null=True, blank=True)
541541

542542
def __unicode__(self):
543-
return u'%s'.format(self.destination_name) or u''
543+
return u'{}'.format(self.destination_name)
544544

545545

546546
class Encode(models.Model):

VEDA_OS01/tests/test_transcripts.py

+25-9
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ def test_cielo24_callback(self, mock_logger):
255255
video = Video.objects.get(studio_id=self.video.studio_id)
256256
self.assertEqual(video.transcript_status, TranscriptStatus.READY)
257257

258-
# verify sjson data uploaded to s3
259-
bucket = conn.get_bucket(CONFIG_DATA['aws_video_transcripts_bucket'])
260-
key = Key(bucket)
261-
key.key = transcript_create_request_data['name']
262-
sjson = json.loads(key.get_contents_as_string())
263-
self.assertEqual(sjson, TRANSCRIPT_SJSON_DATA)
264-
265258
@patch('VEDA_OS01.transcripts.LOGGER')
266259
@responses.activate
267260
def test_fetch_exception_log(self, mock_logger):
@@ -463,8 +456,8 @@ def assert_uploaded_transcript_on_s3(self, connection):
463456
Verify sjson data uploaded to s3
464457
"""
465458
key = Key(connection.get_bucket(CONFIG_DATA['aws_video_transcripts_bucket']))
466-
key.key = '{directory}{uuid}.sjson'.format(
467-
directory=CONFIG_DATA['aws_video_transcripts_prefix'], uuid=self.uuid_hex
459+
key.key = '{transcript_name}.sjson'.format(
460+
transcript_name=transcripts.construct_transcript_names(CONFIG_DATA)[1]
468461
)
469462
sjson_transcript = json.loads(key.get_contents_as_string())
470463
self.assertEqual(sjson_transcript, TRANSCRIPT_SJSON_DATA)
@@ -1565,3 +1558,26 @@ def test_translation_retrieval_with_invalid_course_id(self, course_runs, mock_lo
15651558
self.edx_video_id,
15661559
self.file_id,
15671560
)
1561+
1562+
1563+
class TranscriptNameConstructionTests(APITestCase):
1564+
"""
1565+
Tests for `construct_transcript_names` util function
1566+
"""
1567+
def setUp(self):
1568+
"""
1569+
Tests setup.
1570+
"""
1571+
super(TranscriptNameConstructionTests, self).setUp()
1572+
1573+
def test_upload_sjson_to_s3(self):
1574+
"""
1575+
Verify that `construct_transcript_names` works as expected.
1576+
"""
1577+
edxval_name, s3_name = transcripts.construct_transcript_names(CONFIG_DATA)
1578+
self.assertTrue(
1579+
s3_name.startswith(CONFIG_DATA['instance_prefix'])
1580+
)
1581+
self.assertTrue(
1582+
s3_name.endswith(edxval_name)
1583+
)

0 commit comments

Comments
 (0)