def test_pipeline_class_init(self, tmp_path):
        fp = tmp_path / "pipeline.service.test.yml"
        result = gp.Pipeline(fp)

        assert result.filename == "pipeline.service.test.yml"
        assert result.name == "test"
        assert result.slug == "devops-deploy-test"
    def test_pipeline_class_will_delete(self, tmp_path, mock_server):
        fp = tmp_path / "pipeline.service.is-a-pipeline.yml"

        mock_server.start()

        pipeline = gp.Pipeline(fp)

        assert pipeline._delete() == 204
    def test_class_can_create_pipeline(self, tmp_path):
        fp = tmp_path / "pipeline.service.test-pipeline.yml"

        pipeline = gp.Pipeline(fp)
        try:
            pipeline._create()
            assert pipeline.responses == [("POST", 201)]
        finally:
            pipeline._delete()
    def test_pipeline_class_checks_for_pipeline_existence(
            self, tmp_path, mock_server):
        fp = tmp_path / "pipeline.service.is-a-pipeline.yml"

        mock_server.start()

        pipeline = gp.Pipeline(fp)
        pipeline._exists()
        assert pipeline.responses == [("GET", 200)]
    def test_pipeline_class_will_raise_error_on_existence_check(
            self, tmp_path, mock_server):
        fp = tmp_path / "pipeline.should-raise-exception.yml"

        mock_server.start()

        pipeline = gp.Pipeline(fp)

        with pytest.raises(requests.HTTPError):
            pipeline._exists()
    def test_pipeline_class_will_update_existing(self, tmp_path, capsys,
                                                 mock_server):
        fp = tmp_path / "pipeline.service.is-a-pipeline.yml"

        mock_server.start()

        pipeline = gp.Pipeline(fp)
        pipeline._update()
        captured = capsys.readouterr()

        result = pipeline.responses
        assert result == [("PATCH", 200)]
        assert json.loads(captured.out) == gen_expected(
            "is-a-pipeline", "pipeline.service.is-a-pipeline.yml")
    def test_pipeline_class_creates_buildkite_pipeline(self, tmp_path, capsys,
                                                       mock_server):
        fp = tmp_path / "pipeline.service.is-a-pipeline.yml"

        mock_server.start()

        pipeline = gp.Pipeline(fp)
        pipeline._create()
        captured = capsys.readouterr()

        result = pipeline.responses
        assert result == [("POST", 201)]
        assert json.loads(captured.out) == gen_expected(
            "is-a-pipeline", "pipeline.service.is-a-pipeline.yml")
    def test_class_can_get_existing_pipeline(self, tmp_path):
        fp = tmp_path / "pipeline.service.a_repo.yml"

        pipeline = gp.Pipeline(fp)
        assert pipeline._exists() is True
    def test_pipeline_class_gen_slug(self, tmp_path):
        fp = tmp_path / "pipeline.service.not-a-pipeline.yml"
        pipeline = gp.Pipeline(fp)

        assert pipeline.slug == "devops-deploy-not-a-pipeline"