def test_add_new_artifact_to_model(self, sample_model, test_user_clients, role):
        """
        <b>Description:</b>
        Add artifact file to the model.

        <b>Input data:</b>
        1. Example model existing on models list in model catalog.
        2. User
        3. User role (user or admin)

        <b>Expected results:</b>
        Test passes when artifact is added to the model successfully.

        <b>Steps:</b>
        1. Add artifact to the model.
        2. Verify that added artifact is shown on model's artifacts list.
        """
        client = test_user_clients[role]
        step("Add new artifact to model using {}".format(role))
        new_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, client=client,
                                                     **self.ARTIFACT_METADATA)
        step("Get artifact {} metadata of model {}".format(new_artifact.id, sample_model.id))
        artifact = ModelArtifact.get_artifact(model_id=sample_model.id, artifact_id=new_artifact.id)
        model_artifacts = ScoringEngineModel.get(model_id=sample_model.id).artifacts
        assert artifact in model_artifacts
    def test_artifact_file_has_been_properly_added(self, sample_model, test_user_clients, role):
        """
        <b>Description:</b>
        Added artifact file has been added properly to the model.

        <b>Input data:</b>
        1. Example model existing on models list in model catalog.
        2. User
        3. User role (user or admin)

        <b>Expected results:</b>
        Test passes when added artifact is the same as inserted one.

        <b>Steps:</b>
        1. Add artifact to the model.
        2. Get added artifact from model.
        3. Verify that content of downloaded artifact is correct.
        """
        client = test_user_clients[role]
        step("Add new artifact to model using {}".format(role))
        new_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, client=client, **self.ARTIFACT_METADATA)
        added_file_content = ModelArtifact.get_artifact_file(model_id=sample_model.id, artifact_id=new_artifact.id)
        with open("fixtures/{}".format(self.ARTIFACT_METADATA["filename"]), 'r') as text:
            expected_content = text.read()
        assert added_file_content == expected_content
    def test_delete_artifact_and_file(self, model_with_artifact, test_user_clients, role):
        """
        <b>Description:</b>
        Delete artifact file from model.

        <b>Input data:</b>
        1. Example model with artifact existing on models list in model catalog.
        2. User
        3. User role (user or role)

        <b>Expected results:</b>
        Test passes when artifact file and metadata are deleted from model successfully.

        <b>Steps:</b>
        1. Get artifact id.
        2. Delete artifact file from model.
        3. Try to get artifact file.
        4. Try to get artifact metadata.
        """
        client = test_user_clients[role]
        artifact_id = model_with_artifact.artifacts[0].get("id")
        step("Delete artifact {} of model {} using {}".format(artifact_id, model_with_artifact.id, client))
        ModelArtifact.delete_artifact(model_id=model_with_artifact.id, artifact_id=artifact_id,
                                      client=client)
        assert_raises_http_exception(HttpStatus.CODE_NOT_FOUND, HttpStatus.MSG_NOT_FOUND,
                                     model_catalog_api.get_model_artifact_file, model_id=model_with_artifact.id,
                                     artifact_id=artifact_id)
        assert_raises_http_exception(HttpStatus.CODE_NOT_FOUND, HttpStatus.MSG_NOT_FOUND,
                                     model_catalog_api.get_model_artifact_metadata, model_id=model_with_artifact.id,
                                     artifact_id=artifact_id)
