Commit f37eefe4 by ayub-khan Committed by Ayub khan

updated name for program banner image

parent 76fd9dfa
import os
import re
import ddt
import responses
......@@ -20,18 +20,18 @@ class UploadToFieldNamePathTests(TestCase):
self.program = ProgramFactory()
@ddt.data(
('/media/program', 'uuid', '.jpeg'),
('/media/program', 'title', '.jpeg'),
('/media', 'uuid', '.jpeg'),
('/media', 'title', '.txt'),
('/media/program/', 'uuid', '.jpeg'),
('/media/program/', 'title', '.jpeg'),
('/media/', 'uuid', '.jpeg'),
('/media/', 'title', '.txt'),
('', 'title', ''),
)
@ddt.unpack
def test_upload_to(self, path, field, ext):
upload_to = utils.UploadToFieldNamePath(populate_from=field, path=path)
upload_path = upload_to(self.program, 'name' + ext)
expected = os.path.join(path, str(getattr(self.program, field)) + ext)
self.assertEqual(upload_path, expected)
regex = re.compile(path + str(getattr(self.program, field)) + '-[a-f0-9]{12}' + ext)
self.assertTrue(regex.match(upload_path))
class MarketingSiteAPIClientTests(MarketingSiteAPIClientTestMixin):
......
import random
import string
import uuid
import requests
from django.utils.functional import cached_property
......@@ -46,8 +47,9 @@ class UploadToFieldNamePath(UploadTo):
def __call__(self, instance, filename):
field_value = getattr(instance, self.populate_from)
# Update name with Random string of 12 character at the end example '-ba123cd89e97'
self.kwargs.update({
'name': field_value
'name': str(field_value) + str(uuid.uuid4())[23:]
})
return super(UploadToFieldNamePath, self).__call__(instance, filename)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment