summaryrefslogtreecommitdiff
path: root/tests/test_collection.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-03-16 15:46:14 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-03-16 15:46:14 +0100
commit6c82e1ff21783c590c3bfa3f44e9b0f5dbae07af (patch)
treec1f22eaaac34ddcf7a25c07ee6542f9167f3e44e /tests/test_collection.py
parenta981850bb221735bc0bcb750791228c9f8198143 (diff)
parentf9788793d0b0d384eef3725b13ab3134c1cc46c0 (diff)
Merge branch 'master' of git.trueelena.org:software/lesana
Diffstat (limited to 'tests/test_collection.py')
-rw-r--r--tests/test_collection.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_collection.py b/tests/test_collection.py
index a197237..e17e044 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -4,6 +4,7 @@ import shutil
import tempfile
import unittest
+import git
import ruamel.yaml
import lesana
@@ -203,9 +204,12 @@ class testCollectionCreation(unittest.TestCase):
self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
self.assertTrue(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
+ created = lesana.Collection(tmpdir)
+ self.assertTrue(created.settings['git'])
shutil.rmtree(tmpdir)
def do_nothing(*args, **kwargs):
+ # A function that does nothing instead of editing a file
pass
def test_init_edit_file(self):
@@ -233,6 +237,8 @@ class testCollectionCreation(unittest.TestCase):
self.assertTrue(os.path.isdir(os.path.join(tmpdir, '.lesana')))
self.assertTrue(os.path.isfile(os.path.join(tmpdir, 'settings.yaml')))
self.assertFalse(os.path.isfile(os.path.join(tmpdir, '.gitignore')))
+ created = lesana.Collection(tmpdir)
+ self.assertFalse(created.settings['git'])
shutil.rmtree(tmpdir)
def test_deletion(self):
@@ -259,6 +265,39 @@ class testCollectionCreation(unittest.TestCase):
mset = collection._enquire.get_mset(0, 10)
self.assertEqual(mset.get_matches_estimated(), 0)
+ def _find_file_in_git_index(self, fname, index):
+ found = False
+ for (path, stage) in index.entries:
+ if fname in path:
+ found = True
+ break
+ return found
+
+ def test_git_adding(self):
+ tmpdir = tempfile.mkdtemp()
+ shutil.copy('tests/data/simple/settings.yaml', tmpdir)
+ shutil.copytree(
+ 'tests/data/simple/items',
+ os.path.join(tmpdir, 'items'),
+ )
+ collection = lesana.Collection.init(tmpdir)
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ repo = git.Repo(tmpdir)
+ # By default, this collection doesn't have any git entry in the
+ # settings (but there is a repo)
+ collection.git_add_files([os.path.join(collection.itemdir, fname)])
+ self.assertFalse(self._find_file_in_git_index(fname, repo.index))
+ # Then we set it to false
+ collection.settings['git'] = False
+ collection.git_add_files([os.path.join(collection.itemdir, fname)])
+ self.assertFalse(self._find_file_in_git_index(fname, repo.index))
+ # And only when it's set to true we should find the file in the
+ # staging area
+ collection.settings['git'] = True
+ collection.git_add_files([os.path.join(collection.itemdir, fname)])
+ self.assertTrue(self._find_file_in_git_index(fname, repo.index))
+ shutil.rmtree(tmpdir)
+
if __name__ == '__main__':
unittest.main()