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
39d170e4
Commit
39d170e4
authored
Mar 02, 2017
by
Simon Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert to correct the Learners getting errors on SingleBasketItemView ECOM-7349
parent
0e6e7624
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
39 deletions
+14
-39
ecommerce/core/models.py
+3
-3
ecommerce/core/tests/test_models.py
+0
-1
ecommerce/extensions/basket/tests/test_views.py
+7
-32
ecommerce/extensions/basket/views.py
+4
-3
No files found.
ecommerce/core/models.py
View file @
39d170e4
...
...
@@ -17,7 +17,7 @@ from django.utils.translation import ugettext_lazy as _
from
edx_rest_api_client.client
import
EdxRestApiClient
from
jsonfield.fields
import
JSONField
from
requests.exceptions
import
ConnectionError
,
Timeout
from
slumber.exceptions
import
HttpNotFoundError
,
SlumberBaseException
,
HttpClientError
from
slumber.exceptions
import
HttpNotFoundError
,
SlumberBaseException
from
ecommerce.core.exceptions
import
VerificationStatusError
from
ecommerce.core.url_utils
import
get_lms_url
...
...
@@ -434,11 +434,11 @@ class User(AbstractUser):
try
:
api
=
EdxRestApiClient
(
request
.
site
.
siteconfiguration
.
build_lms_url
(
'/api/enrollment/v1'
),
jwt
=
request
.
site
.
siteconfiguration
.
access_token
,
oauth_access_token
=
self
.
access_token
,
append_slash
=
False
)
status
=
api
.
enrollment
(
','
.
join
([
self
.
username
,
course_key
]))
.
get
()
except
(
ConnectionError
,
SlumberBaseException
,
Timeout
,
HttpClientError
):
except
(
ConnectionError
,
SlumberBaseException
,
Timeout
):
log
.
exception
(
'Failed to retrieve enrollment details for [
%
s] in course [
%
s]'
,
self
.
username
,
...
...
ecommerce/core/tests/test_models.py
View file @
39d170e4
...
...
@@ -78,7 +78,6 @@ class UserTests(CourseCatalogTestMixin, LmsApiMockMixin, TestCase):
""" Verify check for user enrollment in a course. """
user
=
self
.
create_user
()
self
.
request
.
user
=
user
self
.
mock_access_token_response
()
course_id1
=
'course-v1:test+test+test'
__
,
enrolled_seat
=
self
.
create_course_and_seat
(
course_id
=
course_id1
,
seat_type
=
mode
,
id_verification
=
id_verification
...
...
ecommerce/extensions/basket/tests/test_views.py
View file @
39d170e4
...
...
@@ -37,7 +37,7 @@ from ecommerce.extensions.payment.forms import PaymentForm
from
ecommerce.extensions.payment.tests.processors
import
DummyProcessor
from
ecommerce.extensions.test.factories
import
prepare_voucher
from
ecommerce.tests.factories
import
StockRecordFactory
from
ecommerce.tests.mixins
import
ApiMockMixin
,
LmsApiMockMixin
,
SiteMixin
from
ecommerce.tests.mixins
import
ApiMockMixin
,
LmsApiMockMixin
from
ecommerce.tests.testcases
import
TestCase
Applicator
=
get_class
(
'offer.utils'
,
'Applicator'
)
...
...
@@ -57,8 +57,7 @@ COUPON_CODE = 'COUPONTEST'
@ddt.ddt
class
BasketSingleItemViewTests
(
CouponMixin
,
CourseCatalogTestMixin
,
CourseCatalogMockMixin
,
LmsApiMockMixin
,
TestCase
,
SiteMixin
):
class
BasketSingleItemViewTests
(
CouponMixin
,
CourseCatalogTestMixin
,
CourseCatalogMockMixin
,
LmsApiMockMixin
,
TestCase
):
""" BasketSingleItemView view tests. """
path
=
reverse
(
'basket:single-item'
)
...
...
@@ -144,7 +143,6 @@ class BasketSingleItemViewTests(CouponMixin, CourseCatalogTestMixin, CourseCatal
Verify the view redirects to the basket summary page, and that the user's basket is prepared for checkout.
"""
self
.
mock_enrollment_api_success_enrolled
(
self
.
course
.
id
)
self
.
mock_access_token_response
()
self
.
create_coupon
(
catalog
=
self
.
catalog
,
code
=
COUPON_CODE
,
benefit_value
=
5
)
self
.
mock_dynamic_catalog_course_runs_api
(
course_run
=
self
.
course
)
...
...
@@ -169,14 +167,14 @@ class BasketSingleItemViewTests(CouponMixin, CourseCatalogTestMixin, CourseCatal
(The Enrollment API call being used returns an active enrollment record in this case)
"""
course
=
CourseFactory
()
self
.
mock_access_token_response
()
self
.
mock_enrollment_api_success_enrolled
(
course
.
id
,
mode
=
mode
)
product
=
course
.
create_or_update_seat
(
mode
,
id_verification
,
0
,
self
.
partner
,
create_enrollment_code
=
False
)
product
=
course
.
create_or_update_seat
(
mode
,
id_verification
,
0
,
self
.
partner
)
stock_record
=
StockRecordFactory
(
product
=
product
,
partner
=
self
.
partner
)
catalog
=
Catalog
.
objects
.
create
(
partner
=
self
.
partner
)
catalog
.
stock_records
.
add
(
stock_record
)
self
.
create_coupon
(
catalog
=
catalog
,
code
=
COUPON_CODE
,
benefit_value
=
5
)
url
=
'{path}?sku={sku}
'
.
format
(
path
=
self
.
path
,
sku
=
stock_record
.
partner_sku
)
url
=
'{path}?sku={sku}
&code={code}'
.
format
(
path
=
self
.
path
,
sku
=
stock_record
.
partner_sku
,
code
=
COUPON_CODE
)
expected_content
=
'You are already enrolled in {product}.'
.
format
(
product
=
product
.
course
.
name
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
400
)
...
...
@@ -191,7 +189,6 @@ class BasketSingleItemViewTests(CouponMixin, CourseCatalogTestMixin, CourseCatal
(The Enrollment API call being used returns an inactive enrollment record in this case)
"""
course
=
CourseFactory
()
self
.
mock_access_token_response
()
self
.
mock_enrollment_api_success_unenrolled
(
course
.
id
,
mode
=
mode
)
product
=
course
.
create_or_update_seat
(
mode
,
id_verification
,
0
,
self
.
partner
)
stock_record
=
StockRecordFactory
(
product
=
product
,
partner
=
self
.
partner
)
...
...
@@ -206,29 +203,6 @@ class BasketSingleItemViewTests(CouponMixin, CourseCatalogTestMixin, CourseCatal
self
.
assertEqual
(
response
.
wsgi_request
.
GET
[
'sku'
],
sku
)
@httpretty.activate
@ddt.data
((
'verified'
,
False
),
(
'professional'
,
True
),
(
'no-id-professional'
,
False
))
@ddt.unpack
def
test_enrolled_verified_student_for_enrollment_code
(
self
,
mode
,
id_verification
):
"""
Verify the view return HTTP 303 if the student is enrolled as verified and purchasing enrollment code
(The Enrollment API call being used returns an inactive enrollment record in this case)
"""
course
=
CourseFactory
()
self
.
mock_enrollment_api_success_enrolled
(
course
.
id
,
mode
=
mode
)
toggle_switch
(
ENROLLMENT_CODE_SWITCH
,
True
)
course
.
create_or_update_seat
(
mode
,
id_verification
,
10
,
self
.
partner
,
create_enrollment_code
=
True
)
product
=
Product
.
objects
.
get
(
product_class__name
=
ENROLLMENT_CODE_PRODUCT_CLASS_NAME
)
stock_record
=
StockRecordFactory
(
product
=
product
,
partner
=
self
.
partner
)
catalog
=
Catalog
.
objects
.
create
(
partner
=
self
.
partner
)
catalog
.
stock_records
.
add
(
stock_record
)
url
=
'{path}?sku={sku}'
.
format
(
path
=
self
.
path
,
sku
=
stock_record
.
partner_sku
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
303
)
self
.
assertEqual
(
response
.
wsgi_request
.
path_info
,
'/basket/single-item/'
)
self
.
assertEqual
(
response
.
wsgi_request
.
GET
[
'sku'
],
stock_record
.
partner_sku
)
@httpretty.activate
@ddt.data
(
ConnectionError
,
SlumberBaseException
,
Timeout
)
def
test_enrollment_api_failure
(
self
,
error
):
"""
...
...
@@ -236,7 +210,8 @@ class BasketSingleItemViewTests(CouponMixin, CourseCatalogTestMixin, CourseCatal
"""
self
.
request
.
user
=
self
.
user
self
.
mock_enrollment_api_error
(
self
.
request
,
self
.
user
,
self
.
course
.
id
,
error
)
url
=
'{path}?sku={sku}'
.
format
(
path
=
self
.
path
,
sku
=
self
.
stock_record
.
partner_sku
)
self
.
create_coupon
(
catalog
=
self
.
catalog
,
code
=
COUPON_CODE
,
benefit_value
=
5
)
url
=
'{path}?sku={sku}&code={code}'
.
format
(
path
=
self
.
path
,
sku
=
self
.
stock_record
.
partner_sku
,
code
=
COUPON_CODE
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
400
)
...
...
ecommerce/extensions/basket/views.py
View file @
39d170e4
...
...
@@ -62,9 +62,10 @@ class BasketSingleItemView(View):
msg
=
_
(
'Product [{product}] not available to buy.'
)
.
format
(
product
=
product
.
title
)
return
HttpResponseBadRequest
(
msg
)
# If the product is not an Enrollment Code, we check to see if the user is already
# enrolled to prevent double-enrollment and/or accidental coupon usage
if
not
product
.
is_enrollment_code_product
:
# If the product is not an Enrollment Code and this is a Coupon Redemption request,
# we check to see if the user is already enrolled
# to prevent double-enrollment and/or accidental coupon usage.
if
not
product
.
is_enrollment_code_product
and
code
:
try
:
if
request
.
user
.
is_user_already_enrolled
(
request
,
product
):
logger
.
warning
(
...
...
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