From d8d22ea57b13cf26e142b35d1296d9c8d1f65843 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Mon, 18 Jun 2012 13:21:06 -0400 Subject: [PATCH] Make tests pass when running on cms --- .../management/commands/ftpserve.py | 61 ------------------- cms/envs/dev.py | 2 +- cms/envs/test.py | 54 ++++++++++++++++ .../{lib => djangoapps}/cache_toolbox/COPYING | 0 .../cache_toolbox/README.rst | 0 .../cache_toolbox/__init__.py | 0 .../cache_toolbox/app_settings.py | 0 .../{lib => djangoapps}/cache_toolbox/core.py | 0 .../cache_toolbox/middleware.py | 0 .../cache_toolbox/model.py | 0 .../cache_toolbox/relation.py | 0 .../cache_toolbox/templatetags/__init__.py | 0 .../templatetags/cache_toolbox.py | 0 common/{lib => djangoapps}/util/__init__.py | 0 common/{lib => djangoapps}/util/cache.py | 0 common/{lib => djangoapps}/util/memcache.py | 0 common/{lib => djangoapps}/util/middleware.py | 0 common/{lib => djangoapps}/util/models.py | 0 common/{lib => djangoapps}/util/tests.py | 0 common/{lib => djangoapps}/util/views.py | 0 {cms => common}/lib/keystore/__init__.py | 0 {cms => common}/lib/keystore/django.py | 0 {cms => common}/lib/keystore/exceptions.py | 0 {cms => common}/lib/keystore/mongo.py | 0 lms/envs/dev.py | 2 +- rakefile | 2 +- 26 files changed, 57 insertions(+), 64 deletions(-) delete mode 100644 cms/djangoapps/contentstore/management/commands/ftpserve.py create mode 100644 cms/envs/test.py rename common/{lib => djangoapps}/cache_toolbox/COPYING (100%) rename common/{lib => djangoapps}/cache_toolbox/README.rst (100%) rename common/{lib => djangoapps}/cache_toolbox/__init__.py (100%) rename common/{lib => djangoapps}/cache_toolbox/app_settings.py (100%) rename common/{lib => djangoapps}/cache_toolbox/core.py (100%) rename common/{lib => djangoapps}/cache_toolbox/middleware.py (100%) rename common/{lib => djangoapps}/cache_toolbox/model.py (100%) rename common/{lib => djangoapps}/cache_toolbox/relation.py (100%) rename common/{lib => djangoapps}/cache_toolbox/templatetags/__init__.py (100%) rename common/{lib => djangoapps}/cache_toolbox/templatetags/cache_toolbox.py (100%) rename common/{lib => djangoapps}/util/__init__.py (100%) rename common/{lib => djangoapps}/util/cache.py (100%) rename common/{lib => djangoapps}/util/memcache.py (100%) rename common/{lib => djangoapps}/util/middleware.py (100%) rename common/{lib => djangoapps}/util/models.py (100%) rename common/{lib => djangoapps}/util/tests.py (100%) rename common/{lib => djangoapps}/util/views.py (100%) rename {cms => common}/lib/keystore/__init__.py (100%) rename {cms => common}/lib/keystore/django.py (100%) rename {cms => common}/lib/keystore/exceptions.py (100%) rename {cms => common}/lib/keystore/mongo.py (100%) diff --git a/cms/djangoapps/contentstore/management/commands/ftpserve.py b/cms/djangoapps/contentstore/management/commands/ftpserve.py deleted file mode 100644 index f0a1c19dbf..0000000000 --- a/cms/djangoapps/contentstore/management/commands/ftpserve.py +++ /dev/null @@ -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() diff --git a/cms/envs/dev.py b/cms/envs/dev.py index f7277b3d3f..332f52f145 100644 --- a/cms/envs/dev.py +++ b/cms/envs/dev.py @@ -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', } } diff --git a/cms/envs/test.py b/cms/envs/test.py new file mode 100644 index 0000000000..1a20d9e6f8 --- /dev/null +++ b/cms/envs/test.py @@ -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', + } +} diff --git a/common/lib/cache_toolbox/COPYING b/common/djangoapps/cache_toolbox/COPYING similarity index 100% rename from common/lib/cache_toolbox/COPYING rename to common/djangoapps/cache_toolbox/COPYING diff --git a/common/lib/cache_toolbox/README.rst b/common/djangoapps/cache_toolbox/README.rst similarity index 100% rename from common/lib/cache_toolbox/README.rst rename to common/djangoapps/cache_toolbox/README.rst diff --git a/common/lib/cache_toolbox/__init__.py b/common/djangoapps/cache_toolbox/__init__.py similarity index 100% rename from common/lib/cache_toolbox/__init__.py rename to common/djangoapps/cache_toolbox/__init__.py diff --git a/common/lib/cache_toolbox/app_settings.py b/common/djangoapps/cache_toolbox/app_settings.py similarity index 100% rename from common/lib/cache_toolbox/app_settings.py rename to common/djangoapps/cache_toolbox/app_settings.py diff --git a/common/lib/cache_toolbox/core.py b/common/djangoapps/cache_toolbox/core.py similarity index 100% rename from common/lib/cache_toolbox/core.py rename to common/djangoapps/cache_toolbox/core.py diff --git a/common/lib/cache_toolbox/middleware.py b/common/djangoapps/cache_toolbox/middleware.py similarity index 100% rename from common/lib/cache_toolbox/middleware.py rename to common/djangoapps/cache_toolbox/middleware.py diff --git a/common/lib/cache_toolbox/model.py b/common/djangoapps/cache_toolbox/model.py similarity index 100% rename from common/lib/cache_toolbox/model.py rename to common/djangoapps/cache_toolbox/model.py diff --git a/common/lib/cache_toolbox/relation.py b/common/djangoapps/cache_toolbox/relation.py similarity index 100% rename from common/lib/cache_toolbox/relation.py rename to common/djangoapps/cache_toolbox/relation.py diff --git a/common/lib/cache_toolbox/templatetags/__init__.py b/common/djangoapps/cache_toolbox/templatetags/__init__.py similarity index 100% rename from common/lib/cache_toolbox/templatetags/__init__.py rename to common/djangoapps/cache_toolbox/templatetags/__init__.py diff --git a/common/lib/cache_toolbox/templatetags/cache_toolbox.py b/common/djangoapps/cache_toolbox/templatetags/cache_toolbox.py similarity index 100% rename from common/lib/cache_toolbox/templatetags/cache_toolbox.py rename to common/djangoapps/cache_toolbox/templatetags/cache_toolbox.py diff --git a/common/lib/util/__init__.py b/common/djangoapps/util/__init__.py similarity index 100% rename from common/lib/util/__init__.py rename to common/djangoapps/util/__init__.py diff --git a/common/lib/util/cache.py b/common/djangoapps/util/cache.py similarity index 100% rename from common/lib/util/cache.py rename to common/djangoapps/util/cache.py diff --git a/common/lib/util/memcache.py b/common/djangoapps/util/memcache.py similarity index 100% rename from common/lib/util/memcache.py rename to common/djangoapps/util/memcache.py diff --git a/common/lib/util/middleware.py b/common/djangoapps/util/middleware.py similarity index 100% rename from common/lib/util/middleware.py rename to common/djangoapps/util/middleware.py diff --git a/common/lib/util/models.py b/common/djangoapps/util/models.py similarity index 100% rename from common/lib/util/models.py rename to common/djangoapps/util/models.py diff --git a/common/lib/util/tests.py b/common/djangoapps/util/tests.py similarity index 100% rename from common/lib/util/tests.py rename to common/djangoapps/util/tests.py diff --git a/common/lib/util/views.py b/common/djangoapps/util/views.py similarity index 100% rename from common/lib/util/views.py rename to common/djangoapps/util/views.py diff --git a/cms/lib/keystore/__init__.py b/common/lib/keystore/__init__.py similarity index 100% rename from cms/lib/keystore/__init__.py rename to common/lib/keystore/__init__.py diff --git a/cms/lib/keystore/django.py b/common/lib/keystore/django.py similarity index 100% rename from cms/lib/keystore/django.py rename to common/lib/keystore/django.py diff --git a/cms/lib/keystore/exceptions.py b/common/lib/keystore/exceptions.py similarity index 100% rename from cms/lib/keystore/exceptions.py rename to common/lib/keystore/exceptions.py diff --git a/cms/lib/keystore/mongo.py b/common/lib/keystore/mongo.py similarity index 100% rename from cms/lib/keystore/mongo.py rename to common/lib/keystore/mongo.py diff --git a/lms/envs/dev.py b/lms/envs/dev.py index 17e1e96f45..decd92d136 100644 --- a/lms/envs/dev.py +++ b/lms/envs/dev.py @@ -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', } } diff --git a/rakefile b/rakefile index a04d8ebdee..a3d742cef1 100644 --- a/rakefile +++ b/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