def test_ocds_json_output_bad_data(json_data): data = SuppliedData.objects.create() data.original_file.save("bad_data.json", ContentFile(json_data)) with pytest.raises(APIException): ocds_json_output( data.upload_dir(), data.original_file.file.name, schema_version="", convert=False, )
def test_ocds_json_output_bad_data(json_data): cove_temp_folder = tempfile.mkdtemp(prefix="lib-cove-ocds-tests-", dir=tempfile.gettempdir()) file_path = os.path.join(cove_temp_folder, "bad_data.json") with open(file_path, "w") as fp: fp.write(json_data) try: with pytest.raises(APIException): ocds_json_output(cove_temp_folder, file_path, schema_version="", convert=False) finally: shutil.rmtree(cove_temp_folder)
def handle(self, file, *args, **options): super(Command, self).handle(file, *args, **options) schema_version = options.get("schema_version") convert = options.get("convert") version_choices = settings.COVE_CONFIG["schema_version_choices"] if schema_version and schema_version not in version_choices: raise CommandError( "Value for schema version option is not valid. Accepted values: {}" .format(str(list(version_choices.keys())))) try: result = ocds_json_output(self.output_dir, file, schema_version, convert, cache_schema=True) except APIException as e: self.stdout.write(str(e)) sys.exit(1) with open(os.path.join(self.output_dir, "results.json"), "w+") as result_file: json.dump(result, result_file, indent=2, sort_keys=True, cls=SetEncoder)
def handle_package(self, package): cove_temp_folder = tempfile.mkdtemp(prefix='ocdskingfisher-cove-', dir=tempfile.gettempdir()) try: return ocds_json_output(cove_temp_folder, None, None, convert=False, cache_schema=True, file_type='json', json_data=package) finally: shutil.rmtree(cove_temp_folder)
def test_basic_1(): cove_temp_folder = tempfile.mkdtemp(prefix="lib-cove-ocds-tests-", dir=tempfile.gettempdir()) json_filename = os.path.join(basedir, "fixtures", "api", "basic_1.json") results = ocds_json_output(cove_temp_folder, json_filename, schema_version="", convert=False, lib_cove_ocds_config=config) assert results["version_used"] == "1.1" assert results["validation_errors"] == []
def _handle_package(self, package): cove_temp_folder = tempfile.mkdtemp(prefix='ocdskingfisher-cove-', dir=tempfile.gettempdir()) try: output = ocds_json_output( cove_temp_folder, None, None, convert=False, lib_cove_ocds_config=self.libcoveocds_config, file_type='json', json_data=package) output.pop('releases_aggregates', None) output.pop('records_aggregates', None) return output finally: shutil.rmtree(cove_temp_folder)
def handle(self, file, *args, **options): super(Command, self).handle(file, *args, **options) schema_version = options.get('schema_version') convert = options.get('convert') version_choices = settings.COVE_CONFIG['schema_version_choices'] if schema_version and schema_version not in version_choices: raise CommandError('Value for schema version option is not valid. Accepted values: {}'.format( str(list(version_choices.keys())) )) try: result = ocds_json_output(self.output_dir, file, schema_version, convert, cache_schema=True) except APIException as e: self.stdout.write(str(e)) sys.exit(1) with open(os.path.join(self.output_dir, "results.json"), 'w+') as result_file: json.dump(result, result_file, indent=2, sort_keys=True, cls=SetEncoder)
def test_ocds_json_output_bad_data(json_data): data = SuppliedData.objects.create() data.original_file.save('bad_data.json', ContentFile(json_data)) with pytest.raises(APIException): ocds_json_output(data.upload_dir(), data.original_file.file.name, schema_version='', convert=False)