Skip to content

Commit

Permalink
test: Add test for _get_recipe_info function
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily committed Feb 6, 2024
1 parent ae4fe53 commit a4fd67d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/unit/data/result.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<job id="8874545" owner="mrack" result="Pass" status="Completed" retention_tag="audit" product="[internal]"><whiteboard>This job has been created using mrack.</whiteboard><recipeSet priority="Normal" response="ack" id="13149276"><recipe id="15482633" job_id="8874545" result="Pass" status="Completed" system="test.example.com"> <logs><log href="https://test.example.com/logs/console.log" name="console.log"/> <log href="https://test.example.com/logs/anaconda.log" name="anaconda.log"/></logs></recipe></recipeSet></job>
60 changes: 60 additions & 0 deletions tests/unit/test_beaker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2021 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for mrack.providers.beaker"""

from unittest import mock
from unittest.mock import Mock, patch

import pytest

from mrack.providers.beaker import BeakerProvider

from .utils import get_content


class TestBeakerProvider:
def setup_method(self):

self.mock_hub = Mock()
self.result_xml = get_content("result.xml")
self.mock_hub.taskactions.to_xml = Mock(return_value=self.result_xml)
self.mock_hub_class = Mock(return_value=self.mock_hub)
self.hub_patcher = patch(
"mrack.providers.beaker.HubProxy", new=self.mock_hub_class
)
self.hub_patcher.start()
self.log_msg_start = "Beaker [client.testdomain.test]"
self.beaker_id = 8874545
self.distros = ["Fedora-32%", "Fedora-37%", "CentOS-Stream-9%"]
self.timeout = 120
self.reserve_duration = 86400

def teardown_method(self):
mock.patch.stopall()

@pytest.mark.asyncio
async def test_get_repo_info(self):
provider = BeakerProvider()
await provider.init(self.distros, self.timeout, self.reserve_duration)
bkr_res = provider._get_recipe_info(self.beaker_id, self.log_msg_start)
assert bkr_res["system"] == "test.example.com"
assert bkr_res["status"] == "Completed"
assert bkr_res["result"] == "Pass"
assert bkr_res["rid"] == "15482633"
assert bkr_res["id"] == "8874545"
assert bkr_res["logs"] == {
"console.log": "https://test.example.com/logs/console.log",
"anaconda.log": "https://test.example.com/logs/anaconda.log",
}
7 changes: 7 additions & 0 deletions tests/unit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def get_data(name, data_dir="data"):
return data


def get_content(name, file_dir="data"):
path = os.path.join(test_dir_path(), file_dir, name)
with open(os.path.expanduser(path), "r", encoding="utf-8") as file_content:
content = file_content.read()
return content


def copy_as_temp(data_path, text=True):
"""
Makes a temporary copy of file relative to test dir and return it file path.
Expand Down

0 comments on commit a4fd67d

Please sign in to comment.