Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
f37eefe4
Commit
f37eefe4
authored
Jul 24, 2017
by
ayub-khan
Committed by
Ayub khan
Jul 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated name for program banner image
parent
76fd9dfa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
course_discovery/apps/course_metadata/tests/test_utils.py
+7
-7
course_discovery/apps/course_metadata/utils.py
+3
-1
No files found.
course_discovery/apps/course_metadata/tests/test_utils.py
View file @
f37eefe4
import
os
import
re
import
ddt
import
ddt
import
responses
import
responses
...
@@ -20,18 +20,18 @@ class UploadToFieldNamePathTests(TestCase):
...
@@ -20,18 +20,18 @@ class UploadToFieldNamePathTests(TestCase):
self
.
program
=
ProgramFactory
()
self
.
program
=
ProgramFactory
()
@ddt.data
(
@ddt.data
(
(
'/media/program'
,
'uuid'
,
'.jpeg'
),
(
'/media/program
/
'
,
'uuid'
,
'.jpeg'
),
(
'/media/program'
,
'title'
,
'.jpeg'
),
(
'/media/program
/
'
,
'title'
,
'.jpeg'
),
(
'/media'
,
'uuid'
,
'.jpeg'
),
(
'/media
/
'
,
'uuid'
,
'.jpeg'
),
(
'/media'
,
'title'
,
'.txt'
),
(
'/media
/
'
,
'title'
,
'.txt'
),
(
''
,
'title'
,
''
),
(
''
,
'title'
,
''
),
)
)
@ddt.unpack
@ddt.unpack
def
test_upload_to
(
self
,
path
,
field
,
ext
):
def
test_upload_to
(
self
,
path
,
field
,
ext
):
upload_to
=
utils
.
UploadToFieldNamePath
(
populate_from
=
field
,
path
=
path
)
upload_to
=
utils
.
UploadToFieldNamePath
(
populate_from
=
field
,
path
=
path
)
upload_path
=
upload_to
(
self
.
program
,
'name'
+
ext
)
upload_path
=
upload_to
(
self
.
program
,
'name'
+
ext
)
expected
=
os
.
path
.
join
(
path
,
str
(
getattr
(
self
.
program
,
field
))
+
ext
)
regex
=
re
.
compile
(
path
+
str
(
getattr
(
self
.
program
,
field
))
+
'-[a-f0-9]{12}'
+
ext
)
self
.
assert
Equal
(
upload_path
,
expected
)
self
.
assert
True
(
regex
.
match
(
upload_path
)
)
class
MarketingSiteAPIClientTests
(
MarketingSiteAPIClientTestMixin
):
class
MarketingSiteAPIClientTests
(
MarketingSiteAPIClientTestMixin
):
...
...
course_discovery/apps/course_metadata/utils.py
View file @
f37eefe4
import
random
import
random
import
string
import
string
import
uuid
import
requests
import
requests
from
django.utils.functional
import
cached_property
from
django.utils.functional
import
cached_property
...
@@ -46,8 +47,9 @@ class UploadToFieldNamePath(UploadTo):
...
@@ -46,8 +47,9 @@ class UploadToFieldNamePath(UploadTo):
def
__call__
(
self
,
instance
,
filename
):
def
__call__
(
self
,
instance
,
filename
):
field_value
=
getattr
(
instance
,
self
.
populate_from
)
field_value
=
getattr
(
instance
,
self
.
populate_from
)
# Update name with Random string of 12 character at the end example '-ba123cd89e97'
self
.
kwargs
.
update
({
self
.
kwargs
.
update
({
'name'
:
field_value
'name'
:
str
(
field_value
)
+
str
(
uuid
.
uuid4
())[
23
:]
})
})
return
super
(
UploadToFieldNamePath
,
self
)
.
__call__
(
instance
,
filename
)
return
super
(
UploadToFieldNamePath
,
self
)
.
__call__
(
instance
,
filename
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment