annotate rhodecode/tests/vcs/base.py @ 3139:99d32d5d70db beta

email: fail nicely when no SMTP server has been configured
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jan 2013 13:56:34 +0100
parents d2a528b60e50
children d7488551578e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 """
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 Module providing backend independent mixin class. It requires that
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 InMemoryChangeset class is working properly at backend class.
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 """
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 import os
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 from rhodecode.lib import vcs
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 import time
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 import shutil
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 import datetime
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 from rhodecode.lib.vcs.utils.compat import unittest
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 from conf import SCM_TESTS, get_new_dir
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 from rhodecode.lib.vcs.nodes import FileNode
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 class BackendTestMixin(object):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 """
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 This is a backend independent test case class which should be created
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 with ``type`` method.
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 It is required to set following attributes at subclass:
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 - ``backend_alias``: alias of used backend (see ``vcs.BACKENDS``)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 - ``repo_path``: path to the repository which would be created for set of
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 tests
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 - ``recreate_repo_per_test``: If set to ``False``, repo would NOT be created
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 before every single test. Defaults to ``True``.
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 """
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 recreate_repo_per_test = True
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 @classmethod
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 def get_backend(cls):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 return vcs.get_backend(cls.backend_alias)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 @classmethod
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 def _get_commits(cls):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 commits = [
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 {
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 'message': u'Initial commit',
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 'author': u'Joe Doe <joe.doe@example.com>',
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 'date': datetime.datetime(2010, 1, 1, 20),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 'added': [
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 FileNode('foobar', content='Foobar'),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 FileNode('foobar2', content='Foobar II'),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 FileNode('foo/bar/baz', content='baz here!'),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 ],
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 },
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 {
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 'message': u'Changes...',
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 'author': u'Jane Doe <jane.doe@example.com>',
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 'date': datetime.datetime(2010, 1, 1, 21),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 'added': [
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 FileNode('some/new.txt', content='news...'),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 ],
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 'changed': [
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 FileNode('foobar', 'Foobar I'),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 ],
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 'removed': [],
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 },
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 ]
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 return commits
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 @classmethod
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 def setUpClass(cls):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 Backend = cls.get_backend()
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 cls.backend_class = Backend
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 cls.repo_path = get_new_dir(str(time.time()))
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 cls.repo = Backend(cls.repo_path, create=True)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 cls.imc = cls.repo.in_memory_changeset
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 for commit in cls._get_commits():
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 for node in commit.get('added', []):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 cls.imc.add(FileNode(node.path, content=node.content))
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 for node in commit.get('changed', []):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 cls.imc.change(FileNode(node.path, content=node.content))
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 for node in commit.get('removed', []):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 cls.imc.remove(FileNode(node.path))
2453
d2a528b60e50 whitespace cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
79
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 cls.tip = cls.imc.commit(message=unicode(commit['message']),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 author=unicode(commit['author']),
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 date=commit['date'])
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 @classmethod
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 def tearDownClass(cls):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 if not getattr(cls, 'recreate_repo_per_test', False) and \
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 'VCS_REMOVE_TEST_DIRS' in os.environ:
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 shutil.rmtree(cls.repo_path)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 def setUp(self):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 if getattr(self, 'recreate_repo_per_test', False):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 self.__class__.setUpClass()
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 def tearDown(self):
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 if getattr(self, 'recreate_repo_per_test', False) and \
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96 'VCS_REMOVE_TEST_DIRS' in os.environ:
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 shutil.rmtree(self.repo_path)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 # For each backend create test case class
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 for alias in SCM_TESTS:
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 attrs = {
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 'backend_alias': alias,
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 }
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105 cls_name = ''.join(('%s base backend test' % alias).title().split())
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 bases = (BackendTestMixin, unittest.TestCase)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 globals()[cls_name] = type(cls_name, bases, attrs)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 if __name__ == '__main__':
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 unittest.main()