--- /dev/null
+import unittest
+
+import Tests.Fixtures
+import FileUtils
+
+
+class FindFilePathsTest(unittest.TestCase):
+
+ def testPostgisFixturesFound(self):
+ """
+ There are two dummy files in the fixtures directory,
+ lwpostgis.sql and postgis.sql. They have been placed in two
+ subfolders named after two distros who include the SQL file with
+ different names.
+
+ If we search a distro subdirectory for *both* names, we should
+ get back only one result: the correct one to use on that
+ distro.
+ """
+ gentoo_fixtures_path = Tests.Fixtures.Path() + '/FileUtils/gentoo'
+ ubuntu_fixtures_path = Tests.Fixtures.Path() + '/FileUtils/ubuntu'
+
+ target_files = ['lwpostgis.sql', 'postgis.sql']
+
+ res = FileUtils.find_file_paths(gentoo_fixtures_path, target_files)
+ self.assertTrue(len(res) == 1)
+ self.assertTrue('postgis.sql' in res[0])
+
+ res = FileUtils.find_file_paths(ubuntu_fixtures_path, target_files)
+ print res[0]
+ self.assertTrue(len(res) == 1)
+ self.assertTrue('lwpostgis.sql' in res[0])
+
+
+ def testBothFixturesFoundFromRoot(self):
+ """
+ If we search for the (lw)postgis.sql files from the fixtures
+ root, we should find both of them.
+ """
+ fixtures_path = Tests.Fixtures.Path() + '/FileUtils'
+
+ target_files = ['lwpostgis.sql', 'postgis.sql']
+
+ res = FileUtils.find_file_paths(fixtures_path, target_files)
+ self.assertTrue(len(res) == 2)
+ # "gentoo" comes first alphabetically, and so we'll traverse
+ # it first. Thus, postgis.sql should be found before
+ # lwpostgis.sql.
+ self.assertTrue('postgis.sql' in res[0])
+ self.assertTrue('lwpostgis.sql' in res[1])
+
+
+ def testOnlyOneResultReturnedWhenReturnFirstTrue(self):
+ """
+ Make sure that, in a case where we would normally get two
+ results back, the usage of return_first causes us to receive
+ only one.
+ """
+ fixtures_path = Tests.Fixtures.Path() + '/FileUtils'
+
+ target_files = ['lwpostgis.sql', 'postgis.sql']
+
+ res = FileUtils.find_file_paths(fixtures_path, target_files, True)
+ self.assertTrue(len(res) == 1)
+ # Again, "gentoo" comes before "ubuntu" alphabetically, so
+ # this is the expected result.
+ self.assertTrue('postgis.sql' in res[0])
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(FindFilePathsTest))
+ return suite