コード例 #1
0
    def test_flatten_xlsx_successful(self, client, upload_obj_validated):
        _, flatten_id = create_flatten(client, upload_obj_validated,
                                       self.url_prefix)
        flatten_data(flatten_id, model=self.model)

        flatten = Flatten.objects.get(id=flatten_id)
        assert flatten.status == Flatten.COMPLETED
        assert flatten.file.path.startswith(settings.MEDIA_ROOT)
        assert flatten.file.path.endswith(Flatten.XLSX)
コード例 #2
0
    def test_no_left_space(self, client, upload_obj_validated, mocker):
        _, flatten_id = create_flatten(client, upload_obj_validated,
                                       self.url_prefix)
        mocked_flattener = mocker.patch(
            "core.tasks.FileFlattener.flatten_file")
        mocked_flattener.side_effect = OSError(errno.ENOSPC, "No left space.")
        flatten_data(flatten_id, model=self.model)

        flatten = Flatten.objects.get(id=flatten_id)
        assert flatten.status == Flatten.FAILED
        assert flatten.error == "Currently, the space limit was reached. Please try again later."
コード例 #3
0
    def test_flatten_handle_type_error(self, client, upload_obj_validated,
                                       mocker):
        _, flatten_id = create_flatten(client, upload_obj_validated,
                                       self.url_prefix)
        mocked_get_options = mocker.patch("core.tasks.get_flatten_options")
        exc_message = "TypeError message"
        mocked_get_options.side_effect = TypeError(exc_message)
        flatten_data(flatten_id, model=self.model)

        flatten = Flatten.objects.get(id=flatten_id)
        assert flatten.status == Flatten.FAILED
        assert flatten.error == exc_message
コード例 #4
0
 def test_flatten_not_found(self, mocker):
     mocked_logger = mocker.patch("core.tasks.logger")
     flatten_id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
     flatten_data(flatten_id, model=self.model)
     mocked_logger.info.assert_called_once_with(
         "Flatten %s for %s model not found" % (flatten_id, self.model),
         extra={
             "MESSAGE_ID": "flatten_not_found",
             "MODEL": self.model,
             "FLATTEN_ID": flatten_id,
             "TASK": "flatten_data",
         },
     )
コード例 #5
0
    def test_flatten_non_registered_model(self, client, upload_obj_validated,
                                          mocker):
        _, flatten_id = create_flatten(client, upload_obj_validated,
                                       self.url_prefix)
        model = "NewModel"
        mocked_logger = mocker.patch("core.tasks.logger")
        flatten_data(flatten_id, model=model)

        mocked_logger.info.assert_called_once_with(
            "Model %s not registered in getters" % model,
            extra={
                "MESSAGE_ID": "model_not_registered",
                "MODEL": model,
                "TASK": "flatten_data",
                "FLATTEN_ID": flatten_id,
            },
        )
コード例 #6
0
    def test_flatten_csv_successful_lite(self, client, upload_obj_validated):
        selection_id, flatten_id = create_flatten(client,
                                                  upload_obj_validated,
                                                  prefix=self.url_prefix,
                                                  export_format=Flatten.CSV,
                                                  kind="ocds_lite")
        selection = DataSelection.objects.get(id=selection_id)
        assert selection.kind == selection.OCDS_LITE
        assert selection.headings_type == selection.EN_USER_FRIENDLY
        tables = selection.tables.all()
        assert len(tables) == 3

        flatten_data(flatten_id, model=self.model)

        flatten = Flatten.objects.get(id=flatten_id)
        assert flatten.status == Flatten.COMPLETED
        assert flatten.file.path.startswith(settings.MEDIA_ROOT)
        assert flatten.file.path.endswith(".zip")
コード例 #7
0
    def test_task_flatten(self, event_loop, client, upload_obj_validated,
                          mocked_request):
        prefix = "/uploads/" if not settings.API_PREFIX else f"/{settings.API_PREFIX}uploads/"
        _, flatten_id = create_flatten(client,
                                       upload_obj_validated,
                                       prefix=prefix)
        application = URLRouter([
            re_path(r"ws/api/(?P<upload_id>[0-9a-f-]+)/$",
                    ValidationConsumer.as_asgi())
        ])
        communicator = WebsocketCommunicator(
            application, f"/ws/api/{upload_obj_validated.id}/")
        event_loop.run_until_complete(communicator.connect())
        flatten_data(flatten_id, model="Upload")
        message = event_loop.run_until_complete(communicator.receive_from())
        event_loop.run_until_complete(communicator.disconnect())
        message = json.loads(message)

        assert message["type"] == "task.flatten"
        assert message["flatten"]["id"] == flatten_id
        assert message["flatten"]["status"] == "processing"
コード例 #8
0
    def test_flatten_csv_successful(self, client, upload_obj_validated):
        selection_id, flatten_id = create_flatten(client,
                                                  upload_obj_validated,
                                                  prefix=self.url_prefix,
                                                  export_format=Flatten.CSV)
        selection = DataSelection.objects.get(id=selection_id)
        table1 = selection.tables.all()[0]
        table1.split = True
        table1.heading = "New Table Name"
        table1.save(update_fields=["split", "heading"])

        table2 = selection.tables.all()[1]
        table2.include = False
        table2.save(update_fields=["include"])

        flatten_data(flatten_id, model=self.model)

        flatten = Flatten.objects.get(id=flatten_id)
        assert flatten.status == Flatten.COMPLETED
        assert flatten.file.path.startswith(settings.MEDIA_ROOT)
        assert flatten.file.path.endswith(".zip")