Skip to content

Commit

Permalink
remove from disk when delete is called
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Oct 17, 2014
1 parent 60bb29f commit 578ff34
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion elasticgit/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ def delete(self, model, message):
"""
index = self.repo.index
index.remove([self.git_name(model)])
return index.commit(message)
index.commit(message)
return os.remove(
os.path.join(self.workdir, self.git_name(model)))

def storage_exists(self):
"""
Expand Down
25 changes: 25 additions & 0 deletions elasticgit/tests/test_workspace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import types
import os

from elasticgit.tests.base import ModelBaseTest, TestPerson
from elasticgit.manager import ModelMappingType
Expand Down Expand Up @@ -68,21 +69,45 @@ def test_saving(self):
self.assertEqual(
workspace.S(TestPerson).query(name__match='Name').count(), 1)

def is_file(self, workspace, model, suffix):
return os.path.isfile(
os.path.join(
workspace.working_dir,
model.__module__,
model.__class__.__name__,
'%s.%s' % (model.uuid, suffix)))

def assertDataFile(self, workspace, model, suffix='json'):
self.assertTrue(
self.is_file(workspace, model, suffix),
'%s has no data file.' % (model,))

def assertNotDataFile(self, workspace, model, suffix='json'):
self.assertFalse(
self.is_file(workspace, model, suffix),
'%s has a data file.' % (model,))

def test_deleting(self):
workspace = self.workspace
person = TestPerson({
'age': 1,
'name': 'Name'
})

dir_name = os.path.join(workspace.working_dir,
TestPerson.__module__)
workspace.save(person, 'Saving a person')
self.assertDataFile(workspace, person)

workspace.refresh_index()
self.assertEqual(
workspace.S(TestPerson).query(name__match='Name').count(), 1)
git_person = workspace.sm.get(TestPerson, person.uuid)
self.assertEqual(git_person, person)

workspace.delete(person, 'Deleting a person')
self.assertNotDataFile(workspace, person)

workspace.refresh_index()
self.assertEqual(
workspace.S(TestPerson).query(name__match='Name').count(), 0)
Expand Down

0 comments on commit 578ff34

Please sign in to comment.