summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py73
1 files changed, 34 insertions, 39 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index f676a8300..a00679536 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -182,14 +182,14 @@ class ImportTest(BaseImportTest):
def init_ope_import(self, filename="MCC-operations-example.csv", sep=","):
mcc_operation = ImporterType.objects.get(name="MCC - Opérations")
- mcc_operation_file = open(
- settings.LIB_BASE_PATH + "archaeological_operations/tests/" + filename, "rb"
- )
- file_dict = {
- "imported_file": SimpleUploadedFile(
- mcc_operation_file.name, mcc_operation_file.read()
- )
- }
+ with open(
+ settings.LIB_BASE_PATH + "archaeological_operations/tests/" + filename,
+ "rb") as mcc_operation_file:
+ file_dict = {
+ "imported_file": SimpleUploadedFile(
+ mcc_operation_file.name, mcc_operation_file.read()
+ )
+ }
group, c = TargetKeyGroup.objects.get_or_create(name="My group")
post_dict = {
"importer_type": mcc_operation.pk,
@@ -290,14 +290,13 @@ class ImportTest(BaseImportTest):
def init_parcel_import(self):
self.init_ope()
mcc_parcel = ImporterType.objects.get(name="MCC - Parcelles")
- mcc_file = open(
- settings.LIB_BASE_PATH +
- "archaeological_operations/tests/MCC-parcelles-example.csv",
- "rb",
- )
- file_dict = {
- "imported_file": SimpleUploadedFile(mcc_file.name, mcc_file.read())
- }
+ with open(
+ settings.LIB_BASE_PATH +
+ "archaeological_operations/tests/MCC-parcelles-example.csv",
+ "rb") as mcc_file:
+ file_dict = {
+ "imported_file": SimpleUploadedFile(mcc_file.name, mcc_file.read())
+ }
post_dict = {
"importer_type": mcc_parcel.pk,
"skip_lines": 1,
@@ -320,14 +319,12 @@ class ImportTest(BaseImportTest):
def init_context_record_import(self):
self.init_parcel()
mcc = ImporterType.objects.get(name="MCC - UE")
- mcc_file = open(
- settings.LIB_BASE_PATH + "archaeological_context_records/tests/"
- "MCC-context-records-example.csv",
- "rb",
- )
- file_dict = {
- "imported_file": SimpleUploadedFile(mcc_file.name, mcc_file.read())
- }
+ with open(
+ settings.LIB_BASE_PATH + "archaeological_context_records/tests/"
+ "MCC-context-records-example.csv", "rb") as mcc_file:
+ file_dict = {
+ "imported_file": SimpleUploadedFile(mcc_file.name, mcc_file.read())
+ }
post_dict = {
"importer_type": mcc.pk,
"skip_lines": 1,
@@ -817,15 +814,14 @@ class ImportDocumentTest(ImportTest, TestCase):
target="title", formater_type_id=formater.pk, column_id=col.pk
)
- doc_import_file = open(
- settings.LIB_BASE_PATH + "archaeological_operations/tests/" + filename, "rb"
- )
-
- file_dict = {
- "imported_file": SimpleUploadedFile(
- doc_import_file.name, doc_import_file.read()
- )
- }
+ with open(
+ settings.LIB_BASE_PATH + "archaeological_operations/tests/" + filename,
+ "rb") as doc_import_file:
+ file_dict = {
+ "imported_file": SimpleUploadedFile(
+ doc_import_file.name, doc_import_file.read()
+ )
+ }
group, c = TargetKeyGroup.objects.get_or_create(name="My group")
post_dict = {
@@ -4375,12 +4371,11 @@ class RegisterTest(TestCase, OperationInitTest):
self.assertEqual(json.loads(response.content.decode())["recordsTotal"], 1)
def test_document_generation(self):
- tpl = open(
- settings.LIB_BASE_PATH +
- "archaeological_operations/tests/document_reference.odt",
- "rb",
- )
- template = SimpleUploadedFile(tpl.name, tpl.read())
+ with open(
+ settings.LIB_BASE_PATH +
+ "archaeological_operations/tests/document_reference.odt",
+ "rb") as tpl:
+ template = SimpleUploadedFile(tpl.name, tpl.read())
model, __ = ImporterModel.objects.get_or_create(
klass="archaeological_operations.models.AdministrativeAct"
)