Beispiel #4
0
    def test_get_artifact_file_using_both_clients(self, model_with_artifact,
                                                  admin_client,
                                                  test_org_user_client):
        """
        <b>Description:</b>
        Get artifact file from model using user client with user/admin role.

        <b>Input data:</b>
        1. Example model with artifact existing on models list in model catalog.
        2. User with role user
        3. User with role admin

        <b>Expected results:</b>
        Test passes when both user clients can get artifact file successfully.

        <b>Steps:</b>
        1. Get artifact file using user client.
        2. Get artifact file using admin client.
        3. Compare responses from previous steps.
        """
        artifact_id = model_with_artifact.artifacts[0].get("id")
        step("Get file of artifact {} using user client".format(artifact_id))
        artifact_file = ModelArtifact.get_artifact_file(
            model_id=model_with_artifact.id,
            artifact_id=artifact_id,
            client=test_org_user_client)
        step("Get file of artifact {} using admin client".format(artifact_id))
        expected_content = ModelArtifact.get_artifact_file(
            model_id=model_with_artifact.id,
            artifact_id=artifact_id,
            client=admin_client)
        assert artifact_file == expected_content
    def test_add_new_artifact_to_model_different_actions(self, sample_model, artifact_actions_key, actions):
        """
        <b>Description:</b>
        Add artifact file with action to the model.

        <b>Input data:</b>
        1. Example model existing on models list in model catalog.
        2. Artifact action to verifying.
        3. Available options of artifact action.


        <b>Expected results:</b>
        Test passes when artifact is added to the model with properly action.

        <b>Steps:</b>
        1. Prepare artifact metadata with tested action value.
        2. Add artifact with prepared metadata to the model.
        2. Verify that added artifact has expected actions in metadata.
        """
        action = actions[artifact_actions_key]
        artifact_metadata = self.ARTIFACT_METADATA.copy()
        artifact_metadata["actions"] = action
        step("Add new artifact to model with action {}".format(artifact_actions_key))
        new_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, **artifact_metadata)
        new_artifact_actions = new_artifact.actions
        assert new_artifact_actions == artifact_metadata["actions"]
    def test_cannot_delete_artifact_twice(self, model_with_artifact):
        """
        <b>Description:</b>
        Try to delete artifact twice from model.

        <b>Input data:</b>
        1. Example model with artifact existing on models list in model catalog.

        <b>Expected results:</b>
        Test passes when model catalog returns a 404 http status.

        <b>Steps:</b>
        1. Get artifact id.
        2. Delete artifact from model.
        3. Try to delete the same artifact again.
        """
        artifact_id = model_with_artifact.artifacts[0].get("id")
        step("Delete artifact {} of model {}".format(artifact_id, model_with_artifact.id))
        ModelArtifact.delete_artifact(model_id=model_with_artifact.id, artifact_id=artifact_id)
        step("Try to delete the same artifact from model for the second time")
        assert_raises_http_exception(HttpStatus.CODE_NOT_FOUND, HttpStatus.MSG_NOT_FOUND,
                                     ModelArtifact.delete_artifact, model_id=model_with_artifact.id,
                                     artifact_id=artifact_id)
    def test_can_add_more_than_one_artifacts_to_model(self, sample_model):
        """
        <b>Description:</b>
        Add two artifacts to the one model.

        <b>Input data:</b>
        1. Example model existing on models list in model catalog.

        <b>Expected results:</b>
        Test passes when first and second artifacts are added to the model successfully.

        <b>Steps:</b>
        1. Add first artifact to the model.
        2. Add second artifact to the model.
        3. Verify that both artifacts are shown on model's artifacts list.
        """
        step("Add new artifact to model")
        uploaded_first_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, **self.ARTIFACT_METADATA)
        first_artifact = ModelArtifact.get_artifact(model_id=sample_model.id, artifact_id=uploaded_first_artifact.id)
        step("Try to add second artifact to model")
        uploaded_second_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, **self.ARTIFACT_METADATA)
        second_artifact = ModelArtifact.get_artifact(model_id=sample_model.id, artifact_id=uploaded_second_artifact.id)
        assert first_artifact in ScoringEngineModel.get(model_id=sample_model.id).artifacts
        assert second_artifact in ScoringEngineModel.get(model_id=sample_model.id).artifacts
    def test_can_add_artifact_with_two_actions(self, sample_model):
        """
        <b>Description:</b>
        Added artifact file with two actions to the model.

        <b>Input data:</b>
        1. Example model existing on models list in model catalog.

        <b>Expected results:</b>
        Test passes when added artifact has two actions.

        <b>Steps:</b>
         1. Prepare artifact metadata with two actions.
         2. Add artifact with prepared metadata to the model.
         3. Verify that added artifact has expected actions in metadata.
        """
        step("Try to add artifact with two actions")
        artifact_metadata = self.ARTIFACT_METADATA.copy()
        artifact_metadata["actions"].append(ModelArtifact.ARTIFACT_ACTIONS["publish_tap_scoring_engine"])
        new_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, **artifact_metadata)
        assert sorted(new_artifact.actions) == sorted(artifact_metadata["actions"])
    def test_add_new_artifact_without_actions_filed(self, sample_model):
        """
        <b>Description:</b>
        Add artifact file without action to the model.

        <b>Input data:</b>
        1. Example model existing on models list in model catalog.

        <b>Expected results:</b>
        Test passes when artifact is added to the model successfully and artifact's actions list is empty.

        <b>Steps:</b>
        1. Prepare artifact metadata without action parameter.
        2. Add artifact with prepared metadata to the model.
        3. Verify that added artifact has an empty list of actions in metadata.
        """
        artifact_metadata = self.ARTIFACT_METADATA.copy()
        del artifact_metadata["actions"]
        step("Add new artifact to model")
        new_artifact = ModelArtifact.upload_artifact(model_id=sample_model.id, **artifact_metadata)
        artifact_actions = new_artifact.actions
        expected_actions = []
        assert artifact_actions == expected_actions