Commit 5404345b by Calen Pennington

Make tests pass when running on cms

parent 328b2df7
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',
}
}
"""
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',
}
}
......
......@@ -66,7 +66,7 @@ end
desc "Run all django tests on our djangoapps for the #{system}"
task task_name => report_dir do
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
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
......
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