Esempio n. 1
0
    def test_unregistered_model(self, url_obj):
        url_obj = Url.objects.get(id=url_obj.id)
        assert url_obj.validation.is_valid is None

        validate_data(url_obj.id, model="SomeNew")
        url_obj = Url.objects.get(id=url_obj.id)
        assert url_obj.validation.is_valid is None
Esempio n. 2
0
    def test_url_success(self, url_obj_w_files):
        url_obj_w_files = Url.objects.get(id=url_obj_w_files.id)
        assert url_obj_w_files.validation.is_valid is None
        assert not url_obj_w_files.available_tables

        validate_data(url_obj_w_files.id, model="Url")

        url_obj_w_files = Url.objects.get(id=url_obj_w_files.id)
        assert url_obj_w_files.validation.is_valid
        assert len(url_obj_w_files.available_tables) == 8
        assert url_obj_w_files.available_tables[0]["name"] == "parties"
        assert url_obj_w_files.available_tables[0]["rows"] == 8
        assert url_obj_w_files.available_tables[0]["arrays"] == {}
        assert url_obj_w_files.available_tables[0]["available_data"][
            "columns"]["total"] == 26
        assert url_obj_w_files.available_tables[0]["available_data"][
            "columns"]["available"] == 21
        assert url_obj_w_files.available_tables[0]["available_data"][
            "columns"]["additional"] == ["/parties/test"]
        assert set(url_obj_w_files.available_tables[0]["available_data"]
                   ["columns"]["missing_data"]) == {
                       "/parties/identifier/uri",
                       "/parties/additionalIdentifiers/0/id",
                       "/parties/additionalIdentifiers/0/legalName",
                       "/parties/additionalIdentifiers/0/scheme",
                       "/parties/additionalIdentifiers/0/uri",
                   }
Esempio n. 3
0
 def test_handle_exception(self, upload_obj, mocker):
     mocked_logger = mocker.patch("core.tasks.logger")
     mocked_open = mocker.patch("core.tasks.open")
     mocked_open.side_effect = Exception("Open fails")
     validate_data(upload_obj.id, model=self.model)
     assert mocked_logger.exception.call_count == 1
     datasource = Upload.objects.get(id=upload_obj.id)
     assert not datasource.validation.is_valid
     assert datasource.validation.errors == f"Error while validating data `{str(mocked_open.side_effect)}`"
Esempio n. 4
0
    def test_not_json_file(self, upload_obj):
        with open(upload_obj.file.path, "w") as f:
            f.write("some txt file")

        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert not upload_obj.validation.is_valid

        validate_data(upload_obj.id, model="Upload")
        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert not upload_obj.validation.is_valid
Esempio n. 5
0
    def test_upload_success(self, upload_obj):
        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert upload_obj.validation.is_valid is None
        assert not upload_obj.available_tables

        validate_data(upload_obj.id, model="Upload")

        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert upload_obj.validation.is_valid
        assert len(upload_obj.available_tables) == 8
Esempio n. 6
0
 def test_task_validate(self, event_loop, upload_obj):
     application = URLRouter([
         re_path(r"ws/api/(?P<upload_id>[0-9a-f-]+)/$",
                 ValidationConsumer.as_asgi())
     ])
     communicator = WebsocketCommunicator(application,
                                          f"/ws/api/{upload_obj.id}/")
     event_loop.run_until_complete(communicator.connect())
     validate_data(str(upload_obj.id), model="Upload")
     message = event_loop.run_until_complete(communicator.receive_from())
     event_loop.run_until_complete(communicator.disconnect())
     assert (json.loads(message).keys()) == {"datasource", "type"}
Esempio n. 7
0
    def test_no_left_space(self, upload_obj, mocker):
        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert upload_obj.validation.is_valid is None
        assert not upload_obj.available_tables

        mocked_dump = mocker.patch("core.tasks.FileAnalyzer")
        mocked_dump().spec.dump.side_effect = OSError(errno.ENOSPC,
                                                      "No left space.")
        validate_data(upload_obj.id, model="Upload")

        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert not upload_obj.validation.is_valid
        assert upload_obj.validation.errors == "Currently, the space limit was reached. Please try again later."
Esempio n. 8
0
 def test_not_found(self, mocker):
     mocked_logger = mocker.patch("core.tasks.logger")
     obj_id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
     model = "Upload"
     validate_data(obj_id, model=model)
     mocked_logger.info.assert_called_once_with(
         "Datasource %s %s not found" % (self.model, obj_id),
         extra={
             "MESSAGE_ID": "datasource_not_found",
             "MODEL": model,
             "DATASOURCE_ID": obj_id,
             "TASK": "validate_data",
         },
     )