Commit 4cfb8c90 by bmedx Committed by Brian Mesick

Add demo_course option to create_sites_and_partners

Used to support setting up whitelabel end-to-end courses in devstack.
parent 1d14c50c
""" This command creates Sites, SiteThemes, SiteConfigurations and partners.""" """ This command creates Sites, SiteThemes, SiteConfigurations and partners."""
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
import fnmatch import fnmatch
import json import json
import logging import logging
...@@ -8,11 +9,14 @@ import os ...@@ -8,11 +9,14 @@ import os
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core.management import BaseCommand from django.core.management import BaseCommand
from django.utils import timezone
from oscar.core.loading import get_model from oscar.core.loading import get_model
from ecommerce.core.models import SiteConfiguration from ecommerce.core.models import SiteConfiguration
from ecommerce.courses.models import Course
from ecommerce.theming.models import SiteTheme from ecommerce.theming.models import SiteTheme
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
Partner = get_model('partner', 'Partner') Partner = get_model('partner', 'Partner')
...@@ -46,9 +50,15 @@ class Command(BaseCommand): ...@@ -46,9 +50,15 @@ class Command(BaseCommand):
help="Use devstack config, otherwise sandbox config is assumed", help="Use devstack config, otherwise sandbox config is assumed",
) )
def _create_sites(self, site_domain, theme_dir_name, site_configuration, partner_code): parser.add_argument(
"--demo_course",
action='store_true',
help="Create a demo course for testing this partner, used for whitelabel tests",
)
def _create_sites(self, site_domain, theme_dir_name, site_configuration, partner_code, demo_course):
""" """
Create Sites, SiteThemes and SiteConfigurations Create Sites, SiteThemes, SiteConfigurations, and Courses (if requested)
""" """
site, _ = Site.objects.get_or_create( site, _ = Site.objects.get_or_create(
domain=site_domain, domain=site_domain,
...@@ -76,6 +86,23 @@ class Command(BaseCommand): ...@@ -76,6 +86,23 @@ class Command(BaseCommand):
defaults=site_configuration defaults=site_configuration
) )
if demo_course:
# Create the course, this is used in devstack whitelabel testing
course_id = 'course-v1:{}+DemoX+Demo_Course'.format(partner_code)
one_year = datetime.timedelta(days=365)
expires = timezone.now() + one_year
price = 159
course, __ = Course.objects.update_or_create(id=course_id, site=site, defaults={
'name': 'edX Demonstration Course',
'verification_deadline': expires + one_year,
})
# Create the audit and verified seats
course.create_or_update_seat('', False, 0, partner)
course.create_or_update_seat('verified', True, price, partner, expires=expires, create_enrollment_code=True)
logger.info('Created audit and verified seats for [%s]', course_id)
def find(self, pattern, path): def find(self, pattern, path):
""" """
Matched the given pattern in given path and returns the list of matching files Matched the given pattern in given path and returns the list of matching files
...@@ -131,5 +158,6 @@ class Command(BaseCommand): ...@@ -131,5 +158,6 @@ class Command(BaseCommand):
site_data['site_domain'], site_data['site_domain'],
site_data['theme_dir_name'], site_data['theme_dir_name'],
site_data['configuration'], site_data['configuration'],
site_data['partner_code'] site_data['partner_code'],
options['demo_course']
) )
...@@ -10,6 +10,7 @@ from django.test import TestCase ...@@ -10,6 +10,7 @@ from django.test import TestCase
from oscar.core.loading import get_model from oscar.core.loading import get_model
from ecommerce.core.models import SiteConfiguration from ecommerce.core.models import SiteConfiguration
from ecommerce.courses.models import Course
from ecommerce.theming.models import SiteTheme from ecommerce.theming.models import SiteTheme
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -118,6 +119,29 @@ class TestCreateSitesAndPartners(TestCase): ...@@ -118,6 +119,29 @@ class TestCreateSitesAndPartners(TestCase):
) )
self._assert_sites_data_is_valid() self._assert_sites_data_is_valid()
def test_create_devstack_site_and_partner_w_course(self):
"""
Verify that command creates sites and Partners
"""
call_command(
"create_sites_and_partners",
"--dns-name", self.dns_name,
"--theme-path", self.theme_path,
"--devstack", "--demo_course"
)
self._assert_sites_data_is_valid()
partners = Partner.objects.all()
for p in partners:
course_id = 'course-v1:{}+DemoX+Demo_Course'.format(p.short_code)
courses = Course.objects.filter(id=course_id)
# Check that the course exists
self.assertEqual(len(courses), 1)
# Check that the seat products exist
self.assertEqual(len(courses[0].seat_products), 2)
def test_create_site_and_partner(self): def test_create_site_and_partner(self):
""" """
Verify that command creates sites and Partners Verify that command creates sites and Partners
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment