Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
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
ecommerce
Commits
20d3ddc8
Commit
20d3ddc8
authored
Oct 06, 2017
by
Simon Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix unicode encoding during SKU creation LEARNER-2752
parent
ec18d1db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
ecommerce/extensions/catalogue/tests/test_utils.py
+6
-4
ecommerce/extensions/catalogue/utils.py
+6
-6
No files found.
ecommerce/extensions/catalogue/tests/test_utils.py
View file @
20d3ddc8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
hashlib
import
md5
from
hashlib
import
md5
import
ddt
from
django.db.utils
import
IntegrityError
from
django.db.utils
import
IntegrityError
from
oscar.core.loading
import
get_model
from
oscar.core.loading
import
get_model
...
@@ -22,6 +23,7 @@ Voucher = get_model('voucher', 'Voucher')
...
@@ -22,6 +23,7 @@ Voucher = get_model('voucher', 'Voucher')
COURSE_ID
=
'sku/test_course/course'
COURSE_ID
=
'sku/test_course/course'
@ddt.ddt
class
UtilsTests
(
DiscoveryTestMixin
,
TestCase
):
class
UtilsTests
(
DiscoveryTestMixin
,
TestCase
):
course_id
=
'sku/test_course/course'
course_id
=
'sku/test_course/course'
...
@@ -42,14 +44,14 @@ class UtilsTests(DiscoveryTestMixin, TestCase):
...
@@ -42,14 +44,14 @@ class UtilsTests(DiscoveryTestMixin, TestCase):
with
self
.
assertRaises
(
Exception
):
with
self
.
assertRaises
(
Exception
):
generate_sku
(
product
,
self
.
partner
)
generate_sku
(
product
,
self
.
partner
)
def
test_generate_sku_for_course_seat
(
self
):
@ddt.data
(
'sku/test/course'
,
'course-v1:UNCórdobaX+CS001x+3T2017'
)
def
test_generate_sku_for_course_seat
(
self
,
course_id
):
"""Verify the method generates a SKU for a course seat."""
"""Verify the method generates a SKU for a course seat."""
course_id
=
'sku/test/course'
course
=
CourseFactory
(
id
=
course_id
,
name
=
'Test Course'
,
site
=
self
.
site
)
course
=
CourseFactory
(
id
=
course_id
,
name
=
'Test Course'
,
site
=
self
.
site
)
certificate_type
=
'
honor
'
certificate_type
=
'
audit
'
product
=
course
.
create_or_update_seat
(
certificate_type
,
False
,
0
,
self
.
partner
)
product
=
course
.
create_or_update_seat
(
certificate_type
,
False
,
0
,
self
.
partner
)
_hash
=
'{} {} {} {} {}'
.
format
(
certificate_type
,
course_id
,
'False'
,
''
,
self
.
partner
.
id
)
_hash
=
'{} {} {} {} {}'
.
format
(
certificate_type
,
course_id
,
'False'
,
''
,
self
.
partner
.
id
)
.
encode
(
'utf-8'
)
_hash
=
md5
(
_hash
.
lower
())
.
hexdigest
()[
-
7
:]
_hash
=
md5
(
_hash
.
lower
())
.
hexdigest
()[
-
7
:]
# verify that generated sku has partner 'short_code' as prefix
# verify that generated sku has partner 'short_code' as prefix
expected
=
_hash
.
upper
()
expected
=
_hash
.
upper
()
...
...
ecommerce/extensions/catalogue/utils.py
View file @
20d3ddc8
...
@@ -140,22 +140,22 @@ def generate_sku(product, partner):
...
@@ -140,22 +140,22 @@ def generate_sku(product, partner):
if
product
.
is_coupon_product
:
if
product
.
is_coupon_product
:
_hash
=
' '
.
join
((
_hash
=
' '
.
join
((
unicode
(
product
.
id
),
unicode
(
product
.
id
),
str
(
partner
.
id
)
unicode
(
partner
.
id
)
))
))
.
encode
(
'utf-8'
)
elif
product
.
is_enrollment_code_product
:
elif
product
.
is_enrollment_code_product
:
_hash
=
' '
.
join
((
_hash
=
' '
.
join
((
getattr
(
product
.
attr
,
'course_key'
,
''
),
getattr
(
product
.
attr
,
'course_key'
,
''
),
getattr
(
product
.
attr
,
'seat_type'
,
''
),
getattr
(
product
.
attr
,
'seat_type'
,
''
),
unicode
(
partner
.
id
)
unicode
(
partner
.
id
)
))
))
.
encode
(
'utf-8'
)
elif
product
.
is_seat_product
:
elif
product
.
is_seat_product
:
_hash
=
' '
.
join
((
_hash
=
' '
.
join
((
getattr
(
product
.
attr
,
'certificate_type'
,
''
),
getattr
(
product
.
attr
,
'certificate_type'
,
''
),
product
.
attr
.
course_key
,
unicode
(
product
.
attr
.
course_key
)
,
unicode
(
product
.
attr
.
id_verification_required
),
unicode
(
product
.
attr
.
id_verification_required
),
getattr
(
product
.
attr
,
'credit_provider'
,
''
),
getattr
(
product
.
attr
,
'credit_provider'
,
''
),
str
(
partner
.
id
)
unicode
(
partner
.
id
)
))
))
.
encode
(
'utf-8'
)
else
:
else
:
raise
Exception
(
'Unexpected product class'
)
raise
Exception
(
'Unexpected product class'
)
...
...
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