~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to migrations/test_migrate.py

  • Committer: Rick Harding
  • Date: 2013-01-10 17:33:50 UTC
  • mto: This revision was merged to the branch mainline in revision 102.
  • Revision ID: rick.harding@canonical.com-20130110173350-fz1z91843morskow
Initial migrations code with a couple passing tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from os.path import join
 
2
from tempfile import mkdtemp
 
3
from unittest import TestCase
 
4
 
 
5
from charmworld.testing.factory import random_string
 
6
 
 
7
from migrate import Versions
 
8
 
 
9
 
 
10
def make_version_files(directory, number):
 
11
    """Generate a series of revisions to test against.
 
12
 
 
13
    :param number: The number of versions to generate from 1 - number
 
14
 
 
15
    """
 
16
    version_files = []
 
17
    for i in range(1, number + 1):
 
18
        filename = "{0}_{1}.py".format(str(i).zfill(3), random_string(20))
 
19
        path = join(directory, filename)
 
20
        open(path, 'w').close()
 
21
        version_files.append(filename)
 
22
    return version_files
 
23
 
 
24
 
 
25
class TestDataStore(TestCase):
 
26
    """The data store talks to mongo."""
 
27
 
 
28
    def test_mongo_version(self):
 
29
        pass
 
30
 
 
31
 
 
32
class TestVersions(TestCase):
 
33
    """The local versions of the files."""
 
34
 
 
35
    def test_latest_version(self):
 
36
        """latest returns the number of the newest revision."""
 
37
        tmpdir = mkdtemp()
 
38
        make_version_files(tmpdir, 3)
 
39
        ver = Versions(tmpdir)
 
40
 
 
41
        # Note that we're saying to create up to the specified version.
 
42
        self.assertEqual(ver.latest, 3)
 
43
 
 
44
    def test_version_list(self):
 
45
        """versions is the filenames of the version files indexed by order"""
 
46
        tmpdir = mkdtemp()
 
47
        version_files = make_version_files(tmpdir, 4)
 
48
        ver = Versions(tmpdir)
 
49
 
 
50
        for i, filename in enumerate(version_files):
 
51
            # Note that we're saying to create up to the specified version.
 
52
            self.assertEqual(filename, ver.versions[i + 1])