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
1d1952c8
Commit
1d1952c8
authored
Sep 22, 2016
by
Douglas Hall
Committed by
Douglas Hall
Sep 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added SiteMixin for tests that need to test Site specific functionality
parent
8f6182aa
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
21 deletions
+106
-21
common/djangoapps/edxmako/tests.py
+0
-1
lms/djangoapps/branding/tests/test_views.py
+41
-0
lms/djangoapps/shoppingcart/tests/test_configuration_overrides.py
+6
-20
openedx/core/djangoapps/site_configuration/tests/factories.py
+12
-0
openedx/core/djangoapps/site_configuration/tests/mixins.py
+47
-0
No files found.
common/djangoapps/edxmako/tests.py
View file @
1d1952c8
from
mock
import
patch
,
Mock
import
unittest
import
ddt
...
...
lms/djangoapps/branding/tests/test_views.py
View file @
1d1952c8
...
...
@@ -10,7 +10,9 @@ import mock
import
ddt
from
config_models.models
import
cache
from
branding.models
import
BrandingApiConfig
from
openedx.core.djangoapps.site_configuration.tests.mixins
import
SiteMixin
from
openedx.core.djangoapps.theming.tests.test_util
import
with_comprehensive_theme_context
from
student.tests.factories
import
UserFactory
@ddt.ddt
...
...
@@ -227,3 +229,42 @@ class TestFooter(TestCase):
)
return
self
.
client
.
get
(
url
,
HTTP_ACCEPT
=
accepts
)
class
TestIndex
(
SiteMixin
,
TestCase
):
""" Test the index view """
def
setUp
(
self
):
""" Set up a user """
super
(
TestIndex
,
self
)
.
setUp
()
patcher
=
mock
.
patch
(
"student.models.tracker"
)
self
.
mock_tracker
=
patcher
.
start
()
self
.
user
=
UserFactory
.
create
()
self
.
user
.
set_password
(
"password"
)
self
.
user
.
save
()
def
test_index_does_not_redirect_without_site_override
(
self
):
""" Test index view does not redirect if MKTG_URLS['ROOT'] is not set """
response
=
self
.
client
.
get
(
reverse
(
"root"
))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_index_redirects_to_marketing_site_with_site_override
(
self
):
""" Test index view redirects if MKTG_URLS['ROOT'] is set in SiteConfiguration """
self
.
use_site
(
self
.
site_other
)
response
=
self
.
client
.
get
(
reverse
(
"root"
))
self
.
assertRedirects
(
response
,
self
.
site_configuration_other
.
values
[
"MKTG_URLS"
][
"ROOT"
],
fetch_redirect_response
=
False
)
def
test_header_logo_links_to_marketing_site_with_site_override
(
self
):
"""
Test marketing site root link is included on dashboard page
if MKTG_URLS['ROOT'] is set in SiteConfiguration
"""
self
.
use_site
(
self
.
site_other
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"password"
)
response
=
self
.
client
.
get
(
reverse
(
"dashboard"
))
self
.
assertIn
(
self
.
site_configuration_other
.
values
[
"MKTG_URLS"
][
"ROOT"
],
response
.
content
)
lms/djangoapps/shoppingcart/tests/test_configuration_overrides.py
View file @
1d1952c8
...
...
@@ -2,8 +2,6 @@
"""
Dashboard with Shopping Cart History tests with configuration overrides.
"""
import
mock
from
django.core.urlresolvers
import
reverse
from
mock
import
patch
...
...
@@ -15,24 +13,11 @@ from shoppingcart.models import (
)
from
student.tests.factories
import
UserFactory
from
course_modes.models
import
CourseMode
def
fake_all_orgs
(
default
=
None
):
# pylint: disable=unused-argument
"""
Method to return fake orgs,
"""
return
set
([
'fakeX'
,
'fooX'
])
def
fake_site
(
name
,
default
=
None
):
# pylint: disable=unused-argument
"""
Method to return a fake site name.
"""
return
'fakeX'
from
openedx.core.djangoapps.site_configuration.tests.mixins
import
SiteMixin
@patch.dict
(
'django.conf.settings.FEATURES'
,
{
'ENABLE_PAID_COURSE_REGISTRATION'
:
True
})
class
TestOrderHistoryOnSiteDashboard
(
ModuleStoreTestCase
):
class
TestOrderHistoryOnSiteDashboard
(
SiteMixin
,
ModuleStoreTestCase
):
"""
Test for dashboard order history site configuration overrides.
"""
...
...
@@ -76,7 +61,7 @@ class TestOrderHistoryOnSiteDashboard(ModuleStoreTestCase):
self
.
foox_site_order_id
=
cart
.
id
# Third Order with course not attributed to any site.
course3
=
CourseFactory
.
create
(
org
=
'
otherorg'
,
number
=
'777'
,
display_name
=
'otherorg
Course'
)
course3
=
CourseFactory
.
create
(
org
=
'
fakeOtherX'
,
number
=
'777'
,
display_name
=
'fakeOtherX
Course'
)
course3_key
=
course3
.
id
course3_mode
=
CourseMode
(
course_id
=
course3
.
id
,
mode_slug
=
"honor"
,
...
...
@@ -90,7 +75,7 @@ class TestOrderHistoryOnSiteDashboard(ModuleStoreTestCase):
self
.
order_id
=
cart
.
id
# Fourth Order with course not attributed to any site but with a CertificateItem
course4
=
CourseFactory
.
create
(
org
=
'
otherorg
'
,
number
=
'888'
)
course4
=
CourseFactory
.
create
(
org
=
'
fakeOtherX
'
,
number
=
'888'
)
course4_key
=
course4
.
id
course4_mode
=
CourseMode
(
course_id
=
course4
.
id
,
mode_slug
=
"verified"
,
...
...
@@ -104,7 +89,7 @@ class TestOrderHistoryOnSiteDashboard(ModuleStoreTestCase):
self
.
certificate_order_id
=
cart
.
id
# Fifth Order with course not attributed to any site but with a Donation
course5
=
CourseFactory
.
create
(
org
=
'
otherorg
'
,
number
=
'999'
)
course5
=
CourseFactory
.
create
(
org
=
'
fakeOtherX
'
,
number
=
'999'
)
course5_key
=
course5
.
id
cart
=
Order
.
get_cart_for_user
(
self
.
user
)
...
...
@@ -135,6 +120,7 @@ class TestOrderHistoryOnSiteDashboard(ModuleStoreTestCase):
self
.
assertNotIn
(
receipt_url_donation
,
content
)
def
test_shows_orders_with_non_site_courses_only_when_no_configuration_override_exists
(
self
):
self
.
use_site
(
self
.
site_other
)
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"password"
)
response
=
self
.
client
.
get
(
reverse
(
"dashboard"
))
receipt_url_course
=
reverse
(
'shoppingcart.views.show_receipt'
,
kwargs
=
{
'ordernum'
:
self
.
fakex_site_order_id
})
...
...
openedx/core/djangoapps/site_configuration/tests/factories.py
View file @
1d1952c8
"""
Model factories for unit testing views or models.
"""
from
django.contrib.sites.models
import
Site
from
factory.django
import
DjangoModelFactory
from
openedx.core.djangoapps.site_configuration.models
import
SiteConfiguration
...
...
@@ -15,3 +16,14 @@ class SiteConfigurationFactory(DjangoModelFactory):
values
=
{}
enabled
=
True
class
SiteFactory
(
DjangoModelFactory
):
"""
Factory class for Site model
"""
class
Meta
(
object
):
model
=
Site
domain
=
'testserver.fake'
name
=
'testserver.fake'
openedx/core/djangoapps/site_configuration/tests/mixins.py
0 → 100644
View file @
1d1952c8
"""
Mixins for TestCase classes that need to account for multiple sites
"""
from
openedx.core.djangoapps.site_configuration.tests.factories
import
SiteConfigurationFactory
,
SiteFactory
class
SiteMixin
(
object
):
"""
Mixin for setting up Site framework models
"""
def
setUp
(
self
):
super
(
SiteMixin
,
self
)
.
setUp
()
self
.
site
=
SiteFactory
.
create
()
self
.
site_configuration
=
SiteConfigurationFactory
.
create
(
site
=
self
.
site
,
values
=
{
"SITE_NAME"
:
self
.
site
.
domain
,
"course_org_filter"
:
"fakeX"
,
}
)
self
.
site_other
=
SiteFactory
.
create
(
domain
=
'testserver.fakeother'
,
name
=
'testserver.fakeother'
)
self
.
site_configuration_other
=
SiteConfigurationFactory
.
create
(
site
=
self
.
site_other
,
values
=
{
"SITE_NAME"
:
self
.
site_other
.
domain
,
"course_org_filter"
:
"fakeOtherX"
,
"ENABLE_MKTG_SITE"
:
True
,
"MKTG_URLS"
:
{
"ROOT"
:
"https://marketing.fakeother"
,
"ABOUT"
:
"/fake-about"
}
}
)
# Initialize client with default site domain
self
.
use_site
(
self
.
site
)
def
use_site
(
self
,
site
):
"""
# Initializes the test client with the domain of the given site
"""
self
.
client
=
self
.
client_class
(
SERVER_NAME
=
site
.
domain
)
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