Make tests pass when running on cms
This commit is contained in:
committed by
Matthew Mongeau
parent
2aa6193a00
commit
d8d22ea57b
@@ -1,61 +0,0 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.contrib.auth.models import User
|
||||
import contentstore.tasks
|
||||
|
||||
from pyftpdlib import ftpserver
|
||||
import os
|
||||
|
||||
class DjangoAuthorizer(object):
|
||||
def validate_authentication(self, username, password):
|
||||
try:
|
||||
u=User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return False
|
||||
# TODO: Check security groups
|
||||
return u.check_password(password)
|
||||
def has_user(self, username):
|
||||
print "????",username
|
||||
return True
|
||||
def has_perm(self, username, perm, path=None):
|
||||
print "!!!!!",username, perm, path
|
||||
return True
|
||||
def get_home_dir(self, username):
|
||||
d = "/tmp/ftp/"+username
|
||||
try:
|
||||
os.mkdir(d)
|
||||
except OSError:
|
||||
pass
|
||||
return "/tmp/ftp/"+username
|
||||
def get_perms(self, username):
|
||||
return 'elradfmw'
|
||||
def get_msg_login(self, username):
|
||||
return 'Hello'
|
||||
def get_msg_quit(self, username):
|
||||
return 'Goodbye'
|
||||
def __init__(self):
|
||||
pass
|
||||
def impersonate_user(self, username, password):
|
||||
pass
|
||||
def terminate_impersonation(self, username):
|
||||
pass
|
||||
|
||||
def on_upload(ftp_handler, filename):
|
||||
source = ftp_handler.remote_ip
|
||||
author = ftp_handler.username
|
||||
print filename, author, source
|
||||
# We pass on this for now:
|
||||
# contentstore.tasks.on_upload
|
||||
# It is a changing API, and it makes testing the FTP server slow.
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = \
|
||||
''' Run FTP server.'''
|
||||
def handle(self, *args, **options):
|
||||
authorizer = DjangoAuthorizer() #ftpserver.DummyAuthorizer()
|
||||
handler = ftpserver.FTPHandler
|
||||
handler.on_file_received = on_upload
|
||||
|
||||
handler.authorizer = authorizer
|
||||
address = ("127.0.0.1", 2121)
|
||||
ftpd = ftpserver.FTPServer(address, handler)
|
||||
ftpd.serve_forever()
|
||||
@@ -38,6 +38,6 @@ CACHES = {
|
||||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||
'KEY_PREFIX': 'general',
|
||||
'VERSION': 4,
|
||||
'KEY_FUNCTION': 'util.cache.memcache_safe_key',
|
||||
'KEY_FUNCTION': 'util.memcache.safe_key',
|
||||
}
|
||||
}
|
||||
|
||||
54
cms/envs/test.py
Normal file
54
cms/envs/test.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
This config file runs the simplest dev environment using sqlite, and db-based
|
||||
sessions. Assumes structure:
|
||||
|
||||
/envroot/
|
||||
/db # This is where it'll write the database file
|
||||
/mitx # The location of this repo
|
||||
/log # Where we're going to write log files
|
||||
"""
|
||||
from .common import *
|
||||
import os
|
||||
|
||||
# Nose Test Runner
|
||||
INSTALLED_APPS += ('django_nose',)
|
||||
NOSE_ARGS = ['--cover-erase', '--with-xunit', '--with-xcoverage', '--cover-html', '--cover-inclusive']
|
||||
for app in os.listdir(PROJECT_ROOT / 'djangoapps'):
|
||||
NOSE_ARGS += ['--cover-package', app]
|
||||
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
|
||||
|
||||
KEYSTORE = {
|
||||
'host': 'localhost',
|
||||
'db': 'mongo_base',
|
||||
'collection': 'key_store',
|
||||
}
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': ENV_ROOT / "db" / "mitx.db",
|
||||
}
|
||||
}
|
||||
|
||||
CACHES = {
|
||||
# This is the cache used for most things. Askbot will not work without a
|
||||
# functioning cache -- it relies on caching to load its settings in places.
|
||||
# In staging/prod envs, the sessions also live here.
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'mitx_loc_mem_cache',
|
||||
'KEY_FUNCTION': 'util.memcache.safe_key',
|
||||
},
|
||||
|
||||
# The general cache is what you get if you use our util.cache. It's used for
|
||||
# things like caching the course.xml file for different A/B test groups.
|
||||
# We set it to be a DummyCache to force reloading of course.xml in dev.
|
||||
# In staging environments, we would grab VERSION from data uploaded by the
|
||||
# push process.
|
||||
'general': {
|
||||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||
'KEY_PREFIX': 'general',
|
||||
'VERSION': 4,
|
||||
'KEY_FUNCTION': 'util.memcache.safe_key',
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ CACHES = {
|
||||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||
'KEY_PREFIX': 'general',
|
||||
'VERSION': 4,
|
||||
'KEY_FUNCTION': 'util.cache.memcache_safe_key',
|
||||
'KEY_FUNCTION': 'util.memcache.safe_key',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
rakefile
2
rakefile
@@ -67,7 +67,7 @@ end
|
||||
task task_name => report_dir do
|
||||
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
|
||||
ENV['NOSE_COVER_HTML_DIR'] = File.join(report_dir, "cover")
|
||||
sh(django_admin(:lms, :test, 'test', *Dir['lms/djangoapps'].each))
|
||||
sh(django_admin(system, :test, 'test', *Dir["#{system}/djangoapps/*"].each))
|
||||
end
|
||||
task :test => task_name
|
||||
|
||||
|
||||
Reference in New Issue
Block a user