Files
edx-platform/common/djangoapps/microsite_configuration/tests/test_microsites.py
Felipe Montoya 4742e661f4 Creating a settings object that is aware of the microsite settings.
Adding the declaration of the settings object to openedx.conf to be able to import it from a nicer location

Resolving quality violations

Merging dicts with the settings definition when they exist in the microsite configuration

Using a cache to improve the perfomance of quering any dictionary in the microsite definition

Ignoring the invalid-name pylint warning since the names must be kept thsi way to stay the same as the ones in django.
Removing the default dict argument as per https://docs.python.org/2/tutorial/controlflow.html#default-argument-values

Extracting the implementation of the microsite to a selectable backend.

Leaving the function startup.enable_microsites for backwards compatibilityy

Adding a database backend

Using a cache to improve the perfomance of quering any dictionary in the microsite definition.
Changed the database backend so that it extends the settings file backend and removed all the unnecessary methods.

Using the backend provider for the get_dict function

some tweeks and some initial unit tests

Using getattr as a function insteal of calling the underlying __getattr__ directly

Adding an ModelAdmin object for the microsite model in the django-admin panel

refactor enable_microsites()

consolidate/refactor some shared code

add config to aws.py and add migration files

fix tests

Changes to get the backends to run after the refactor

add archiving capabilities to microsites. Also make a few notes about performance improvements to make

fix tests

Making the query to find if microsites exist in the database faster

add ORG to microsite mapping tables and some performance improvements

allow for Mako templates to be pulled from the database

fix tests

For the database template backend the uri of the template does not use the filesystem relative path

Fixing pylint violations

Added caching of the templates stored in the database

Fixing pylint errors

fix pylint

Clearing the cache on model save

Fixing pylint errors

rebased and added test coverage

rebased cdodge/microsite-improvements branch with master and added test
coverage

added missing migration

fix quality violations

add more test coverage

mattdrayer: Add microsite_configuration to cms.INSTALLED_APPS

added microsite settings to cms/envs/test.py

run session cookie tests only in LMS

fixed broken tests

putting middleware changes back

Preventing the template_backend to be called on requests which have no microsite

changes to address feedback from mjfrey

changed BaseMicrositeBackend to AbstractBaseMicrositeBackend

changes after feedback from mattdrayer

fixed broken tests and quality violations

Allowing the backend to handle the enable_pre_startup routine

Typos and docstrings

Adressing feedback

Fixing python tests

add comment to explain why we need enable_microsites_pre_startup()
2016-01-15 14:52:36 +05:00

77 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
"""
Tests microsite_configuration templatetags and helper functions.
"""
from django.test import TestCase
from django.conf import settings
from microsite_configuration.templatetags import microsite as microsite_tags
from microsite_configuration import microsite
from microsite_configuration.backends.base import BaseMicrositeBackend
from microsite_configuration.backends.database import DatabaseMicrositeBackend
class MicrositeTests(TestCase):
"""
Make sure some of the helper functions work
"""
def test_breadcrumbs(self):
crumbs = ['my', 'less specific', 'Page']
expected = u'my | less specific | Page | edX'
title = microsite_tags.page_title_breadcrumbs(*crumbs)
self.assertEqual(expected, title)
def test_unicode_title(self):
crumbs = [u'øo', u'π tastes gréât', u'']
expected = u'øo | π tastes gréât | 驴 | edX'
title = microsite_tags.page_title_breadcrumbs(*crumbs)
self.assertEqual(expected, title)
def test_platform_name(self):
pname = microsite_tags.platform_name()
self.assertEqual(pname, settings.PLATFORM_NAME)
def test_breadcrumb_tag(self):
crumbs = ['my', 'less specific', 'Page']
expected = u'my | less specific | Page | edX'
title = microsite_tags.page_title_breadcrumbs_tag(None, *crumbs)
self.assertEqual(expected, title)
def test_microsite_template_path(self):
"""
When an unexistent path is passed to the filter, it should return the same path
"""
path = microsite_tags.microsite_template_path('footer.html')
self.assertEqual("footer.html", path)
def test_get_backend_raise_error_for_invalid_class(self):
"""
Test get_backend returns None for invalid paths
and raises TypeError when invalid class or class name is a method.
"""
# invalid backend path
self.assertEqual(microsite.get_backend(None, BaseMicrositeBackend), None)
# invalid class or class name is a method
with self.assertRaises(TypeError):
microsite.get_backend('microsite_configuration.microsite.get_backend', BaseMicrositeBackend)
def test_get_backend_raise_error_when_module_has_no_class(self):
"""
Test get_backend raises ValueError when module does not have a class.
"""
# module does not have a class
with self.assertRaises(ValueError):
microsite.get_backend('microsite_configuration.microsite.invalid_method', BaseMicrositeBackend)
def test_get_backend_for_valid_class(self):
"""
Test get_backend loads class if class exists.
"""
# load a valid class
self.assertIsInstance(
microsite.get_backend(
'microsite_configuration.backends.database.DatabaseMicrositeBackend', BaseMicrositeBackend
),
DatabaseMicrositeBackend
)