Ejemplo n.º 1
0
    def test_run_log_dataset_version(self, client_2, client_3, organization,
                                     created_entities):
        """Log someone else's dataset version to my run."""
        organization.add_member(client_2._conn.email)
        organization.add_member(client_3._conn.email)
        client_2.set_workspace(organization.name)
        client_3.set_workspace(organization.name)

        created_entities.append(client_2.create_project())
        run = client_2.create_experiment_run()

        # private dataset version
        dataset = client_3.create_dataset(visibility=Private())
        created_entities.append(dataset)
        dataver = dataset.create_version(Path(__file__))
        with pytest.raises(requests.HTTPError,
                           match="Access Denied|Forbidden"):
            run.log_dataset_version("train", dataver)

        # org dataset version
        dataset = client_3.create_dataset()
        created_entities.append(dataset)
        dataver = dataset.create_version(Path(__file__))
        run.log_dataset_version("train", dataver)
        assert run.get_dataset_version("train").id == dataver.id
Ejemplo n.º 2
0
    def test_endpoint_update_run(self, client_2, client_3, organization, created_entities):
        """Update endpoint from someone else's run."""
        LogisticRegression = pytest.importorskip("sklearn.linear_model").LogisticRegression

        organization.add_member(client_2._conn.email)
        organization.add_member(client_3._conn.email)
        client_2.set_workspace(organization.name)
        client_3.set_workspace(organization.name)

        endpoint = client_2.create_endpoint(_utils.generate_default_name())
        created_entities.append(endpoint)

        # private run
        created_entities.append(client_3.create_project(visibility=Private()))
        run = client_3.create_experiment_run()
        run.log_model(LogisticRegression(), custom_modules=[])
        run.log_environment(Python(["scikit-learn"]))
        with pytest.raises(requests.HTTPError, match="Access Denied|Forbidden"):
            endpoint.update(run)

        # org run, deploy=False
        created_entities.append(client_3.create_project(visibility=OrgCustom(deploy=False)))
        run = client_3.create_experiment_run()
        run.log_model(LogisticRegression(), custom_modules=[])
        run.log_environment(Python(["scikit-learn"]))
        with pytest.raises(requests.HTTPError, match="Access Denied|Forbidden"):
            endpoint.update(run)

        # org run, deploy=True
        created_entities.append(client_3.create_project(visibility=OrgCustom(deploy=True)))
        run = client_3.create_experiment_run()
        run.log_model(LogisticRegression(), custom_modules=[])
        run.log_environment(Python(["scikit-learn"]))
        assert endpoint.update(run)
Ejemplo n.º 3
0
    def test_run_log_commit(self, client_2, client_3, organization,
                            created_entities):
        """Log someone else's commit to my run."""
        organization.add_member(client_2._conn.email)
        organization.add_member(client_3._conn.email)
        client_2.set_workspace(organization.name)
        client_3.set_workspace(organization.name)

        created_entities.append(client_2.create_project())
        run = client_2.create_experiment_run()

        # private commit
        repo = client_3.set_repository(_utils.generate_default_name(),
                                       visibility=Private())
        created_entities.append(repo)
        commit = repo.get_commit()
        with pytest.raises(requests.HTTPError,
                           match="Access Denied|Forbidden"):
            run.log_commit(commit)

        # org commit
        repo = client_3.set_repository(_utils.generate_default_name())
        created_entities.append(repo)
        commit = repo.get_commit()
        run.log_commit(commit)
        assert run.get_commit()[0].id == commit.id
Ejemplo n.º 4
0
    def test_private(self, client, client_2, organization, created_entities, entity_name):
        """Org member cannot get."""
        organization.add_member(client_2._conn.email)
        client.set_workspace(organization.name)
        client_2.set_workspace(organization.name)
        name = _utils.generate_default_name()
        visibility = Private()

        entity = getattr(client, "create_{}".format(entity_name))(name, visibility=visibility)
        created_entities.append(entity)

        with pytest.raises(Exception, match="not found|Denied"):
            getattr(client_2, "get_{}".format(entity_name))(name)
Ejemplo n.º 5
0
    def test_mdb_entity(self, client, organization, entity_name, visibility):
        set_entity = getattr(client, "set_{}".format(entity_name))

        entity = set_entity(workspace=organization.name, visibility=visibility)
        try:
            assert_visibility(entity, visibility, entity_name)

            # second set ignores visibility
            with pytest.warns(UserWarning, match="cannot set"):
                entity = set_entity(entity.name,
                                    workspace=organization.name,
                                    visibility=Private())
            assert_visibility(entity, visibility, entity_name)
        finally:
            entity.delete()
            client._ctx.proj = None  # otherwise client teardown tries to delete
