Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
b0885bd4
Commit
b0885bd4
authored
Sep 08, 2016
by
PaulWattenberger
Committed by
GitHub
Sep 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13409 from edx/pwattenberger/sailthru_campaign_id
Pass Sailthru campaign id cookie to ecommerce
parents
05c8fa82
7ec89829
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
lms/djangoapps/commerce/api/v0/tests/test_views.py
+7
-0
lms/djangoapps/commerce/api/v0/views.py
+13
-1
openedx/core/djangoapps/commerce/utils.py
+3
-2
No files found.
lms/djangoapps/commerce/api/v0/tests/test_views.py
View file @
b0885bd4
...
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta
...
@@ -3,6 +3,7 @@ from datetime import datetime, timedelta
import
json
import
json
import
itertools
import
itertools
from
uuid
import
uuid4
from
uuid
import
uuid4
import
httpretty
import
ddt
import
ddt
from
django.conf
import
settings
from
django.conf
import
settings
...
@@ -28,6 +29,7 @@ from student.models import CourseEnrollment
...
@@ -28,6 +29,7 @@ from student.models import CourseEnrollment
from
student.tests.factories
import
CourseModeFactory
from
student.tests.factories
import
CourseModeFactory
from
student.tests.tests
import
EnrollmentEventTestMixin
from
student.tests.tests
import
EnrollmentEventTestMixin
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
commerce.api.v0.views
import
SAILTHRU_CAMPAIGN_COOKIE
@attr
(
shard
=
1
)
@attr
(
shard
=
1
)
...
@@ -51,6 +53,8 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
...
@@ -51,6 +53,8 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
}
}
if
marketing_email_opt_in
:
if
marketing_email_opt_in
:
payload
[
"email_opt_in"
]
=
True
payload
[
"email_opt_in"
]
=
True
self
.
client
.
cookies
[
SAILTHRU_CAMPAIGN_COOKIE
]
=
'sailthru id'
return
self
.
client
.
post
(
self
.
url
,
payload
)
return
self
.
client
.
post
(
self
.
url
,
payload
)
def
assertResponseMessage
(
self
,
response
,
expected_msg
):
def
assertResponseMessage
(
self
,
response
,
expected_msg
):
...
@@ -173,6 +177,9 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
...
@@ -173,6 +177,9 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
else
:
else
:
self
.
assertResponsePaymentData
(
response
)
self
.
assertResponsePaymentData
(
response
)
# make sure ecommerce API call forwards Sailthru cookie
self
.
assertIn
(
'{}=sailthru id'
.
format
(
SAILTHRU_CAMPAIGN_COOKIE
),
httpretty
.
last_request
()
.
headers
[
'cookie'
])
@ddt.data
(
True
,
False
)
@ddt.data
(
True
,
False
)
def
test_course_with_honor_seat_sku
(
self
,
user_is_active
):
def
test_course_with_honor_seat_sku
(
self
,
user_is_active
):
"""
"""
...
...
lms/djangoapps/commerce/api/v0/views.py
View file @
b0885bd4
""" API v0 views. """
""" API v0 views. """
import
logging
import
logging
import
requests
from
edx_rest_api_client
import
exceptions
from
edx_rest_api_client
import
exceptions
from
opaque_keys
import
InvalidKeyError
from
opaque_keys
import
InvalidKeyError
...
@@ -26,6 +27,7 @@ from util.json_request import JsonResponse
...
@@ -26,6 +27,7 @@ from util.json_request import JsonResponse
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
SAILTHRU_CAMPAIGN_COOKIE
=
'sailthru_bid'
class
BasketsView
(
APIView
):
class
BasketsView
(
APIView
):
...
@@ -135,7 +137,8 @@ class BasketsView(APIView):
...
@@ -135,7 +137,8 @@ class BasketsView(APIView):
# Setup the API
# Setup the API
try
:
try
:
api
=
ecommerce_api_client
(
user
)
api_session
=
requests
.
Session
()
api
=
ecommerce_api_client
(
user
,
session
=
api_session
)
except
ValueError
:
except
ValueError
:
self
.
_enroll
(
course_key
,
user
)
self
.
_enroll
(
course_key
,
user
)
msg
=
Messages
.
NO_ECOM_API
.
format
(
username
=
user
.
username
,
course_id
=
unicode
(
course_key
))
msg
=
Messages
.
NO_ECOM_API
.
format
(
username
=
user
.
username
,
course_id
=
unicode
(
course_key
))
...
@@ -146,6 +149,15 @@ class BasketsView(APIView):
...
@@ -146,6 +149,15 @@ class BasketsView(APIView):
# Make the API call
# Make the API call
try
:
try
:
# Pass along Sailthru campaign id
campaign_cookie
=
request
.
COOKIES
.
get
(
SAILTHRU_CAMPAIGN_COOKIE
)
if
campaign_cookie
:
cookie
=
{
SAILTHRU_CAMPAIGN_COOKIE
:
campaign_cookie
}
if
api_session
.
cookies
:
requests
.
utils
.
add_dict_to_cookiejar
(
api_session
.
cookies
,
cookie
)
else
:
api_session
.
cookies
=
requests
.
utils
.
cookiejar_from_dict
(
cookie
)
response_data
=
api
.
baskets
.
post
({
response_data
=
api
.
baskets
.
post
({
'products'
:
[{
'sku'
:
default_enrollment_mode
.
sku
}],
'products'
:
[{
'sku'
:
default_enrollment_mode
.
sku
}],
'checkout'
:
True
,
'checkout'
:
True
,
...
...
openedx/core/djangoapps/commerce/utils.py
View file @
b0885bd4
...
@@ -32,7 +32,7 @@ def is_commerce_service_configured():
...
@@ -32,7 +32,7 @@ def is_commerce_service_configured():
return
bool
(
ecommerce_api_url
and
ecommerce_api_signing_key
)
return
bool
(
ecommerce_api_url
and
ecommerce_api_signing_key
)
def
ecommerce_api_client
(
user
):
def
ecommerce_api_client
(
user
,
session
=
None
):
""" Returns an E-Commerce API client setup with authentication for the specified user. """
""" Returns an E-Commerce API client setup with authentication for the specified user. """
jwt_auth
=
configuration_helpers
.
get_value
(
"JWT_AUTH"
,
settings
.
JWT_AUTH
)
jwt_auth
=
configuration_helpers
.
get_value
(
"JWT_AUTH"
,
settings
.
JWT_AUTH
)
return
EdxRestApiClient
(
return
EdxRestApiClient
(
...
@@ -43,5 +43,6 @@ def ecommerce_api_client(user):
...
@@ -43,5 +43,6 @@ def ecommerce_api_client(user):
user
.
email
,
user
.
email
,
tracking_context
=
create_tracking_context
(
user
),
tracking_context
=
create_tracking_context
(
user
),
issuer
=
jwt_auth
[
'JWT_ISSUER'
],
issuer
=
jwt_auth
[
'JWT_ISSUER'
],
expires_in
=
jwt_auth
[
'JWT_EXPIRATION'
]
expires_in
=
jwt_auth
[
'JWT_EXPIRATION'
],
session
=
session
)
)
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