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"),
|
||||
("date", "Invoiced Date"),
|
||||
("integer", "Invoice #"),
|
||||
("boolean", "Is Active"),
|
||||
]:
|
||||
resp = self.client.post(
|
||||
self.ENDPOINT,
|
||||
@ -53,21 +54,66 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
||||
checksum="123",
|
||||
mime_type="application/pdf",
|
||||
)
|
||||
custom_field = CustomField.objects.create(
|
||||
name="Test Custom Field",
|
||||
custom_field_string = CustomField.objects.create(
|
||||
name="Test Custom Field 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(
|
||||
f"/api/documents/{doc.id}/",
|
||||
data={
|
||||
"custom_fields": [
|
||||
{
|
||||
"parent": {
|
||||
"id": custom_field.id,
|
||||
"field": {
|
||||
"id": custom_field_string.id,
|
||||
"name": custom_field_string.name,
|
||||
},
|
||||
"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",
|
||||
@ -75,8 +121,5 @@ class TestCustomField(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||
|
||||
doc.refresh_from_db()
|
||||
from pprint import pprint
|
||||
|
||||
for item in doc.custom_fields.all():
|
||||
pprint(item)
|
||||
self.assertFalse(True)
|
||||
self.assertEqual(len(doc.custom_fields.all()), 5)
|
||||
self.assertEqual(doc.custom_fields.first().value, "test value")
|
||||
|
@ -153,7 +153,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
|
||||
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
|
||||
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(GroupObjectPermission.objects.count(), 1)
|
||||
self.assertEqual(UserObjectPermission.objects.count(), 1)
|
||||
self.assertEqual(Permission.objects.count(), 120)
|
||||
self.assertEqual(Permission.objects.count(), 144)
|
||||
messages = check_sanity()
|
||||
# everything is alright after the test
|
||||
self.assertEqual(len(messages), 0)
|
||||
@ -676,15 +676,15 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
os.path.join(self.dirs.media_dir, "documents"),
|
||||
)
|
||||
|
||||
self.assertEqual(ContentType.objects.count(), 30)
|
||||
self.assertEqual(Permission.objects.count(), 120)
|
||||
self.assertEqual(ContentType.objects.count(), 36)
|
||||
self.assertEqual(Permission.objects.count(), 144)
|
||||
|
||||
manifest = self._do_export()
|
||||
|
||||
with paperless_environment():
|
||||
self.assertEqual(
|
||||
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
|
||||
Permission.objects.create(
|
||||
@ -692,7 +692,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
codename="test_perm",
|
||||
content_type_id=1,
|
||||
)
|
||||
self.assertEqual(Permission.objects.count(), 121)
|
||||
self.assertEqual(Permission.objects.count(), 145)
|
||||
|
||||
# will cause an import error
|
||||
self.user.delete()
|
||||
@ -701,5 +701,5 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
with self.assertRaises(IntegrityError):
|
||||
call_command("document_importer", "--no-progress-bar", self.target)
|
||||
|
||||
self.assertEqual(ContentType.objects.count(), 30)
|
||||
self.assertEqual(Permission.objects.count(), 121)
|
||||
self.assertEqual(ContentType.objects.count(), 36)
|
||||
self.assertEqual(Permission.objects.count(), 145)
|
||||
|
@ -1170,8 +1170,8 @@ class RemoteVersionView(GenericAPIView):
|
||||
remote_json = json.loads(remote)
|
||||
remote_version = remote_json["tag_name"]
|
||||
# Basically PEP 616 but that only went in 3.9
|
||||
if remote_version.startswith("ngx"):
|
||||
remote_version = remote_version[len("ngx") :]
|
||||
if remote_version.startswith("ngx-"):
|
||||
remote_version = remote_version[len("ngx-") :]
|
||||
except ValueError:
|
||||
logger.debug("An error occurred parsing remote version json")
|
||||
except urllib.error.URLError:
|
||||
|
Loading…
x
Reference in New Issue
Block a user