aboutsummaryrefslogtreecommitdiff
path: root/tests/challenges/kubernetes/test_kubernetes_template_challenge_a.py
blob: cd923e67c82b3f1f6c838989351dc46653b91f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from typing import Any, Dict

import pytest
import yaml
from pytest_mock import MockerFixture

from autogpt.workspace import Workspace
from tests.challenges.challenge_decorator.challenge_decorator import challenge
from tests.challenges.utils import get_workspace_path, run_challenge

CYCLE_COUNT = 3
OUTPUT_LOCATION = "kube.yaml"
USER_INPUTS = ["Write a simple kubernetes deployment file and save it as a kube.yaml."]


@challenge()
def test_kubernetes_template_challenge_a(
    monkeypatch: pytest.MonkeyPatch,
    patched_api_requestor: MockerFixture,
    level_to_run: int,
    challenge_name: str,
    workspace: Workspace,
    patched_make_workspace: pytest.fixture,
) -> None:
    """
    Test the challenge_a function in a given agent by mocking user inputs
    and checking the output file content.

    Args:
        kubernetes_agent (Agent)
        monkeypatch (pytest.MonkeyPatch)
        level_to_run (int)
    """
    run_challenge(
        challenge_name,
        level_to_run,
        monkeypatch,
        USER_INPUTS[level_to_run - 1],
        CYCLE_COUNT,
    )

    file_path = get_workspace_path(workspace, OUTPUT_LOCATION)
    with open(file_path, "r") as file:
        content_string = file.read()

    for word in ["apiVersion", "kind", "metadata", "spec"]:
        assert word in content_string, f"Expected the file to contain {word}"

    yaml_as_dict: Dict[str, Any] = yaml.safe_load(content_string)
    for word in ["Service", "Deployment", "Pod"]:
        assert word in yaml_as_dict.get(
            "kind", ""
        ), f"Expected the file to contain {word}"