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
74c8bf40
Commit
74c8bf40
authored
May 10, 2016
by
Peter Fogg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add acceptance tests for affiliate cookie tracking.
ECOM-4329
parent
7b9e15f5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
+92
-0
acceptance_tests/affiliate_cookie_tests.py
+84
-0
acceptance_tests/config.py
+7
-0
requirements/test.txt
+1
-0
No files found.
acceptance_tests/affiliate_cookie_tests.py
0 → 100644
View file @
74c8bf40
"""
Tests for affiliate tracking cookies.
"""
from
unittest
import
TestCase
from
selenium
import
webdriver
from
acceptance_tests.config
import
(
BASIC_AUTH_USERNAME
,
BASIC_AUTH_PASSWORD
,
ECOMMERCE_URL_ROOT
,
MARKETING_SITE_URL_ROOT
,
LMS_URL_ROOT
)
def
_with_basic_auth
(
url
):
"""
If basic auth parameters have been provided, return the given URL
with auth added. Otherwise, just returns the URL unchanged.
"""
if
BASIC_AUTH_USERNAME
and
BASIC_AUTH_PASSWORD
:
return
url
.
replace
(
'://'
,
'://{username}:{password}@'
.
format
(
username
=
BASIC_AUTH_USERNAME
,
password
=
BASIC_AUTH_PASSWORD
))
return
url
class
AffiliateCookieTestMixin
(
object
):
"""
Test mixin for affiliate tracking cookies. Classes inheriting from
this should also inherit from TestCase and define a `url` property
which will be used to test cookie tracking.
"""
cookie_name
=
"affiliate_id"
cookie_value
=
"test_partner"
def
setUp
(
self
):
super
()
.
setUp
()
self
.
browser
=
webdriver
.
Firefox
()
def
tearDown
(
self
):
super
()
.
tearDown
()
self
.
browser
.
quit
()
def
test_without_query
(
self
):
"""Verify that no cookie is set without affiliate query parameters."""
self
.
browser
.
get
(
self
.
url
)
self
.
assertIsNone
(
self
.
browser
.
get_cookie
(
self
.
cookie_name
))
def
test_with_query
(
self
):
"""Verify that GTM drops a cookie when the correct query parameters are present."""
self
.
browser
.
get
(
'{root}?utm_source={partner}&utm_medium=affiliate_partner'
.
format
(
root
=
self
.
url
,
partner
=
self
.
cookie_value
)
)
cookie
=
self
.
browser
.
get_cookie
(
self
.
cookie_name
)
self
.
assertIsNotNone
(
cookie
)
self
.
assertEqual
(
cookie
[
'value'
],
self
.
cookie_value
)
def
test_with_query_wrong_medium
(
self
):
"""Verify that requests without utm_medium=affiliate_partner do not get a cookie."""
self
.
browser
.
get
(
'{root}?utm_source={partner}&utm_medium=nope'
.
format
(
root
=
self
.
url
,
partner
=
self
.
cookie_value
))
self
.
assertIsNone
(
self
.
browser
.
get_cookie
(
self
.
cookie_name
))
class
MarketingSiteCookieTest
(
AffiliateCookieTestMixin
,
TestCase
):
"""Cookie tests for the marketing site."""
url
=
MARKETING_SITE_URL_ROOT
class
LmsCookieTest
(
AffiliateCookieTestMixin
,
TestCase
):
"""Cookie tests for the LMS."""
url
=
_with_basic_auth
(
LMS_URL_ROOT
+
'/login'
)
class
EcommerceCookieTest
(
AffiliateCookieTestMixin
,
TestCase
):
"""Cookie tests for ecommerce."""
url
=
ECOMMERCE_URL_ROOT
+
'/basket/'
acceptance_tests/config.py
View file @
74c8bf40
...
...
@@ -11,3 +11,10 @@ if not API_ACCESS_TOKEN:
CATALOG_ID
=
int
(
os
.
environ
.
get
(
'CATALOG_ID'
,
1
))
COURSE_ID
=
os
.
environ
.
get
(
'COURSE_ID'
,
'edX/DemoX'
)
COURSE_RUN_ID
=
os
.
environ
.
get
(
'COURSE_RUN_ID'
,
'course-v1:edX+DemoX+Demo_Course'
)
MARKETING_SITE_URL_ROOT
=
os
.
environ
.
get
(
'MARKETING_SITE_URL_ROOT'
,
'https://stage.edx.org'
)
LMS_URL_ROOT
=
os
.
environ
.
get
(
'LMS_URL_ROOT'
,
'https://courses.stage.edx.org'
)
ECOMMERCE_URL_ROOT
=
os
.
environ
.
get
(
'ECOMMERCE_URL_ROOT'
,
'https://ecommerce.stage.edx.org'
)
BASIC_AUTH_USERNAME
=
os
.
environ
.
get
(
'BASIC_AUTH_USERNAME'
,
''
)
BASIC_AUTH_PASSWORD
=
os
.
environ
.
get
(
'BASIC_AUTH_PASSWORD'
,
''
)
requirements/test.txt
View file @
74c8bf40
...
...
@@ -11,4 +11,5 @@ mock==1.3.0
nose-ignore-docstring==0.2
pep8==1.6.2
responses==0.5.0
selenium==2.53.2
testfixtures==4.7.0
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