- `tags`: Similar to correspondent. Specify this multiple times to
have multiple tags added to the document.
- `owner`: An optional user ID to set as the owner.
-
-The endpoint will immediately return "OK" if the document consumption
-process was started successfully. No additional status information about
-the consumption process itself is available, since that happens in a
-different process.
+- `archive_serial_number`: An optional archive serial number to set.
+
+The endpoint will immediately return HTTP 200 if the document consumption
+process was started successfully, with the UUID of the consumption task
+as the data. No additional status information about
+the consumption process itself is available immediately, since that happens in a
+different process. Querying the tasks endpoint with the returned UUID will
+provide information on the state of the consumption.
## API Versioning
required=False,
)
+ archive_serial_number = serializers.IntegerField(
+ label="ASN",
+ write_only=True,
+ required=False,
+ min_value=Document.ARCHIVE_SERIAL_NUMBER_MIN,
+ max_value=Document.ARCHIVE_SERIAL_NUMBER_MAX,
+ )
+
def validate_document(self, document):
document_data = document.file.read()
mime_type = magic.from_buffer(document_data, mime=True)
import shutil
import uuid
from pathlib import Path
+from typing import Optional
from typing import Type
import dateutil.parser
task_id=None,
override_created=None,
override_owner_id=None,
+ override_archive_serial_num: Optional[int] = None,
):
path = Path(path).resolve()
override_tag_ids=override_tag_ids,
task_id=task_id,
override_created=override_created,
- override_asn=asn,
+ override_asn=override_archive_serial_num or asn,
override_owner_id=override_owner_id,
)
self.assertEqual(kwargs["override_created"], created)
+ @mock.patch("documents.views.consume_file.delay")
+ def test_upload_with_asn(self, m):
+
+ m.return_value = celery.result.AsyncResult(id=str(uuid.uuid4()))
+
+ with open(
+ os.path.join(os.path.dirname(__file__), "samples", "simple.pdf"),
+ "rb",
+ ) as f:
+ response = self.client.post(
+ "/api/documents/post_document/",
+ {"document": f, "archive_serial_number": 500},
+ )
+
+ self.assertEqual(response.status_code, 200)
+
+ m.assert_called_once()
+
+ args, kwargs = m.call_args
+ file_path = Path(args[0])
+ self.assertEqual(file_path.name, "simple.pdf")
+ self.assertIn(Path(settings.SCRATCH_DIR), file_path.parents)
+ self.assertIsNone(kwargs["override_title"])
+ self.assertIsNone(kwargs["override_correspondent_id"])
+ self.assertIsNone(kwargs["override_document_type_id"])
+ self.assertIsNone(kwargs["override_tag_ids"])
+ self.assertEqual(500, kwargs["override_archive_serial_num"])
+
def test_get_metadata(self):
doc = Document.objects.create(
title="test",
self.assertEqual(returned_data["task_file_name"], "anothertest.pdf")
-class TestApiUser(APITestCase):
+class TestApiUser(DirectoriesMixin, APITestCase):
ENDPOINT = "/api/users/"
def setUp(self):
self.assertNotEqual(returned_user2.password, initial_password)
-class TestApiGroup(APITestCase):
+class TestApiGroup(DirectoriesMixin, APITestCase):
ENDPOINT = "/api/groups/"
def setUp(self):
title = serializer.validated_data.get("title")
created = serializer.validated_data.get("created")
owner_id = serializer.validated_data.get("owner")
+ archive_serial_number = serializer.validated_data.get("archive_serial_number")
t = int(mktime(datetime.now().timetuple()))
task_id=task_id,
override_created=created,
override_owner_id=owner_id,
+ override_archive_serial_num=archive_serial_number,
)
return Response(async_task.id)