test_api.py 7.74 KB
Newer Older
1 2
# encoding: utf-8
"""Tests of Branding API """
3
from __future__ import unicode_literals
4 5

import mock
6
from django.core.urlresolvers import reverse
7
from django.test import TestCase
8
from django.test.utils import override_settings
9

10 11
from branding.api import get_footer, get_home_url, get_logo_url
from edxmako.shortcuts import marketing_link
12

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

class TestHeader(TestCase):
    """Test API end-point for retrieving the header. """

    def test_cdn_urls_for_logo(self):
        # Ordinarily, we'd use `override_settings()` to override STATIC_URL,
        # which is what the staticfiles storage backend is using to construct the URL.
        # Unfortunately, other parts of the system are caching this value on module
        # load, which can cause other tests to fail.  To ensure that this change
        # doesn't affect other tests, we patch the `url()` method directly instead.
        cdn_url = "http://cdn.example.com/static/image.png"
        with mock.patch('branding.api.staticfiles_storage.url', return_value=cdn_url):
            logo_url = get_logo_url()

        self.assertEqual(logo_url, cdn_url)
28

29 30 31 32 33 34 35 36 37 38 39 40
    def test_home_url_with_mktg_disabled(self):
        expected_url = get_home_url()
        self.assertEqual(reverse('dashboard'), expected_url)

    @mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True})
    @mock.patch.dict('django.conf.settings.MKTG_URLS', {
        "ROOT": "https://edx.org",
    })
    def test_home_url_with_mktg_enabled(self):
        expected_url = get_home_url()
        self.assertEqual(marketing_link('ROOT'), expected_url)

41 42 43 44 45 46 47 48 49

class TestFooter(TestCase):
    """Test retrieving the footer. """
    @mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_MKTG_SITE': True})
    @mock.patch.dict('django.conf.settings.MKTG_URLS', {
        "ROOT": "https://edx.org",
        "ABOUT": "/about-us",
        "NEWS": "/news-announcements",
        "CONTACT": "/contact",
50
        "CAREERS": '/careers',
51 52 53 54 55 56 57 58
        "FAQ": "/student-faq",
        "BLOG": "/edx-blog",
        "DONATE": "/donate",
        "JOBS": "/jobs",
        "SITE_MAP": "/sitemap",
        "TOS_AND_HONOR": "/edx-terms-service",
        "PRIVACY": "/edx-privacy-policy",
        "ACCESSIBILITY": "/accessibility",
59
        "AFFILIATES": '/affiliates',
60 61
        "MEDIA_KIT": "/media-kit",
        "ENTERPRISE": "/enterprise"
62
    })
63
    @override_settings(PLATFORM_NAME='\xe9dX')
64 65
    def test_get_footer(self):
        actual_footer = get_footer(is_secure=True)
66 67 68
        import pprint
        pprint.pprint(actual_footer)
        print('******************************************!!!!!!!!!!!!!!!!!!!!!!!!!!!*******************************************')
