|
1 | 1 | import pytest |
2 | 2 |
|
| 3 | +from compiler_admin.commands import RESULT_SUCCESS |
| 4 | + |
3 | 5 |
|
4 | 6 | @pytest.fixture |
5 | | -def mock_commands_create(mocker): |
6 | | - """Fixture returns a function that patches commands.create in a given module.""" |
| 7 | +def mock_module_name(mocker): |
| 8 | + """Fixture returns a function taking a name, that returns a function taking a module, |
| 9 | + patching the given name in the given module. |
7 | 10 |
|
8 | | - def _mock_commands_create(module, **kwargs): |
9 | | - return mocker.patch(f"{module}.create", **kwargs) |
| 11 | + By default, the patched object is given a return_value = RESULT_SUCCESS. |
| 12 | + """ |
10 | 13 |
|
11 | | - return _mock_commands_create |
| 14 | + def _mock_module_name(name): |
| 15 | + def __mock_module_name(module): |
| 16 | + patched = mocker.patch(f"{module}.{name}") |
| 17 | + patched.return_value = RESULT_SUCCESS |
| 18 | + return patched |
12 | 19 |
|
| 20 | + return __mock_module_name |
13 | 21 |
|
14 | | -@pytest.fixture |
15 | | -def mock_commands_convert(mocker): |
16 | | - """Fixture returns a function that patches commands.convert in a given module.""" |
| 22 | + return _mock_module_name |
17 | 23 |
|
18 | | - def _mock_commands_convert(module, **kwargs): |
19 | | - return mocker.patch(f"{module}.convert", **kwargs) |
20 | 24 |
|
21 | | - return _mock_commands_convert |
| 25 | +@pytest.fixture |
| 26 | +def mock_commands_create(mock_module_name): |
| 27 | + """Fixture returns a function that patches commands.create in a given module.""" |
| 28 | + return mock_module_name("create") |
22 | 29 |
|
23 | 30 |
|
24 | 31 | @pytest.fixture |
25 | | -def mock_commands_delete(mocker): |
26 | | - """Fixture returns a function that patches commands.delete in a given module.""" |
| 32 | +def mock_commands_convert(mock_module_name): |
| 33 | + """Fixture returns a function that patches commands.convert in a given module.""" |
| 34 | + return mock_module_name("convert") |
27 | 35 |
|
28 | | - def _mock_commands_delete(module, **kwargs): |
29 | | - return mocker.patch(f"{module}.delete", **kwargs) |
30 | 36 |
|
31 | | - return _mock_commands_delete |
| 37 | +@pytest.fixture |
| 38 | +def mock_commands_delete(mock_module_name): |
| 39 | + """Fixture returns a function that patches commands.delete in a given module.""" |
| 40 | + return mock_module_name("delete") |
32 | 41 |
|
33 | 42 |
|
34 | 43 | @pytest.fixture |
35 | | -def mock_commands_info(mocker): |
| 44 | +def mock_commands_info(mock_module_name): |
36 | 45 | """Fixture returns a function that patches commands.info in a given module.""" |
37 | | - |
38 | | - def _mock_commands_info(module, **kwargs): |
39 | | - return mocker.patch(f"{module}.info", **kwargs) |
40 | | - |
41 | | - return _mock_commands_info |
| 46 | + return mock_module_name("info") |
42 | 47 |
|
43 | 48 |
|
44 | 49 | @pytest.fixture |
45 | | -def mock_commands_init(mocker): |
| 50 | +def mock_commands_init(mock_module_name): |
46 | 51 | """Fixture returns a function that patches commands.init in a given module.""" |
47 | | - |
48 | | - def _mock_commands_init(module, **kwargs): |
49 | | - return mocker.patch(f"{module}.init", **kwargs) |
50 | | - |
51 | | - return _mock_commands_init |
| 52 | + return mock_module_name("init") |
52 | 53 |
|
53 | 54 |
|
54 | 55 | @pytest.fixture |
55 | | -def mock_commands_offboard(mocker): |
| 56 | +def mock_commands_offboard(mock_module_name): |
56 | 57 | """Fixture returns a function that patches commands.offboard in a given module.""" |
57 | | - |
58 | | - def _mock_commands_offboard(module, **kwargs): |
59 | | - return mocker.patch(f"{module}.offboard", **kwargs) |
60 | | - |
61 | | - return _mock_commands_offboard |
| 58 | + return mock_module_name("offboard") |
62 | 59 |
|
63 | 60 |
|
64 | 61 | @pytest.fixture |
65 | | -def mock_commands_restore(mocker): |
| 62 | +def mock_commands_restore(mock_module_name): |
66 | 63 | """Fixture returns a function that patches commands.restore in a given module.""" |
67 | | - |
68 | | - def _mock_commands_restore(module, **kwargs): |
69 | | - return mocker.patch(f"{module}.restore", **kwargs) |
70 | | - |
71 | | - return _mock_commands_restore |
| 64 | + return mock_module_name("restore") |
72 | 65 |
|
73 | 66 |
|
74 | 67 | @pytest.fixture |
75 | | -def mock_commands_signout(mocker): |
| 68 | +def mock_commands_signout(mock_module_name): |
76 | 69 | """Fixture returns a function that patches commands.signout in a given module.""" |
77 | | - |
78 | | - def _mock_commands_signout(module, **kwargs): |
79 | | - return mocker.patch(f"{module}.signout", **kwargs) |
80 | | - |
81 | | - return _mock_commands_signout |
| 70 | + return mock_module_name("signout") |
82 | 71 |
|
83 | 72 |
|
84 | 73 | @pytest.fixture |
85 | | -def mock_google_CallGAMCommand(mocker): |
| 74 | +def mock_google_CallGAMCommand(mock_module_name): |
86 | 75 | """Fixture returns a function that patches the CallGAMCommand function from a given module.""" |
87 | | - |
88 | | - def _mock_google_CallGAMCommand(module, **kwargs): |
89 | | - return mocker.patch(f"{module}.CallGAMCommand", **kwargs) |
90 | | - |
91 | | - return _mock_google_CallGAMCommand |
| 76 | + return mock_module_name("CallGAMCommand") |
92 | 77 |
|
93 | 78 |
|
94 | 79 | @pytest.fixture |
95 | | -def mock_google_CallGYBCommand(mocker): |
| 80 | +def mock_google_CallGYBCommand(mock_module_name): |
96 | 81 | """Fixture returns a function that patches the CallGYBCommand function from a given module.""" |
97 | | - |
98 | | - def _mock_google_CallGYBCommand(module, **kwargs): |
99 | | - return mocker.patch(f"{module}.CallGYBCommand", **kwargs) |
100 | | - |
101 | | - return _mock_google_CallGYBCommand |
| 82 | + return mock_module_name("CallGYBCommand") |
102 | 83 |
|
103 | 84 |
|
104 | 85 | @pytest.fixture |
105 | | -def mock_google_add_user_to_group(mocker): |
| 86 | +def mock_google_add_user_to_group(mock_module_name): |
106 | 87 | """Fixture returns a function that patches the add_user_to_group function from a given module.""" |
107 | | - |
108 | | - def _mock_google_add_user_to_group(module, **kwargs): |
109 | | - return mocker.patch(f"{module}.add_user_to_group", **kwargs) |
110 | | - |
111 | | - return _mock_google_add_user_to_group |
| 88 | + return mock_module_name("add_user_to_group") |
112 | 89 |
|
113 | 90 |
|
114 | 91 | @pytest.fixture |
115 | | -def mock_google_move_user_ou(mocker): |
| 92 | +def mock_google_move_user_ou(mock_module_name): |
116 | 93 | """Fixture returns a function that patches the move_user_ou function from a given module.""" |
117 | | - |
118 | | - def _mock_google_move_user_ou(module, **kwargs): |
119 | | - return mocker.patch(f"{module}.move_user_ou", **kwargs) |
120 | | - |
121 | | - return _mock_google_move_user_ou |
| 94 | + return mock_module_name("move_user_ou") |
122 | 95 |
|
123 | 96 |
|
124 | 97 | @pytest.fixture |
125 | | -def mock_google_remove_user_from_group(mocker): |
| 98 | +def mock_google_remove_user_from_group(mock_module_name): |
126 | 99 | """Fixture returns a function that patches the remove_user_from_group function from a given module.""" |
127 | | - |
128 | | - def _mock_google_remove_user_from_group(module, **kwargs): |
129 | | - return mocker.patch(f"{module}.remove_user_from_group", **kwargs) |
130 | | - |
131 | | - return _mock_google_remove_user_from_group |
| 100 | + return mock_module_name("remove_user_from_group") |
132 | 101 |
|
133 | 102 |
|
134 | 103 | @pytest.fixture |
135 | | -def mock_google_user_exists(mocker): |
| 104 | +def mock_google_user_exists(mock_module_name): |
136 | 105 | """Fixture returns a function that patches the user_exists function from a given module.""" |
137 | | - |
138 | | - def _mock_google_user_exists(module, **kwargs): |
139 | | - return mocker.patch(f"{module}.user_exists", **kwargs) |
140 | | - |
141 | | - return _mock_google_user_exists |
| 106 | + return mock_module_name("user_exists") |
142 | 107 |
|
143 | 108 |
|
144 | 109 | @pytest.fixture |
145 | | -def mock_google_user_in_group(mocker): |
| 110 | +def mock_google_user_in_group(mock_module_name): |
146 | 111 | """Fixture returns a function that patches the user_in_group function from a given module.""" |
147 | | - |
148 | | - def _mock_google_user_in_group(module, **kwargs): |
149 | | - return mocker.patch(f"{module}.user_in_group", **kwargs) |
150 | | - |
151 | | - return _mock_google_user_in_group |
| 112 | + return mock_module_name("user_in_group") |
152 | 113 |
|
153 | 114 |
|
154 | 115 | @pytest.fixture |
155 | | -def mock_google_user_is_partner(mocker): |
| 116 | +def mock_google_user_is_partner(mock_module_name): |
156 | 117 | """Fixture returns a function that patches the user_is_partner function from a given module.""" |
157 | | - |
158 | | - def _mock_google_user_is_partner(module, **kwargs): |
159 | | - return mocker.patch(f"{module}.user_is_partner", **kwargs) |
160 | | - |
161 | | - return _mock_google_user_is_partner |
| 118 | + return mock_module_name("user_is_partner") |
162 | 119 |
|
163 | 120 |
|
164 | 121 | @pytest.fixture |
165 | | -def mock_google_user_is_staff(mocker): |
| 122 | +def mock_google_user_is_staff(mock_module_name): |
166 | 123 | """Fixture returns a function that patches the user_is_staff function from a given module.""" |
167 | | - |
168 | | - def _mock_google_user_is_staff(module, **kwargs): |
169 | | - return mocker.patch(f"{module}.user_is_staff", **kwargs) |
170 | | - |
171 | | - return _mock_google_user_is_staff |
| 124 | + return mock_module_name("user_is_staff") |
172 | 125 |
|
173 | 126 |
|
174 | 127 | @pytest.fixture |
|
0 commit comments