Skip to content

Commit

Permalink
test: add test for importing from git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmanville committed Feb 21, 2025
1 parent 5eee196 commit 3e2d0a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/unit/restapi/v1/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
# https://creativecommons.org/licenses/by/4.0/legalcode
"""Fixtures representing resources needed for test suites"""
import os
import shutil
import subprocess
import tarfile
import textwrap
from collections.abc import Iterator
from http import HTTPStatus
from pathlib import Path
from tempfile import NamedTemporaryFile
from tempfile import NamedTemporaryFile, TemporaryDirectory
from typing import Any, cast


import pytest
import tomllib
import uuid
Expand Down Expand Up @@ -749,6 +752,23 @@ def resources_tar_file() -> DioptraFile:
os.unlink(f.name)


@pytest.fixture
def resources_repo() -> str:
path = Path(__file__).absolute().parent / "workflows" / "resource_import_files"

git = shutil.which("git")

with TemporaryDirectory() as tmp_dir:
repo_dir = Path(tmp_dir) / "repo.git"
shutil.copytree(path, repo_dir)
with set_cwd(repo_dir):
subprocess.run([git, "init", "."])
subprocess.run([git, "add", "."])
subprocess.run([git, "commit", "-m."])

yield str(repo_dir)


@pytest.fixture
def resources_files() -> DioptraFile:
path = Path(__file__).absolute().parent / "workflows" / "resource_import_files"
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/restapi/v1/workflows/test_resource_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ def test_resource_import_from_files(

assert_imported_resources_match_expected(dioptra_client, resources_import_config)

def test_resource_import_from_repo(
dioptra_client: DioptraClient[DioptraResponseProtocol],
db: SQLAlchemy,
auth_account: dict[str, Any],
resources_repo: str,
resources_import_config: dict[str, Any],
):
group_id = auth_account["groups"][0]["id"]
dioptra_client.workflows.import_resources(group_id, source=resources_repo)

assert_imported_resources_match_expected(dioptra_client, resources_import_config)


def test_resource_import_fails_from_name_clash(
dioptra_client: DioptraClient[DioptraResponseProtocol],
Expand Down

0 comments on commit 3e2d0a5

Please sign in to comment.