69
        expected_footer = {
70 71 72
            'copyright': '\xa9 \xe9dX.  All rights reserved except where noted. '
                         ' EdX, Open edX and their respective logos are '
                         'trademarks or registered trademarks of edX Inc.',
73 74
            'navigation_links': [
                {'url': 'https://edx.org/about-us', 'name': 'about', 'title': 'About'},
75
                {'url': 'https://edx.org/enterprise', 'name': 'enterprise', 'title': '\xe9dX for Business'},
76 77 78 79
                {'url': 'https://edx.org/edx-blog', 'name': 'blog', 'title': 'Blog'},
                {'url': 'https://edx.org/news-announcements', 'name': 'news', 'title': 'News'},
                {'url': 'https://support.example.com', 'name': 'help-center', 'title': 'Help Center'},
                {'url': 'https://edx.org/contact', 'name': 'contact', 'title': 'Contact'},
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
                {'url': 'https://edx.org/careers', 'name': 'careers', 'title': 'Careers'},
                {'url': 'https://edx.org/donate', 'name': 'donate', 'title': 'Donate'}
            ],
            'business_links': [
                {'url': 'https://edx.org/about-us', 'name': 'about', 'title': 'About'},
                {'url': 'https://edx.org/enterprise', 'name': 'enterprise', 'title': '\xe9dX for Business'},
                {'url': 'https://edx.org/affiliates', 'name': 'affiliates', 'title': 'Affiliates'},
                {'url': 'http://open.edx.org', 'name': 'openedx', 'title': 'Open edX'},
                {'url': 'https://edx.org/careers', 'name': 'careers', 'title': 'Careers'},
                {'url': 'https://edx.org/news-announcements', 'name': 'news', 'title': 'News'},

            ],
            'more_info_links': [
                {'url': 'https://edx.org/edx-terms-service',
                 'name': 'terms_of_service_and_honor_code',
                 'title': 'Terms of Service & Honor Code'},
                {'url': 'https://edx.org/edx-privacy-policy', 'name': 'privacy_policy', 'title': 'Privacy Policy'},
                {'url': 'https://edx.org/accessibility',
                 'name': 'accessibility_policy',
                 'title': 'Accessibility Policy'},
                {'url': 'https://edx.org/sitemap', 'name': 'sitemap', 'title': 'Sitemap'},

            ],
            'connect_links': [
                {'url': 'https://edx.org/edx-blog', 'name': 'blog', 'title': 'Blog'},
                {'url': 'https://edx.org/contact', 'name': 'contact', 'title': 'Contact Us'},
                {'url': 'https://support.example.com', 'name': 'help-center', 'title': 'Help Center'},
                {'url': 'https://edx.org/media-kit', 'name': 'media_kit', 'title': 'Media Kit'},
108
                {'url': 'https://edx.org/donate', 'name': 'donate', 'title': 'Donate'}
109 110 111 112 113 114 115 116 117
            ],
            'legal_links': [
                {'url': 'https://edx.org/edx-terms-service',
                 'name': 'terms_of_service_and_honor_code',
                 'title': 'Terms of Service & Honor Code'},
                {'url': 'https://edx.org/edx-privacy-policy', 'name': 'privacy_policy', 'title': 'Privacy Policy'},
                {'url': 'https://edx.org/accessibility',
                 'name': 'accessibility_policy',
                 'title': 'Accessibility Policy'},
118
                {'url': 'https://edx.org/sitemap', 'name': 'sitemap', 'title': 'Sitemap'},
119 120 121
                {'name': 'media_kit',
                 'title': u'Media Kit',
                 'url': u'https://edx.org/media-kit'}
122 123 124 125 126
            ],
            'social_links': [
                {'url': '#', 'action': 'Like \xe9dX on Facebook', 'name': 'facebook',
                 'icon-class': 'fa-facebook-square', 'title': 'Facebook'},
                {'url': '#', 'action': 'Follow \xe9dX on Twitter', 'name': 'twitter',
127
                 'icon-class': 'fa-twitter-square', 'title': 'Twitter'},
128
                {'url': '#', 'action': 'Subscribe to the \xe9dX YouTube channel',
129
                 'name': 'youtube', 'icon-class': 'fa-youtube-square', 'title': 'Youtube'},
130 131 132 133 134
                {'url': '#', 'action': 'Follow \xe9dX on LinkedIn', 'name': 'linkedin',
                 'icon-class': 'fa-linkedin-square', 'title': 'LinkedIn'},
                {'url': '#', 'action': 'Follow \xe9dX on Google+', 'name': 'google_plus',
                 'icon-class': 'fa-google-plus-square', 'title': 'Google+'},
                {'url': '#', 'action': 'Subscribe to the \xe9dX subreddit',
135
                 'name': 'reddit', 'icon-class': 'fa-reddit-square', 'title': 'Reddit'}
136 137 138 139 140 141 142
            ],
            'mobile_links': [],
            'logo_image': 'https://edx.org/static/images/logo.png',
            'openedx_link': {
                'url': 'http://open.edx.org',
                'image': 'https://files.edx.org/openedx-logos/edx-openedx-logo-tag.png',
                'title': 'Powered by Open edX'
143 144 145 146 147
            },
            'edx_org_link': {
                'url': 'https://www.edx.org/?utm_medium=affiliate_partner&utm_source=opensource-partner&utm_content=open-edx-partner-footer-link&utm_campaign=open-edx-footer',
                'text': 'Take free online courses at edX.org',
            },
148
        }
149
        pprint.pprint(expected_footer)
150
        self.assertEqual(actual_footer, expected_footer)