Debian Codegraph @

test/units/cli/galaxy/test_execute_list.py

raw
1 # -*- coding: utf-8 -*-
2 # -*- coding: utf-8 -*-
3 # Copyright (c) 2020 Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import annotations
7
8 import pytest
9
10 from ansible import context
11 from ansible.cli.galaxy import GalaxyCLI
12
13
14 def test_execute_list_role_called(mocker):
15 """Make sure the correct method is called for a role"""
16
17 gc = GalaxyCLI(['ansible-galaxy', 'role', 'list'])
18 context.CLIARGS._store = {'type': 'role'}
19 execute_list_role_mock = mocker.patch('ansible.cli.galaxy.GalaxyCLI.execute_list_role', side_effect=AttributeError('raised intentionally'))
20 execute_list_collection_mock = mocker.patch('ansible.cli.galaxy.GalaxyCLI.execute_list_collection', side_effect=AttributeError('raised intentionally'))
21 with pytest.raises(AttributeError):
22 gc.execute_list()
23
24 assert execute_list_role_mock.call_count == 1
25 assert execute_list_collection_mock.call_count == 0
26
27
28 def test_execute_list_collection_called(mocker):
29 """Make sure the correct method is called for a collection"""
30
31 gc = GalaxyCLI(['ansible-galaxy', 'collection', 'list'])
32 context.CLIARGS._store = {'type': 'collection'}
33 execute_list_role_mock = mocker.patch('ansible.cli.galaxy.GalaxyCLI.execute_list_role', side_effect=AttributeError('raised intentionally'))
34 execute_list_collection_mock = mocker.patch('ansible.cli.galaxy.GalaxyCLI.execute_list_collection', side_effect=AttributeError('raised intentionally'))
35 with pytest.raises(AttributeError):
36 gc.execute_list()
37
38 assert execute_list_role_mock.call_count == 0
39 assert execute_list_collection_mock.call_count == 1