| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| 3 | # Copyright (C) 2014 Steffen Hoffmann <hoff.st@web.de> |
|---|
| 4 | # |
|---|
| 5 | # This software is licensed as described in the file COPYING, which |
|---|
| 6 | # you should have received as part of this distribution. |
|---|
| 7 | # |
|---|
| 8 | |
|---|
| 9 | import shutil |
|---|
| 10 | import tempfile |
|---|
| 11 | import unittest |
|---|
| 12 | |
|---|
| 13 | from trac.perm import PermissionCache, PermissionSystem |
|---|
| 14 | from trac.test import EnvironmentStub, MockRequest |
|---|
| 15 | |
|---|
| 16 | from tractags.api import TagSystem |
|---|
| 17 | from tractags.db import TagSetup |
|---|
| 18 | from tractags.xmlrpc import TagRPC |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class TagRPCTestCase(unittest.TestCase): |
|---|
| 22 | |
|---|
| 23 | def setUp(self): |
|---|
| 24 | self.env = EnvironmentStub(default_data=True, |
|---|
| 25 | enable=['trac.*', 'tractags.*']) |
|---|
| 26 | self.env.path = tempfile.mkdtemp() |
|---|
| 27 | setup = TagSetup(self.env) |
|---|
| 28 | # Current tractags schema is partially setup with enabled component. |
|---|
| 29 | # Revert these changes for getting a clean setup. |
|---|
| 30 | self._revert_tractags_schema_init() |
|---|
| 31 | setup.upgrade_environment() |
|---|
| 32 | |
|---|
| 33 | self.perms = PermissionSystem(self.env) |
|---|
| 34 | self.tag_s = TagSystem(self.env) |
|---|
| 35 | |
|---|
| 36 | # Populate table with initial test data. |
|---|
| 37 | self.env.db_transaction(""" |
|---|
| 38 | INSERT INTO tags (tagspace, name, tag) |
|---|
| 39 | VALUES ('wiki', 'WikiStart', 'tag1') |
|---|
| 40 | """) |
|---|
| 41 | |
|---|
| 42 | self.req = MockRequest(self.env, authname='editor') |
|---|
| 43 | |
|---|
| 44 | def tearDown(self): |
|---|
| 45 | self.env.shutdown() |
|---|
| 46 | shutil.rmtree(self.env.path) |
|---|
| 47 | |
|---|
| 48 | # Helpers |
|---|
| 49 | |
|---|
| 50 | def _revert_tractags_schema_init(self): |
|---|
| 51 | with self.env.db_transaction as db: |
|---|
| 52 | db("DROP TABLE IF EXISTS tags") |
|---|
| 53 | db("DROP TABLE IF EXISTS tags_change") |
|---|
| 54 | db("DELETE FROM system WHERE name='tags_version'") |
|---|
| 55 | db("DELETE FROM permission WHERE action %s" % db.like(), |
|---|
| 56 | ('TAGS_%',)) |
|---|
| 57 | |
|---|
| 58 | # Tests |
|---|
| 59 | |
|---|
| 60 | def test_init(self): |
|---|
| 61 | TagRPC(self.env) |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | def test_suite(): |
|---|
| 65 | suite = unittest.TestSuite() |
|---|
| 66 | suite.addTest(unittest.makeSuite(TagRPCTestCase)) |
|---|
| 67 | return suite |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | if __name__ == '__main__': |
|---|
| 71 | unittest.main(defaultTest='test_suite') |
|---|