1#!/usr/bin/env python
2#    Licensed to the Apache Software Foundation (ASF) under one
3#    or more contributor license agreements.  See the NOTICE file
4#    distributed with this work for additional information
5#    regarding copyright ownership.  The ASF licenses this file
6#    to you under the Apache License, Version 2.0 (the
7#    "License"); you may not use this file except in compliance
8#    with the License.  You may obtain a copy of the License at
9#
10#      http://www.apache.org/licenses/LICENSE-2.0
11#
12#    Unless required by applicable law or agreed to in writing,
13#    software distributed under the License is distributed on an
14#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15#    KIND, either express or implied.  See the License for the
16#    specific language governing permissions and limitations
17#    under the License.
18
19import setup_path
20import unittest
21import os
22import shutil
23import tempfile
24from csvn.core import *
25from urllib import pathname2url
26from csvn.repos import LocalRepository, RemoteRepository
27
28repos_location = os.path.join(tempfile.gettempdir(), "svn_test_repos")
29
30class LocalRepositoryTestCase(unittest.TestCase):
31
32    def setUp(self):
33        dumpfile = open(os.path.join(os.path.split(__file__)[0],
34                        'test.dumpfile'))
35
36        # Just in case a previous test instance was not properly cleaned up
37        self.remove_from_disk()
38
39        self.repos = LocalRepository(repos_location, create=True)
40        self.repos.load(dumpfile)
41
42    def tearDown(self):
43        self.repos.close()
44        self.remove_from_disk()
45        self.repos = None
46
47    def remove_from_disk(self):
48        """Remove anything left on disk"""
49        if os.path.exists(repos_location):
50            svn_repos_delete(repos_location, Pool())
51
52    def test_local_latest_revnum(self):
53        self.assertEqual(9, self.repos.latest_revnum())
54
55    def test_local_get_prop(self):
56        self.assertEqual(
57            "Set prop to indicate proper information on awesomeness.\n",
58            self.repos.get_rev_prop(8, "svn:log")
59        )
60
61    def test_local_check_path(self):
62        self.assertEqual(svn_node_file,
63            self.repos.check_path("trunk/README.txt"))
64        self.assertEqual(svn_node_dir,
65            self.repos.check_path("trunk/dir", 6))
66        self.assertEqual(svn_node_none,
67            self.repos.check_path("trunk/dir", 7))
68        self.assertEqual(svn_node_none,
69            self.repos.check_path("does_not_compute"))
70
71def suite():
72    return unittest.makeSuite(LocalRepositoryTestCase, 'test')
73
74if __name__ == '__main__':
75    runner = unittest.TextTestRunner()
76    runner.run(suite())
77