Fix backend tests for custom_fields
This commit is contained in:
parent
df973922c3
commit
e399d4f8d3
@ -30,6 +30,7 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
|||||||
("url", "Wikipedia Link"),
|
("url", "Wikipedia Link"),
|
||||||
("date", "Invoiced Date"),
|
("date", "Invoiced Date"),
|
||||||
("integer", "Invoice #"),
|
("integer", "Invoice #"),
|
||||||
|
("boolean", "Is Active"),
|
||||||
]:
|
]:
|
||||||
resp = self.client.post(
|
resp = self.client.post(
|
||||||
self.ENDPOINT,
|
self.ENDPOINT,
|
||||||
@ -53,21 +54,66 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
|||||||
checksum="123",
|
checksum="123",
|
||||||
mime_type="application/pdf",
|
mime_type="application/pdf",
|
||||||
)
|
)
|
||||||
custom_field = CustomField.objects.create(
|
custom_field_string = CustomField.objects.create(
|
||||||
name="Test Custom Field",
|
name="Test Custom Field String",
|
||||||
data_type=CustomField.FieldDataType.STRING,
|
data_type=CustomField.FieldDataType.STRING,
|
||||||
)
|
)
|
||||||
|
custom_field_date = CustomField.objects.create(
|
||||||
|
name="Test Custom Field Date",
|
||||||
|
data_type=CustomField.FieldDataType.DATE,
|
||||||
|
)
|
||||||
|
custom_field_int = CustomField.objects.create(
|
||||||
|
name="Test Custom Field Int",
|
||||||
|
data_type=CustomField.FieldDataType.INT,
|
||||||
|
)
|
||||||
|
custom_field_boolean = CustomField.objects.create(
|
||||||
|
name="Test Custom Field Boolean",
|
||||||
|
data_type=CustomField.FieldDataType.BOOL,
|
||||||
|
)
|
||||||
|
custom_field_url = CustomField.objects.create(
|
||||||
|
name="Test Custom Field Url",
|
||||||
|
data_type=CustomField.FieldDataType.URL,
|
||||||
|
)
|
||||||
|
|
||||||
resp = self.client.patch(
|
resp = self.client.patch(
|
||||||
f"/api/documents/{doc.id}/",
|
f"/api/documents/{doc.id}/",
|
||||||
data={
|
data={
|
||||||
"custom_fields": [
|
"custom_fields": [
|
||||||
{
|
{
|
||||||
"parent": {
|
"field": {
|
||||||
"id": custom_field.id,
|
"id": custom_field_string.id,
|
||||||
|
"name": custom_field_string.name,
|
||||||
},
|
},
|
||||||
"value": "test value",
|
"value": "test value",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"field": {
|
||||||
|
"id": custom_field_date.id,
|
||||||
|
"name": custom_field_date.name,
|
||||||
|
},
|
||||||
|
"value": "2023-10-31",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": {
|
||||||
|
"id": custom_field_int.id,
|
||||||
|
"name": custom_field_int.name,
|
||||||
|
},
|
||||||
|
"value": 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": {
|
||||||
|
"id": custom_field_boolean.id,
|
||||||
|
"name": custom_field_boolean.name,
|
||||||
|
},
|
||||||
|
"value": True,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": {
|
||||||
|
"id": custom_field_url.id,
|
||||||
|
"name": custom_field_url.name,
|
||||||
|
},
|
||||||
|
"value": "https://example.com",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
format="json",
|
format="json",
|
||||||
@ -75,8 +121,5 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
doc.refresh_from_db()
|
doc.refresh_from_db()
|
||||||
from pprint import pprint
|
self.assertEqual(len(doc.custom_fields.all()), 5)
|
||||||
|
self.assertEqual(doc.custom_fields.first().value, "test value")
|
||||||
for item in doc.custom_fields.all():
|
|
||||||
pprint(item)
|
|
||||||
self.assertFalse(True)
|
|
||||||
|
@ -153,7 +153,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
manifest = self._do_export(use_filename_format=use_filename_format)
|
manifest = self._do_export(use_filename_format=use_filename_format)
|
||||||
|
|
||||||
self.assertEqual(len(manifest), 164)
|
self.assertEqual(len(manifest), 194)
|
||||||
|
|
||||||
# dont include consumer or AnonymousUser users
|
# dont include consumer or AnonymousUser users
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -247,7 +247,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
self.assertEqual(Document.objects.get(id=self.d4.id).title, "wow_dec")
|
self.assertEqual(Document.objects.get(id=self.d4.id).title, "wow_dec")
|
||||||
self.assertEqual(GroupObjectPermission.objects.count(), 1)
|
self.assertEqual(GroupObjectPermission.objects.count(), 1)
|
||||||
self.assertEqual(UserObjectPermission.objects.count(), 1)
|
self.assertEqual(UserObjectPermission.objects.count(), 1)
|
||||||
self.assertEqual(Permission.objects.count(), 120)
|
self.assertEqual(Permission.objects.count(), 144)
|
||||||
messages = check_sanity()
|
messages = check_sanity()
|
||||||
# everything is alright after the test
|
# everything is alright after the test
|
||||||
self.assertEqual(len(messages), 0)
|
self.assertEqual(len(messages), 0)
|
||||||
@ -676,15 +676,15 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
os.path.join(self.dirs.media_dir, "documents"),
|
os.path.join(self.dirs.media_dir, "documents"),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(ContentType.objects.count(), 30)
|
self.assertEqual(ContentType.objects.count(), 36)
|
||||||
self.assertEqual(Permission.objects.count(), 120)
|
self.assertEqual(Permission.objects.count(), 144)
|
||||||
|
|
||||||
manifest = self._do_export()
|
manifest = self._do_export()
|
||||||
|
|
||||||
with paperless_environment():
|
with paperless_environment():
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
len(list(filter(lambda e: e["model"] == "auth.permission", manifest))),
|
len(list(filter(lambda e: e["model"] == "auth.permission", manifest))),
|
||||||
120,
|
144,
|
||||||
)
|
)
|
||||||
# add 1 more to db to show objects are not re-created by import
|
# add 1 more to db to show objects are not re-created by import
|
||||||
Permission.objects.create(
|
Permission.objects.create(
|
||||||
@ -692,7 +692,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
codename="test_perm",
|
codename="test_perm",
|
||||||
content_type_id=1,
|
content_type_id=1,
|
||||||
)
|
)
|
||||||
self.assertEqual(Permission.objects.count(), 121)
|
self.assertEqual(Permission.objects.count(), 145)
|
||||||
|
|
||||||
# will cause an import error
|
# will cause an import error
|
||||||
self.user.delete()
|
self.user.delete()
|
||||||
@ -701,5 +701,5 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
with self.assertRaises(IntegrityError):
|
with self.assertRaises(IntegrityError):
|
||||||
call_command("document_importer", "--no-progress-bar", self.target)
|
call_command("document_importer", "--no-progress-bar", self.target)
|
||||||
|
|
||||||
self.assertEqual(ContentType.objects.count(), 30)
|
self.assertEqual(ContentType.objects.count(), 36)
|
||||||
self.assertEqual(Permission.objects.count(), 121)
|
self.assertEqual(Permission.objects.count(), 145)
|
||||||
|
@ -1170,8 +1170,8 @@ class RemoteVersionView(GenericAPIView):
|
|||||||
remote_json = json.loads(remote)
|
remote_json = json.loads(remote)
|
||||||
remote_version = remote_json["tag_name"]
|
remote_version = remote_json["tag_name"]
|
||||||
# Basically PEP 616 but that only went in 3.9
|
# Basically PEP 616 but that only went in 3.9
|
||||||
if remote_version.startswith("ngx"):
|
if remote_version.startswith("ngx-"):
|
||||||
remote_version = remote_version[len("ngx") :]
|
remote_version = remote_version[len("ngx-") :]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.debug("An error occurred parsing remote version json")
|
logger.debug("An error occurred parsing remote version json")
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user