Beispiel #1
0
async def test_create_instance_missing_schema(jp_fetch, namespace_location):
    """Attempt to create an instance using an invalid schema """

    missing_schema = copy.deepcopy(valid_metadata_json)
    missing_schema['name'] = 'missing_schema'
    missing_schema['schema_name'] = 'missing_schema'
    missing_schema.pop('display_name')
    body = json.dumps(missing_schema)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       body=body,
                       method='POST')
    assert expected_http_error(e, 404)

    # Ensure instance was not created.  Can't use REST here since it will correctly trigger 404
    # even though an instance was created and not removed due to failure to validate (due to
    # missing schema).  Fixed by trapping the FileNotFoundError raised due to no schema.
    assert not os.path.exists(
        os.path.join(namespace_location, 'missing_schema.json'))

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE,
                       'missing_schema')
    assert expected_http_error(e, 404)
Beispiel #2
0
async def test_delete_instance(jp_fetch, namespace_location, setup_data):
    """Create a simple instance - not conflicting with factory instances and delete it. """

    # First, attempt to delete non-existent resource, exception expected.
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'missing',
                       method='DELETE')
    assert expected_http_error(e, 404)

    create_json_file(namespace_location, 'valid.json', valid_metadata_json)

    r = await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'valid',
                       method='DELETE')
    assert r.code == 204

    # Confirm deletion
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'valid',
                       method='DELETE')
    assert expected_http_error(e, 404)
Beispiel #3
0
async def test_bogus_schema(jp_fetch):
    # Validate missing is not found

    # Remove self.request (and other 'self.' prefixes) once transition to jupyter_server occurs
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'schema', 'bogus')
    assert expected_http_error(e, 404)
Beispiel #4
0
async def test_invalid_update(jp_fetch, namespace_location):
    """Update a simple instance with invalid metadata. """

    # Create an instance, then update with invalid metadata
    create_json_file(namespace_location, 'update_bad_md.json',
                     valid_metadata_json)

    # Fetch it to get the valid instance
    r = await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE,
                       'update_bad_md')
    assert r.code == 200
    instance = json.loads(r.body.decode())

    # Now attempt the update with bad metadata and ensure previous still exists
    valid2 = copy.deepcopy(valid_metadata_json)
    valid2['name'] = 'valid'
    valid2['metadata']['number_range_test'] = 42
    body2 = json.dumps(valid2)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'update_bad_md',
                       body=body2,
                       method='PUT')
    assert expected_http_error(e, 400)

    # Fetch again and ensure it matches the previous instance
    r = await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE,
                       'update_bad_md')
    assert r.code == 200
    instance2 = json.loads(r.body.decode())
    assert instance2 == instance
Beispiel #5
0
async def test_create_hierarchy_instance(jp_fetch, setup_hierarchy):
    """Attempts to create an instance from one in the hierarchy. """

    byo_instance = copy.deepcopy(byo_metadata_json)
    byo_instance['display_name'] = 'user'
    byo_instance['name'] = 'byo_2'
    body = json.dumps(byo_instance)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       body=body,
                       method='POST')
    assert expected_http_error(e, 409)

    # Confirm the instance was not changed
    r = await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE)
    assert r.code == 200
    metadata = json.loads(r.body.decode())
    assert isinstance(metadata, dict)
    assert len(metadata) == 1
    instances = metadata[METADATA_TEST_NAMESPACE]
    assert len(instances) == 3
    assert isinstance(instances, list)
    byo_2 = get_instance(instances, 'name', 'byo_2')
    assert byo_2['display_name'] == 'factory'
Beispiel #6
0
async def test_bogus_namespace(jp_fetch, bogus_location):
    # Validate missing is not found.  Remove the bogus location to ensure its not created
    shutil.rmtree(bogus_location)
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'metadata', 'bogus', 'missing')

    assert expected_http_error(e, 400)
    assert not os.path.exists(bogus_location)