Ejemplo n.º 6
0
    def test_repository(self, client, organization):
        visibility = OrgCustom(write=True)

        repo = client.set_repository(
            name=_utils.generate_default_name(),
            workspace=organization.name,
            visibility=visibility,
        )
        try:
            assert_repository_visibility(repo, visibility)

            # second set ignores visibility
            repo = client.set_repository(name=repo.name,
                                         workspace=organization.name,
                                         visibility=Private())
            assert_repository_visibility(repo, visibility)
        finally:
            repo.delete()
    def test_endpoint(self, client, organization, created_entities):
        visibility = OrgCustom(write=True)

        endpoint = client.set_endpoint(
            path=_utils.generate_default_name(),
            workspace=organization.name,
            visibility=visibility,
        )
        created_entities.append(endpoint)

        assert_endpoint_visibility(endpoint, visibility)

        # second set ignores visibility
        with pytest.warns(UserWarning, match="cannot set"):
            endpoint = client.set_endpoint(path=endpoint.path,
                                           workspace=organization.name,
                                           visibility=Private())
        assert_endpoint_visibility(endpoint, visibility)
Ejemplo n.º 8
0
    def test_endpoint_update_model_version(self, client_2, client_3,
                                           organization, created_entities):
        """Update endpoint from someone else's model version."""
        LogisticRegression = pytest.importorskip(
            "sklearn.linear_model").LogisticRegression

        organization.add_member(client_2._conn.auth['Grpc-Metadata-email'])
        organization.add_member(client_3._conn.auth['Grpc-Metadata-email'])
        client_2.set_workspace(organization.name)
        client_3.set_workspace(organization.name)

        endpoint = client_2.create_endpoint(_utils.generate_default_name())
        created_entities.append(endpoint)

        # private model version
        reg_model = client_3.create_registered_model(visibility=Private())
        created_entities.append(reg_model)
        model_ver = reg_model.create_version()
        model_ver.log_model(LogisticRegression(), custom_modules=[])
        model_ver.log_environment(Python(["scikit-learn"]))
        with pytest.raises(requests.HTTPError,
                           match="Access Denied|Forbidden"):
            endpoint.update(model_ver)

        # org model version, deploy=False
        reg_model = client_3.create_registered_model(visibility=OrgCustom(
            deploy=False))
        created_entities.append(reg_model)
        model_ver = reg_model.create_version()
        model_ver.log_model(LogisticRegression(), custom_modules=[])
        model_ver.log_environment(Python(["scikit-learn"]))
        with pytest.raises(requests.HTTPError,
                           match="Access Denied|Forbidden"):
            endpoint.update(model_ver)

        # org model version, deploy=True
        reg_model = client_3.create_registered_model(visibility=OrgCustom(
            deploy=True))
        created_entities.append(reg_model)
        model_ver = reg_model.create_version()
        model_ver.log_model(LogisticRegression(), custom_modules=[])
        model_ver.log_environment(Python(["scikit-learn"]))
        assert endpoint.update(model_ver)
Ejemplo n.º 9
0
    def test_model_version_from_run(self, client_2, client_3, organization, created_entities):
        """Create model version from someone else's run."""
        organization.add_member(client_2._conn.email)
        organization.add_member(client_3._conn.email)
        client_2.set_workspace(organization.name)
        client_3.set_workspace(organization.name)

        reg_model = client_2.create_registered_model()
        created_entities.append(reg_model)

        # private run
        created_entities.append(client_3.create_project(visibility=Private()))
        run = client_3.create_experiment_run()
        with pytest.raises(requests.HTTPError, match="Access Denied|Forbidden"):
            reg_model.create_version_from_run(run.id)

        # org run
        created_entities.append(client_3.create_project())
        run = client_3.create_experiment_run()
        model_ver = reg_model.create_version_from_run(run.id)
        assert model_ver._msg.experiment_run_id == run.id
Ejemplo n.º 10
0
    def test_repository(self, client, client_2, organization,
                        created_entities):
        """
        The above, but for repository.

        Because there is no client.create_repository() or client.get_repository().
        """
        organization.add_member(client_2._conn.email)
        client.set_workspace(organization.name)
        client_2.set_workspace(organization.name)

        # private
        private_repo = client.set_repository(_utils.generate_default_name(),
                                             visibility=Private())
        created_entities.append(private_repo)
        with pytest.raises(Exception, match="unable to get Repository"):
            client_2.set_repository(private_repo.name)

        # read-only
        read_repo = client.set_repository(_utils.generate_default_name(),
                                          visibility=OrgCustom(write=False))
        created_entities.append(read_repo)
        retrieved_repo = client_2.set_repository(read_repo.name)
        assert retrieved_repo.id == read_repo.id
        with pytest.raises(requests.HTTPError,
                           match="Access Denied|Forbidden"):
            retrieved_repo.delete()

        # read-write
        write_repo = client.set_repository(_utils.generate_default_name(),
                                           visibility=OrgCustom(write=True))
        try:
            retrieved_repo = client_2.set_repository(write_repo.name)
            retrieved_repo.delete()
        except:
            created_entities.append(write_repo)