def test_command_drop(monkeypatch, tmpdir): stdin = ['release-package_minimal.json'] database_url = 'sqlite:///{}'.format(tmpdir.join('tmp.db')) run_streaming(monkeypatch, main, ['tabulate', database_url], stdin) actual = run_streaming(monkeypatch, main, ['tabulate', database_url, '--drop'], stdin) assert actual == ''
def test_command_without_sqlite(monkeypatch, caplog): ocdskit.combine.sqlite = False # To check the warning, not the output. run_streaming(monkeypatch, main, ['compile'], ['release-package_minimal.json']) assert len(caplog.records) == 1 assert caplog.records[0].levelname == 'WARNING' assert caplog.records[0].message == 'sqlite3 is unavailable, so the command will run in memory. If input files ' \ 'are too large, the command might exceed available memory.'
def test_command_release_party_id_missing(monkeypatch): data = json.loads(read('release-package_minimal.json')) data['releases'][0]['parties'] = [{'name': 'Acme Inc.'}] del data['version'] stdin = json.dumps(data).encode('utf-8') # Should not raise an error. run_streaming(monkeypatch, main, ['upgrade', '1.0:1.1'], stdin)
def test_command_release_party_roles_str(monkeypatch): data = json.loads(read('release-package_minimal.json')) data['releases'][0]['parties'] = [{'id': '1', 'roles': 'buyer'}] data['releases'][0]['tender'] = {'procuringEntity': {'id': '1'}} del data['version'] stdin = json.dumps(data).encode('utf-8') # Should not raise an error. run_streaming(monkeypatch, main, ['upgrade', '1.0:1.1'], stdin)
def test_command_valid_release_package_url(monkeypatch): url = 'http://standard.open-contracting.org/schema/1__0__3/release-package-schema.json' actual = run_streaming(monkeypatch, main, ['validate', '--schema', url], ['realdata/release-package-1.json']) assert actual == ''
def test_command_array_input(monkeypatch): actual = run_streaming(monkeypatch, main, ['echo'], ['release-packages.json']) assert actual == ( '{"uri":"http://example.com/id/1","publisher":{"name":"Acme"},"publishedDate":"2001-02-03T04:05:07Z","releases":[{"ocid":"ocds-213czf-1","id":"1","date":"2001-02-03T04:05:06Z","tag":["planning"],"initiationType":"tender"}],"version":"1.1"}\n' # noqa: E501 '{"uri":"http://example.com/id/1","publisher":{"name":"Acme"},"publishedDate":"2001-02-03T04:05:07Z","releases":[{"ocid":"ocds-213czf-1","id":"1","date":"2001-02-03T04:05:06Z","tag":["planning"],"initiationType":"tender"}],"version":"1.1"}\n' # noqa: E501 )
def test_command_invalid_record_package(monkeypatch): url = 'https://standard.open-contracting.org/latest/en/record-package-schema.json' actual = run_streaming(monkeypatch, main, ['validate', '--schema', url], ['realdata/record-package-1.json']) assert "item 0: None is not of type 'string' (properties/records/items/properties/compiledRelease/properties/tender/properties/submissionMethod/items/type)" in actual # noqa: E501
def test_command_publisher(monkeypatch): actual = run_streaming( monkeypatch, main, ['combine-record-packages', '--publisher-name', 'Acme Inc.'], ['record-package_minimal.json']) package = json.loads(actual) assert package['publisher']['name'] == 'Acme Inc.'
def test_command_valid_release_package_file(monkeypatch): url = 'file://{}'.format( os.path.realpath( os.path.join('tests', 'fixtures', 'release-package-schema.json'))) actual = run_streaming(monkeypatch, main, ['validate', '--schema', url], ['realdata/release-package-1.json']) assert actual == ''
def test_command_release_field_is_null(pointer, monkeypatch): data = json.loads(read('release_minimal.json')) parts = pointer.split('/') for i, part in enumerate(parts, 1): if i < len(parts): if parts[i] == '0': value = [{}] else: value = {} else: value = None set_pointer(data, '/' + '/'.join(parts[:i]), value) stdin = json.dumps(data).encode('utf-8') # Should not raise an error. run_streaming(monkeypatch, main, ['upgrade', '1.0:1.1'], stdin)
def test_command_package_uri_published_date(monkeypatch): actual = run_streaming(monkeypatch, main, ['compile', '--package', '--uri', 'http://example.com/x.json', '--published-date', '2010-01-01T00:00:00Z', '--version', '1.2'], ['release-package_minimal.json']) package = json.loads(actual) assert package['uri'] == 'http://example.com/x.json' assert package['publishedDate'] == '2010-01-01T00:00:00Z' assert package['version'] == '1.2'
def test_command_package_publisher(monkeypatch): actual = run_streaming(monkeypatch, main, ['compile', '--package', '--publisher-name', 'Acme Inc.', '--publisher-uri', 'http://example.com/', '--publisher-scheme', 'scheme', '--publisher-uid', '12345'], ['release-package_minimal.json']) package = json.loads(actual) assert package['publisher']['name'] == 'Acme Inc.' assert package['publisher']['uri'] == 'http://example.com/' assert package['publisher']['scheme'] == 'scheme' assert package['publisher']['uid'] == '12345'
def test_command_packages(monkeypatch): actual = run_streaming(monkeypatch, main, ['combine-record-packages'], [ 'realdata/record-package_package.json', 'realdata/record-package_package.json' ]) package = json.loads(actual) assert package['packages'] == [ 'http://www.contratosabiertos.cdmx.gob.mx/api/contrato/OCDS-87SD3T-AD-SF-DRM-063-2015', 'http://www.contratosabiertos.cdmx.gob.mx/api/contrato/OCDS-87SD3T-AD-SF-DRM-065-2015', ]
def test_command_record_package(monkeypatch): actual = run_streaming(monkeypatch, main, ['tabulate', 'sqlite://'], ['record-package_minimal.json']) assert actual == ''
def test_command_package_fake(monkeypatch): actual = run_streaming(monkeypatch, main, ['compile', '--package', '--fake'], ['release-package_minimal.json']) package = json.loads(actual) assert package['uri'] == 'placeholder:' assert package['publishedDate'] == '9999-01-01T00:00:00Z'
def test_command_no_check_urls(monkeypatch): actual = run_streaming(monkeypatch, main, ['validate'], ['release-package_urls.json']) assert actual == ''
def test_command_check_urls(monkeypatch): actual = run_streaming(monkeypatch, main, ['validate', '--check-urls'], ['release-package_url-error.json']) assert actual == """HTTP 500 on GET http://httpbin.org/status/500
def test_command_multiline_input(monkeypatch): stdin = b'{\n "releases": [\n {\n "ocid": "x",\n "date": "2001-02-03T00:00:00Z"\n }\n ]\n}' actual = run_streaming(monkeypatch, main, ['echo'], stdin) assert actual == '{"releases":[{"ocid":"x","date":"2001-02-03T00:00:00Z"}]}\n'
def test_command_timeout(monkeypatch): actual = run_streaming(monkeypatch, main, ['validate', '--check-urls', '--timeout', '1'], ['release-package_url-timeout.json']) assert actual == """Timedout on GET http://httpbin.org/delay/3
def test_command(monkeypatch): actual = run_streaming(monkeypatch, main, ['tabulate', 'sqlite://'], ['realdata/release-package-1.json']) assert actual == ''
def test_command(monkeypatch): actual = run_streaming(monkeypatch, main, ['validate'], ['realdata/release-package-1.json']) assert actual == "item 0: 'version' is a required property (required)\n"