Add teardown method for all tests.

This commit is contained in:
Roberto Rosario
2015-07-12 03:28:31 -04:00
parent e05f6b5830
commit fd8721b297
5 changed files with 22 additions and 8 deletions

View File

@@ -43,6 +43,13 @@ class PermissionTestCase(TestCase):
self.role = Role.objects.create(label='test role') self.role = Role.objects.create(label='test role')
Permission.invalidate_cache() Permission.invalidate_cache()
def tearDown(self):
for document_type in DocumentType.objects.all():
document_type.delete()
self.role.delete()
self.group.delete()
self.user.delete()
def test_check_access_without_permissions(self): def test_check_access_without_permissions(self):
with self.assertRaises(PermissionDenied): with self.assertRaises(PermissionDenied):
AccessControlList.objects.check_access(permissions=(permission_document_view,), user=self.user, obj=self.document_1) AccessControlList.objects.check_access(permissions=(permission_document_view,), user=self.user, obj=self.document_1)

View File

@@ -21,6 +21,10 @@ class IndexTestCase(TestCase):
with open(TEST_SMALL_DOCUMENT_PATH) as file_object: with open(TEST_SMALL_DOCUMENT_PATH) as file_object:
self.document = self.document_type.new_document(file_object=File(file_object)) self.document = self.document_type.new_document(file_object=File(file_object))
def tearDown(self):
for document_type in DocumentType.objects.all():
document_type.delete()
def test_indexing(self): def test_indexing(self):
metadata_type = MetadataType.objects.create(name='test', label='test') metadata_type = MetadataType.objects.create(name='test', label='test')
DocumentTypeMetadataType.objects.create(document_type=self.document_type, metadata_type=metadata_type) DocumentTypeMetadataType.objects.create(document_type=self.document_type, metadata_type=metadata_type)

View File

@@ -32,6 +32,10 @@ class DocumentTestCase(TestCase):
with open(TEST_KEY_FILE) as file_object: with open(TEST_KEY_FILE) as file_object:
gpg.import_key(file_object.read()) gpg.import_key(file_object.read())
def tearDown(self):
self.document.delete()
self.document_type.delete()
def test_document_no_signature(self): def test_document_no_signature(self):
self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), False) self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), False)
@@ -54,7 +58,3 @@ class DocumentTestCase(TestCase):
self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), True) self.assertEqual(DocumentVersionSignature.objects.has_detached_signature(self.document.latest_version), True)
self.assertEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version).status, SIGNATURE_STATE_VALID) self.assertEqual(DocumentVersionSignature.objects.verify_signature(self.document.latest_version).status, SIGNATURE_STATE_VALID)
def tearDown(self):
self.document.delete()
self.document_type.delete()

View File

@@ -34,6 +34,10 @@ class DocumentAPICreateDocumentTestCase(TestCase):
ocr_settings.auto_ocr = False ocr_settings.auto_ocr = False
ocr_settings.save() ocr_settings.save()
def tearDown(self):
self.document_type.delete()
self.admin_user.delete()
def test_uploading_a_document_using_token_auth(self): def test_uploading_a_document_using_token_auth(self):
# Get the an user token # Get the an user token
token_client = APIClient() token_client = APIClient()
@@ -97,6 +101,3 @@ class DocumentAPICreateDocumentTestCase(TestCase):
# The document was deleted from the the DB? # The document was deleted from the the DB?
self.assertEqual(Document.objects.count(), 0) self.assertEqual(Document.objects.count(), 0)
def tearDown(self):
self.document_type.delete()

View File

@@ -43,7 +43,9 @@ class Issue46TestCase(TestCase):
) )
def tearDown(self): def tearDown(self):
DocumentType.objects.all().delete() for document_type in DocumentType.objects.all():
document_type.delete()
self.admin_user.delete() self.admin_user.delete()
def test_advanced_search_past_first_page(self): def test_advanced_search_past_first_page(self):