Make end-to-end tests work again
* NOTE: successfully running the tests depends on an updated version of
django-pipeline, which fixes a unicode bug (efaba4ac63)
Config changes:
* Use separate db for the cms
* Run collectstatic before running tests--needed to get everything in the right place for loading pages
* fix some paths related to this
* Turn off JS compressor for CMS
* add empty test_root/uploads dir
Code changes:
* Add cms tests to check that home page and signup pages load
* Add cms account creation test
* Make github sync tests clean out repo dirs before running.
This commit is contained in:
@@ -1,16 +0,0 @@
|
|||||||
"""
|
|
||||||
This file demonstrates writing tests using the unittest module. These will pass
|
|
||||||
when you run "manage.py test".
|
|
||||||
|
|
||||||
Replace this with more appropriate tests for your application.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleTest(TestCase):
|
|
||||||
def test_basic_addition(self):
|
|
||||||
"""
|
|
||||||
Tests that 1 + 1 always equals 2.
|
|
||||||
"""
|
|
||||||
self.assertEqual(1 + 1, 2)
|
|
||||||
1
cms/djangoapps/contentstore/tests/__init__.py
Normal file
1
cms/djangoapps/contentstore/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
48
cms/djangoapps/contentstore/tests/tests.py
Normal file
48
cms/djangoapps/contentstore/tests/tests.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import json
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.test import TestCase
|
||||||
|
from mock import patch, Mock
|
||||||
|
from override_settings import override_settings
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
def parse_json(response):
|
||||||
|
"""Parse response, which is assumed to be json"""
|
||||||
|
return json.loads(response.content)
|
||||||
|
|
||||||
|
class AuthTestCase(TestCase):
|
||||||
|
"""Check that various permissions-related things work"""
|
||||||
|
|
||||||
|
def test_index(self):
|
||||||
|
"""Make sure the main page loads."""
|
||||||
|
resp = self.client.get('/')
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
||||||
|
def test_signup_load(self):
|
||||||
|
"""Make sure the signup page loads."""
|
||||||
|
resp = self.client.get('/signup')
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_account(self):
|
||||||
|
|
||||||
|
# No post data -- should fail
|
||||||
|
resp = self.client.post('/create_account', {})
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
data = parse_json(resp)
|
||||||
|
self.assertEqual(data['success'], False)
|
||||||
|
|
||||||
|
# Should work
|
||||||
|
resp = self.client.post('/create_account', {
|
||||||
|
'username': 'user',
|
||||||
|
'email': 'a@b.com',
|
||||||
|
'password': 'xyz',
|
||||||
|
'location' : 'home',
|
||||||
|
'language' : 'Franglish',
|
||||||
|
'name' : 'Fred Weasley',
|
||||||
|
'terms_of_service' : 'true',
|
||||||
|
'honor_code' : 'true'})
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
data = parse_json(resp)
|
||||||
|
self.assertEqual(data['success'], True)
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from path import path
|
from path import path
|
||||||
import shutil
|
import shutil
|
||||||
|
import os
|
||||||
from github_sync import import_from_github, export_to_github
|
from github_sync import import_from_github, export_to_github
|
||||||
from git import Repo
|
from git import Repo
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -13,10 +14,18 @@ from github_sync.exceptions import GithubSyncError
|
|||||||
@override_settings(DATA_DIR=path('test_root'))
|
@override_settings(DATA_DIR=path('test_root'))
|
||||||
class GithubSyncTestCase(TestCase):
|
class GithubSyncTestCase(TestCase):
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
shutil.rmtree(self.repo_dir, ignore_errors=True)
|
||||||
|
shutil.rmtree(self.remote_dir, ignore_errors=True)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.working_dir = path(settings.TEST_ROOT)
|
self.working_dir = path(settings.TEST_ROOT)
|
||||||
self.repo_dir = self.working_dir / 'local_repo'
|
self.repo_dir = self.working_dir / 'local_repo'
|
||||||
self.remote_dir = self.working_dir / 'remote_repo'
|
self.remote_dir = self.working_dir / 'remote_repo'
|
||||||
|
|
||||||
|
# make sure there's no stale data lying around
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
shutil.copytree('common/test/data/toy', self.remote_dir)
|
shutil.copytree('common/test/data/toy', self.remote_dir)
|
||||||
|
|
||||||
remote = Repo.init(self.remote_dir)
|
remote = Repo.init(self.remote_dir)
|
||||||
@@ -33,8 +42,7 @@ class GithubSyncTestCase(TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.repo_dir)
|
self.cleanup()
|
||||||
shutil.rmtree(self.remote_dir)
|
|
||||||
|
|
||||||
def test_initialize_repo(self):
|
def test_initialize_repo(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ PIPELINE_COMPILERS = [
|
|||||||
PIPELINE_SASS_ARGUMENTS = '-t compressed -r {proj_dir}/static/sass/bourbon/lib/bourbon.rb'.format(proj_dir=PROJECT_ROOT)
|
PIPELINE_SASS_ARGUMENTS = '-t compressed -r {proj_dir}/static/sass/bourbon/lib/bourbon.rb'.format(proj_dir=PROJECT_ROOT)
|
||||||
|
|
||||||
PIPELINE_CSS_COMPRESSOR = None
|
PIPELINE_CSS_COMPRESSOR = None
|
||||||
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yui.YUICompressor'
|
PIPELINE_JS_COMPRESSOR = None
|
||||||
|
|
||||||
STATICFILES_IGNORE_PATTERNS = (
|
STATICFILES_IGNORE_PATTERNS = (
|
||||||
"sass/*",
|
"sass/*",
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ sessions. Assumes structure:
|
|||||||
"""
|
"""
|
||||||
from .common import *
|
from .common import *
|
||||||
import os
|
import os
|
||||||
|
from path import path
|
||||||
|
|
||||||
|
|
||||||
# Nose Test Runner
|
# Nose Test Runner
|
||||||
INSTALLED_APPS += ('django_nose',)
|
INSTALLED_APPS += ('django_nose',)
|
||||||
@@ -17,7 +19,11 @@ for app in os.listdir(PROJECT_ROOT / 'djangoapps'):
|
|||||||
NOSE_ARGS += ['--cover-package', app]
|
NOSE_ARGS += ['--cover-package', app]
|
||||||
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
|
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
|
||||||
|
|
||||||
TEST_ROOT = 'test_root'
|
TEST_ROOT = path('test_root')
|
||||||
|
|
||||||
|
# Want static files in the same dir for running on jenkins.
|
||||||
|
STATIC_ROOT = TEST_ROOT / "staticfiles"
|
||||||
|
|
||||||
|
|
||||||
MODULESTORE = {
|
MODULESTORE = {
|
||||||
'default': {
|
'default': {
|
||||||
@@ -34,7 +40,7 @@ MODULESTORE = {
|
|||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
'NAME': ENV_ROOT / "db" / "mitx.db",
|
'NAME': ENV_ROOT / "db" / "cms.db",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,50 +6,50 @@
|
|||||||
|
|
||||||
.videosequence a:first-child {
|
.videosequence a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/videosequence.png');
|
background-image: url('../img/content-types/videosequence.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.video a:first-child {
|
.video a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/video.png');
|
background-image: url('../img/content-types/video.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.problemset a:first-child {
|
.problemset a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/problemset.png');
|
background-image: url('../img/content-types/problemset.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.problem a:first-child {
|
.problem a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/problem.png');
|
background-image: url('../img/content-types/problem.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.lab a:first-child {
|
.lab a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/lab.png');
|
background-image: url('../img/content-types/lab.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab a:first-child {
|
.tab a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/lab.png');
|
background-image: url('../img/content-types/lab.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.html a:first-child {
|
.html a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/html.png');
|
background-image: url('../img/content-types/html.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.vertical a:first-child {
|
.vertical a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/vertical.png');
|
background-image: url('../img/content-types/vertical.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.sequential a:first-child {
|
.sequential a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/sequential.png');
|
background-image: url('../img/content-types/sequential.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
.chapter a:first-child {
|
.chapter a:first-child {
|
||||||
@extend .content-type;
|
@extend .content-type;
|
||||||
background-image: url('/static/img/content-types/chapter.png');
|
background-image: url('../img/content-types/chapter.png');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<script type="text/javascript" src="${static.url('js/vendor/underscore-min.js')}"></script>
|
<script type="text/javascript" src="${static.url('js/vendor/underscore-min.js')}"></script>
|
||||||
<script type="text/javascript" src="${static.url('js/vendor/backbone-min.js')}"></script>
|
<script type="text/javascript" src="${static.url('js/vendor/backbone-min.js')}"></script>
|
||||||
<script type="text/javascript" src="${static.url('js/vendor/markitup/jquery.markitup.js')}"></script>
|
<script type="text/javascript" src="${static.url('js/vendor/markitup/jquery.markitup.js')}"></script>
|
||||||
<script type="text/javascript" src="${static.url('js/vendor/markitup/sets/wiki/set.js"')}></script>
|
<script type="text/javascript" src="${static.url('js/vendor/markitup/sets/wiki/set.js')}"></script>
|
||||||
% if settings.MITX_FEATURES['USE_DJANGO_PIPELINE']:
|
% if settings.MITX_FEATURES['USE_DJANGO_PIPELINE']:
|
||||||
<%static:js group='main'/>
|
<%static:js group='main'/>
|
||||||
% else:
|
% else:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ sessions. Assumes structure:
|
|||||||
from .common import *
|
from .common import *
|
||||||
from .logsettings import get_logger_config
|
from .logsettings import get_logger_config
|
||||||
import os
|
import os
|
||||||
|
from path import path
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
app
|
app
|
||||||
@@ -28,6 +29,9 @@ TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
|
|||||||
|
|
||||||
# Local Directories
|
# Local Directories
|
||||||
TEST_ROOT = path("test_root")
|
TEST_ROOT = path("test_root")
|
||||||
|
# Want static files in the same dir for running on jenkins.
|
||||||
|
STATIC_ROOT = TEST_ROOT / "staticfiles"
|
||||||
|
|
||||||
COURSES_ROOT = TEST_ROOT / "data"
|
COURSES_ROOT = TEST_ROOT / "data"
|
||||||
DATA_DIR = COURSES_ROOT
|
DATA_DIR = COURSES_ROOT
|
||||||
MAKO_TEMPLATES['course'] = [DATA_DIR]
|
MAKO_TEMPLATES['course'] = [DATA_DIR]
|
||||||
@@ -77,7 +81,7 @@ SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd'
|
|||||||
|
|
||||||
############################ FILE UPLOADS (ASKBOT) #############################
|
############################ FILE UPLOADS (ASKBOT) #############################
|
||||||
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
|
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
|
||||||
MEDIA_ROOT = PROJECT_ROOT / "uploads"
|
MEDIA_ROOT = TEST_ROOT / "uploads"
|
||||||
MEDIA_URL = "/static/uploads/"
|
MEDIA_URL = "/static/uploads/"
|
||||||
STATICFILES_DIRS.append(("uploads", MEDIA_ROOT))
|
STATICFILES_DIRS.append(("uploads", MEDIA_ROOT))
|
||||||
FILE_UPLOAD_TEMP_DIR = PROJECT_ROOT / "uploads"
|
FILE_UPLOAD_TEMP_DIR = PROJECT_ROOT / "uploads"
|
||||||
|
|||||||
4
rakefile
4
rakefile
@@ -80,7 +80,7 @@ end
|
|||||||
|
|
||||||
# Per System tasks
|
# Per System tasks
|
||||||
desc "Run all django tests on our djangoapps for the #{system}"
|
desc "Run all django tests on our djangoapps for the #{system}"
|
||||||
task "test_#{system}" => [report_dir, :predjango] do
|
task "test_#{system}" => [report_dir, :predjango, "#{system}:collectstatic:test"] do
|
||||||
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
|
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
|
||||||
ENV['NOSE_COVER_HTML_DIR'] = File.join(report_dir, "cover")
|
ENV['NOSE_COVER_HTML_DIR'] = File.join(report_dir, "cover")
|
||||||
sh(django_admin(system, :test, 'test', *Dir["#{system}/djangoapps/*"].each))
|
sh(django_admin(system, :test, 'test', *Dir["#{system}/djangoapps/*"].each))
|
||||||
@@ -106,7 +106,7 @@ end
|
|||||||
|
|
||||||
desc "Run collectstatic in the specified environment"
|
desc "Run collectstatic in the specified environment"
|
||||||
task "#{system}:collectstatic:#{env}" => :predjango do
|
task "#{system}:collectstatic:#{env}" => :predjango do
|
||||||
sh("#{django_admin(system, env, 'collectstatic')}")
|
sh("#{django_admin(system, env, 'collectstatic', '--noinput')}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
0
test_root/uploads/.git-keep
Normal file
0
test_root/uploads/.git-keep
Normal file
Reference in New Issue
Block a user