Beispiel #7
0
async def test_create_invalid_instance(jp_fetch):
    """Create a simple instance - not conflicting with factory instances. """

    invalid = copy.deepcopy(invalid_metadata_json)
    invalid['name'] = 'invalid'
    body = json.dumps(invalid)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       body=body,
                       method='POST')
    assert expected_http_error(e, 400)
Beispiel #8
0
async def test_update_hierarchy_instance(jp_fetch, setup_hierarchy):
    """Update a simple instance - that's conflicting with factory instances. """

    # Do not name intentionally, since this is an update
    byo_instance = copy.deepcopy(byo_metadata_json)
    byo_instance['display_name'] = 'user'
    byo_instance['metadata']['number_range_test'] = 7
    body = json.dumps(byo_instance)

    # Because this is considered an update, replacement is enabled.
    r = await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'byo_2',
                       body=body,
                       method='PUT')
    assert r.code == 200

    # Confirm the instances and ensure byo_2 is in USER area
    r = await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE)
    assert r.code == 200
    metadata = json.loads(r.body.decode())
    assert isinstance(metadata, dict)
    assert len(metadata) == 1
    instances = metadata[METADATA_TEST_NAMESPACE]
    assert len(instances) == 3
    assert isinstance(instances, list)
    byo_2 = get_instance(instances, 'name', 'byo_2')
    assert byo_2['schema_name'] == byo_metadata_json['schema_name']
    assert byo_2['metadata']['number_range_test'] == 7

    # Attempt to rename the resource, exception expected.
    byo_2['name'] = 'byo_2_renamed'
    body = json.dumps(byo_2)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'byo_2',
                       body=body,
                       method='PUT')
    assert expected_http_error(e, 400)

    # Confirm no update occurred
    r = await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE, 'byo_2')
    assert r.code == 200
    instance = json.loads(r.body.decode())
    assert instance['name'] == 'byo_2'
Beispiel #9
0
async def test_update_non_existent(jp_fetch, namespace_location):
    """Attempt to update a non-existent instance. """

    # Try to update a non-existent instance - 404 expected...
    valid = copy.deepcopy(valid_metadata_json)
    valid['name'] = 'valid'
    valid['metadata']['number_range_test'] = 7
    body = json.dumps(valid)

    # Update (non-existent) instance
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'valid',
                       body=body,
                       method='PUT')
    assert expected_http_error(e, 404)
Beispiel #10
0
async def test_delete_hierarchy_instance(jp_fetch, namespace_location,
                                         setup_hierarchy):
    """Create a simple instance - that conflicts with factory instances and delete it only if local. """

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'byo_2',
                       method='DELETE')
    assert expected_http_error(e, 403)

    # create local instance, delete should succeed
    create_json_file(namespace_location, 'byo_2.json', byo_metadata_json)

    r = await jp_fetch('elyra',
                       'metadata',
                       METADATA_TEST_NAMESPACE,
                       'byo_2',
                       method='DELETE')
    assert r.code == 204
Beispiel #11
0
async def test_invalid_instance(jp_fetch, setup_data):
    # Validate invalid throws 404 with validation message
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE, 'invalid')
    assert expected_http_error(e, 400)
Beispiel #12
0
async def test_missing_runtimes_schema(jp_fetch):
    # Validate missing is not found
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'schema', 'runtimes', 'missing')
    assert expected_http_error(e, 404)
Beispiel #13
0
async def test_missing_instance(jp_fetch, setup_data):
    # Validate missing is not found
    name = 'missing'
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'metadata', METADATA_TEST_NAMESPACE, name)
    assert expected_http_error(e, 404)
Beispiel #14
0
async def test_invalid_config_resource(jp_fetch):
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'pipeline', 'config', 'invalid', method='GET')

    assert expected_http_error(e, 400)
Beispiel #15
0
async def test_file_is_not_directory(jp_fetch, create_directory,
                                     directory_name):
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'contents/properties', directory_name)
    assert expected_http_error(e, 400)
Beispiel #16
0
async def test_file_not_found(jp_fetch):
    filepath = "nofile.py"

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch('elyra', 'contents/properties', filepath)
    assert expected_http_error(e, 404)