diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-14 12:01:00 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-14 15:34:05 +0100 |
commit | 7108320a1295641a6d591d29edf01e3a4cc45e82 (patch) | |
tree | 216a472994556d08c127f2b535f77f9c41902e35 /ishtar_common/tests.py | |
parent | 5e121edfd6b3bb4de4344e2f631630bf94c3de0b (diff) | |
download | Ishtar-7108320a1295641a6d591d29edf01e3a4cc45e82.tar.bz2 Ishtar-7108320a1295641a6d591d29edf01e3a4cc45e82.zip |
Tests: use variable for fixtures paths
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index ce3e096c8..f4e372770 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -97,64 +97,64 @@ from ishtar_common.utils import ( from ishtar_common.tasks import launch_export from ishtar_common import utils_secretary -from django.contrib.staticfiles.testing import StaticLiveServerTestCase - +LIB_BASE_PATH = settings.LIB_BASE_PATH +FIXTURE_AUTH_PATH = settings.FIXTURE_AUTH_PATH COMMON_FIXTURES = [ - settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json", - settings.ROOT_PATH + "../ishtar_common/fixtures/initial_data-fr.json", - settings.ROOT_PATH + "../ishtar_common/fixtures/initial_geo-fr.json", - settings.ROOT_PATH + "../ishtar_common/fixtures/initial_importtypes-fr.json", + FIXTURE_AUTH_PATH + "fixtures/initial_data-auth-fr.json", + LIB_BASE_PATH + "ishtar_common/fixtures/initial_data-fr.json", + LIB_BASE_PATH + "ishtar_common/fixtures/initial_geo-fr.json", + LIB_BASE_PATH + "ishtar_common/fixtures/initial_importtypes-fr.json", ] OPERATION_FIXTURES = COMMON_FIXTURES + [ - settings.ROOT_PATH + "../archaeological_operations/fixtures/initial_data-fr.json", - settings.ROOT_PATH - + "../archaeological_operations/fixtures/initial_data_relation_type_norel-fr.json", - settings.ROOT_PATH - + "../archaeological_operations/fixtures/initial_data_relation_type-fr.json", + LIB_BASE_PATH + "archaeological_operations/fixtures/initial_data-fr.json", + LIB_BASE_PATH + + "archaeological_operations/fixtures/initial_data_relation_type_norel-fr.json", + LIB_BASE_PATH + + "archaeological_operations/fixtures/initial_data_relation_type-fr.json", ] OPERATION_TOWNS_FIXTURES = OPERATION_FIXTURES + [ - settings.ROOT_PATH + "../ishtar_common/fixtures/test_towns.json" + LIB_BASE_PATH + "ishtar_common/fixtures/test_towns.json" ] FILE_FIXTURES = OPERATION_FIXTURES + [ - settings.ROOT_PATH + "../archaeological_files/fixtures/initial_data-fr.json" + LIB_BASE_PATH + "archaeological_files/fixtures/initial_data-fr.json" ] FILE_TOWNS_FIXTURES = OPERATION_TOWNS_FIXTURES + [ - settings.ROOT_PATH + "../archaeological_files/fixtures/initial_data-fr.json" + LIB_BASE_PATH + "archaeological_files/fixtures/initial_data-fr.json" ] CONTEXT_RECORD_FIXTURES = FILE_FIXTURES + [ - settings.ROOT_PATH - + "../archaeological_context_records/fixtures/initial_data-fr.json", - settings.ROOT_PATH - + "../archaeological_context_records/fixtures/initial_data_relation_type_norel-fr.json", - settings.ROOT_PATH - + "../archaeological_context_records/fixtures/initial_data_relation_type-fr.json", + LIB_BASE_PATH + + "archaeological_context_records/fixtures/initial_data-fr.json", + LIB_BASE_PATH + + "archaeological_context_records/fixtures/initial_data_relation_type_norel-fr.json", + LIB_BASE_PATH + + "archaeological_context_records/fixtures/initial_data_relation_type-fr.json", ] CONTEXT_RECORD_TOWNS_FIXTURES = FILE_TOWNS_FIXTURES + [ - settings.ROOT_PATH - + "../archaeological_context_records/fixtures/initial_data-fr.json", - settings.ROOT_PATH - + "../archaeological_context_records/fixtures/initial_data_relation_type_norel-fr.json", - settings.ROOT_PATH - + "../archaeological_context_records/fixtures/initial_data_relation_type-fr.json", + LIB_BASE_PATH + + "archaeological_context_records/fixtures/initial_data-fr.json", + LIB_BASE_PATH + + "archaeological_context_records/fixtures/initial_data_relation_type_norel-fr.json", + LIB_BASE_PATH + + "archaeological_context_records/fixtures/initial_data_relation_type-fr.json", ] FIND_FIXTURES = CONTEXT_RECORD_FIXTURES + [ - settings.ROOT_PATH + "../archaeological_finds/fixtures/initial_data-fr.json", + LIB_BASE_PATH + "archaeological_finds/fixtures/initial_data-fr.json", ] FIND_TOWNS_FIXTURES = CONTEXT_RECORD_TOWNS_FIXTURES + [ - settings.ROOT_PATH + "../archaeological_finds/fixtures/initial_data-fr.json", + LIB_BASE_PATH + "archaeological_finds/fixtures/initial_data-fr.json", ] WAREHOUSE_FIXTURES = FIND_FIXTURES + [ - settings.ROOT_PATH + "../archaeological_warehouse/fixtures/initial_data-fr.json", + LIB_BASE_PATH + "archaeological_warehouse/fixtures/initial_data-fr.json", ] @@ -259,7 +259,7 @@ class SearchText: class CommandsTestCase(TestCase): - fixtures = [settings.ROOT_PATH + "../ishtar_common/fixtures/test_towns.json"] + fixtures = [LIB_BASE_PATH + "ishtar_common/fixtures/test_towns.json"] def test_clean_ishtar(self): """ @@ -282,14 +282,14 @@ class CommandsTestCase(TestCase): out = StringIO() call_command( "import_geofla_csv", - settings.ROOT_PATH + "../ishtar_common/tests/geofla-test.csv", + LIB_BASE_PATH + "ishtar_common/tests/geofla-test.csv", "--quiet", stdout=out, ) self.assertEqual(town_nb + 9, models.Town.objects.count()) call_command( "import_geofla_csv", - settings.ROOT_PATH + "../ishtar_common/tests/geofla-test.csv", + LIB_BASE_PATH + "ishtar_common/tests/geofla-test.csv", "--quiet", stdout=out, ) @@ -333,7 +333,7 @@ class CommandsTestCase(TestCase): out = StringIO() call_command( "import_insee_comm_csv", - settings.ROOT_PATH + "../ishtar_common/tests/insee-test.csv", + LIB_BASE_PATH + "ishtar_common/tests/insee-test.csv", "--quiet", stdout=out, ) @@ -348,7 +348,7 @@ class CommandsTestCase(TestCase): call_command( "import_insee_comm_csv", "--quiet", - settings.ROOT_PATH + "../ishtar_common/tests/insee-test.csv", + LIB_BASE_PATH + "ishtar_common/tests/insee-test.csv", stdout=out, ) # no new town @@ -645,8 +645,8 @@ class WizardTest(object): class CacheTest(TestCase): fixtures = [ - settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json", - settings.ROOT_PATH + "../ishtar_common/fixtures/initial_data-fr.json", + FIXTURE_AUTH_PATH + "fixtures/initial_data-auth-fr.json", + LIB_BASE_PATH + "ishtar_common/fixtures/initial_data-fr.json", ] def test_add(self): @@ -710,7 +710,7 @@ class CacheTest(TestCase): class GenericSerializationTest: def create_document_default(self): image_path = os.path.join( - settings.ROOT_PATH, "..", "ishtar_common", "tests", "test.png" + LIB_BASE_PATH, "ishtar_common", "tests", "test.png" ) self.documents = [] for idx in range(12): @@ -2426,8 +2426,8 @@ class ImportTest(TestCase): importer_type = models.ImporterType.objects.create(associated_models=imp_model) dest = os.path.join("media", "MCC-operations-example.csv") shutil.copy( - settings.ROOT_PATH - + "../archaeological_operations/tests/MCC-operations-example.csv", + LIB_BASE_PATH + + "archaeological_operations/tests/MCC-operations-example.csv", dest, ) with open(dest, "rb") as f: @@ -2523,8 +2523,7 @@ class ImportTest(TestCase): imp_model = self.create_importer_model() importer_type = self.create_importer_type(imp_model) - image_path = os.path.join("..", "ishtar_common", "tests", "test.png") - + image_path = os.path.join(LIB_BASE_PATH, "ishtar_common", "tests", "test.png") data = { "name": "Import Zip Not Valid Must Fail", "importer_type": importer_type.pk, @@ -2700,8 +2699,8 @@ class ImportTest(TestCase): class IshtarSiteProfileTest(TestCase): fixtures = [ - settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json", - settings.ROOT_PATH + "../ishtar_common/fixtures/initial_data-fr.json", + FIXTURE_AUTH_PATH + "fixtures/initial_data-auth-fr.json", + LIB_BASE_PATH + "ishtar_common/fixtures/initial_data-fr.json", ] def testRelevance(self): @@ -3570,8 +3569,8 @@ class NewItems(TestCase): class AccountWizardTest(WizardTest, TestCase): fixtures = [ - settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json", - settings.ROOT_PATH + "../ishtar_common/fixtures/initial_data-fr.json", + FIXTURE_AUTH_PATH + "fixtures/initial_data-auth-fr.json", + LIB_BASE_PATH + "ishtar_common/fixtures/initial_data-fr.json", ] url_name = "account_management" wizard_name = "account_wizard" @@ -3625,7 +3624,7 @@ class CleanMedia(TestCase): # another file exists ] base_dir = os.sep.join( - [settings.ROOT_PATH, "..", "ishtar_common", "tests", "rename"] + [LIB_BASE_PATH, "ishtar_common", "tests", "rename"] ) for name, expected in test_names: name = os.sep.join([base_dir, name]) @@ -3645,7 +3644,7 @@ class CleanMedia(TestCase): ), ] base_dir = os.sep.join( - [settings.ROOT_PATH, "..", "ishtar_common", "tests", "rename"] + [LIB_BASE_PATH, "ishtar_common", "tests", "rename"] ) for name, expected in test_names: name = os.sep.join([base_dir, name]) @@ -3700,7 +3699,7 @@ class StorageTest(TestCase): def test_filesystemstorage(self) -> None: # bug when link to non-existing files image_path = os.path.join( - settings.ROOT_PATH, "..", "ishtar_common", "tests", "test.png" + LIB_BASE_PATH, "ishtar_common", "tests", "test.png" ) doc = models.Document.objects.create( source_type=self.st1, @@ -3892,7 +3891,7 @@ class DocumentTest(TestCase): if not settings.PDFTOPPM_BINARY: return pdf_path = os.path.join( - settings.ROOT_PATH, "..", "ishtar_common", "tests", "simple.pdf" + LIB_BASE_PATH, "ishtar_common", "tests", "simple.pdf" ) doc = models.Document.objects.create( title="Document", @@ -4011,7 +4010,7 @@ class TemplateGenerationTest(TestCase): "complete_idx", "complete_idxy", ] - tpl_label = settings.ROOT_PATH + "../ishtar_common/tests/test-filters-label.odt" + tpl_label = LIB_BASE_PATH + "ishtar_common/tests/test-filters-label.odt" BASE_EXPECTED_KEYS = [ "container_index", "context_record_operation_common_name", @@ -4023,7 +4022,7 @@ class TemplateGenerationTest(TestCase): "complete_idx", "complete_idxy", ] - tpl_base = settings.ROOT_PATH + "../ishtar_common/tests/test-filters-base.odt" + tpl_base = LIB_BASE_PATH + "ishtar_common/tests/test-filters-base.odt" tests = ( (LABEL_EXPECTED_KEYS, tpl_label, models.DocumentTemplate.LABEL_RE), (BASE_EXPECTED_KEYS, tpl_base, models.DocumentTemplate.BASE_RE), |