~ubuntu-branches/ubuntu/precise/desktopcouch/precise

« back to all changes in this revision

Viewing changes to desktopcouch/application/tests/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Chad MILLER
  • Date: 2011-01-12 15:08:25 UTC
  • mfrom: (1.5.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110112150825-bzvn23kzufr0qdyb
Tags: 1.0.5-0ubuntu1
* New upstream release, skipping a few buggy releases.
* Split code into binary packages:
  - desktopcouch, configuration files and dependencies, but no code.
  - python-desktopcouch: transitional package
  - python-desktopcouch-application: local DB startup and discovery
  - python-desktopcouch-records: library for DB access anywhere
  - python-desktopcouch-recordtypes: support specific data structures
  - desktopcouch-ubuntuone, replication and pairing with cloud service
* Drop patch that some maverick apps incorrectly needed.
  patches/0-items-should-expose-private-data-for-now.patch
* Update package compatibility-version, 6 -> 7.
* Use newer debhelper and use python-support instead of python-central.
* Depend on contemporary python-couchdb, instead of ancient version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Tests for Desktop CouchDB"""
 
2
 
 
3
import atexit
 
4
import os
 
5
import unittest
 
6
import tempfile
 
7
import shutil
 
8
 
 
9
 
 
10
from desktopcouch.application import local_files
 
11
from desktopcouch.application.platform import (TestKeyring,
 
12
    set_application_name)
 
13
from desktopcouch.application.start_local_couchdb import start_couchdb
 
14
from desktopcouch.application.stop_local_couchdb import stop_couchdb
 
15
 
 
16
set_application_name('desktopcouch testing')
 
17
 
 
18
 
 
19
class TestCase(unittest.TestCase):
 
20
    """Base class for tests."""
 
21
 
 
22
    def __init__(self, *args, **kwargs):
 
23
        super(TestCase, self).__init__(*args, **kwargs)
 
24
        # pylint: disable=C0103
 
25
        if not hasattr(self, 'assertIn'):
 
26
            self.assertIn = lambda value, container, *args: \
 
27
                            self.assertTrue(value in container, *args)
 
28
        if not hasattr(self, 'assertNotIn'):
 
29
            self.assertNotIn = lambda value, container, *args: \
 
30
                               self.assertTrue(value not in container, *args)
 
31
        if not hasattr(self, 'assertIs'):
 
32
            self.assertIs = lambda value1, value2, *args: \
 
33
                            self.assertTrue(value1 is value2, *args)
 
34
        if not hasattr(self, 'assertIsNot'):
 
35
            self.assertIsNot = lambda value1, value2, *args: \
 
36
                               self.assertTrue(value1 is not value2, *args)
 
37
 
 
38
 
 
39
def create_new_test_environment():
 
40
    """Create a new test environment."""
 
41
    basedir = tempfile.mkdtemp()
 
42
    if not os.path.exists(basedir):
 
43
        os.mkdir(basedir)
 
44
 
 
45
    cache = os.path.join(basedir, 'cache')
 
46
    data = os.path.join(basedir, 'data')
 
47
    config = os.path.join(basedir, 'config')
 
48
    new_context = local_files.Context(
 
49
        cache, data, config, keyring=TestKeyring())
 
50
    new_context.couchdb_log_level = 'debug'
 
51
 
 
52
    # Add etc folder to config
 
53
    source_tree_etc_folder = os.path.realpath(
 
54
      os.path.join(os.path.split(__file__)[0], "..", "..", "config"))
 
55
    if os.path.isdir(source_tree_etc_folder):
 
56
        os.environ["XDG_CONFIG_DIRS"] = source_tree_etc_folder
 
57
 
 
58
    def stop_test_couch(temp_dir, ctx):
 
59
        """Stop the test couchdatabase."""
 
60
        stop_couchdb(ctx)
 
61
        shutil.rmtree(temp_dir)
 
62
 
 
63
    start_couchdb(ctx=new_context)
 
64
    atexit.register(stop_test_couch, basedir, new_context)
 
65
 
 
66
    return new_context
 
67
 
 
68
 
 
69
# TODO: Remove these after you're sure nothing we care about uses these env.
 
70
os.environ['XDG_CACHE_HOME'] = "/cachehome"
 
71
os.environ['XDG_DATA_HOME'] = "/datahome"
 
72
os.environ['XDG_CONFIG_HOME'] = "/confighome"
 
73
os.environ['XDG_DATA_DIRS'] = ''
 
74
 
 
75
test_context = create_new_test_environment()  # pylint: disable=C0103