Esempio n. 1
0
async def test_malformed_refresh(jp_fetch):
    # Ensure that providing the endpoints with a bad body generate 400 errors.
    refresh = {"no-action": "refresh"}
    body = json.dumps(refresh)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch("elyra",
                       "pipeline",
                       "components",
                       "cache",
                       body=body,
                       method="PUT")
    assert expected_http_error(e, 400)

    refresh = {"action": "no-refresh"}
    body = json.dumps(refresh)

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch("elyra",
                       "pipeline",
                       "components",
                       "cache",
                       body=body,
                       method="PUT")
    assert expected_http_error(e, 400)
Esempio n. 2
0
async def test_delete_instance(jp_fetch, schemaspace_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_SCHEMASPACE,
                       "missing",
                       method="DELETE")
    assert expected_http_error(e, 404)

    create_json_file(schemaspace_location, "valid.json", valid_metadata_json)

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

    # Confirm deletion
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch("elyra",
                       "metadata",
                       METADATA_TEST_SCHEMASPACE,
                       "valid",
                       method="DELETE")
    assert expected_http_error(e, 404)
Esempio n. 3
0
async def test_create_instance_missing_schema(jp_fetch, schemaspace_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_SCHEMASPACE,
                       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(schemaspace_location, "missing_schema.json"))

    with pytest.raises(HTTPClientError) as e:
        await jp_fetch("elyra", "metadata", METADATA_TEST_SCHEMASPACE,
                       "missing_schema")
    assert expected_http_error(e, 404)
Esempio n. 4
0
async def test_invalid_update(jp_fetch, schemaspace_location):
    """Update a simple instance with invalid metadata."""

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

    # Fetch it to get the valid instance
    r = await jp_fetch("elyra", "metadata", METADATA_TEST_SCHEMASPACE,
                       "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_SCHEMASPACE_ID,
                       "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_SCHEMASPACE_ID,
                       "update_bad_md")
    assert r.code == 200
    instance2 = json.loads(r.body.decode())
    assert instance2 == instance
Esempio n. 5
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)
Esempio n. 6
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_SCHEMASPACE,
                       body=body,
                       method="POST")
    assert expected_http_error(e, 409)

    # Confirm the instance was not changed
    r = await jp_fetch("elyra", "metadata", METADATA_TEST_SCHEMASPACE)
    assert r.code == 200
    metadata = json.loads(r.body.decode())
    assert isinstance(metadata, dict)
    assert len(metadata) == 1
    instances = metadata[METADATA_TEST_SCHEMASPACE]
    assert len(instances) == 3
    assert isinstance(instances, list)
    byo_2 = get_instance(instances, "name", "byo_2")
    assert byo_2["display_name"] == "factory"
Esempio n. 7
0
async def test_double_refresh(jp_fetch):
    # Ensure that attempts to refresh the component cache while another is in progress result in 409

    await cli_catalog_instance(jp_fetch)

    refresh = {"action": "refresh"}
    body = json.dumps(refresh)

    response = await jp_fetch("elyra",
                              "pipeline",
                              "components",
                              "cache",
                              body=body,
                              method="PUT")
    assert response.code == 204
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch("elyra",
                       "pipeline",
                       "components",
                       "cache",
                       body=body,
                       method="PUT")
    assert expected_http_error(e, 409)
    # Give the first refresh attempt a chance to complete and try again to ensure it has
    await asyncio.sleep(2)
    response = await jp_fetch("elyra",
                              "pipeline",
                              "components",
                              "cache",
                              body=body,
                              method="PUT")
    assert response.code == 204
Esempio n. 8
0
async def test_bogus_schemaspace(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)
Esempio n. 9
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_SCHEMASPACE,
                       body=body,
                       method="POST")
    assert expected_http_error(e, 400)
Esempio n. 10
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_SCHEMASPACE,
                       "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_SCHEMASPACE)
    assert r.code == 200
    metadata = json.loads(r.body.decode())
    assert isinstance(metadata, dict)
    assert len(metadata) == 1
    instances = metadata[METADATA_TEST_SCHEMASPACE]
    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_SCHEMASPACE,
                       "byo_2",
                       body=body,
                       method="PUT")
    assert expected_http_error(e, 400)

    # Confirm no update occurred
    r = await jp_fetch("elyra", "metadata", METADATA_TEST_SCHEMASPACE, "byo_2")
    assert r.code == 200
    instance = json.loads(r.body.decode())
    assert instance["name"] == "byo_2"
Esempio n. 11
0
async def test_update_non_existent(jp_fetch, schemaspace_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_SCHEMASPACE,
                       "valid",
                       body=body,
                       method="PUT")
    assert expected_http_error(e, 404)
Esempio n. 12
0
async def test_delete_hierarchy_instance(jp_fetch, schemaspace_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_SCHEMASPACE,
                       "byo_2",
                       method="DELETE")
    assert expected_http_error(e, 403)

    # create local instance, delete should succeed
    create_json_file(schemaspace_location, "byo_2.json", byo_metadata_json)

    r = await jp_fetch("elyra",
                       "metadata",
                       METADATA_TEST_SCHEMASPACE,
                       "byo_2",
                       method="DELETE")
    assert r.code == 204
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
0
async def test_get_missing_schemaspace_info(jp_fetch):
    with pytest.raises(HTTPClientError) as e:
        await jp_fetch("elyra", "schemaspace", "missing-schemaspace")
    assert expected_http_error(e, 404)
Esempio n. 16
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_SCHEMASPACE,
                       "invalid")
    assert expected_http_error(e, 400)
Esempio n. 17
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)
Esempio n. 18
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_SCHEMASPACE, name)
    assert expected_http_error(e, 404)