|
1 | 1 | from leapp import reporting |
2 | | -from leapp.libraries.actor import checkmemory |
| 2 | +from leapp.libraries.actor import checkpanelmemory |
3 | 3 | from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked |
4 | 4 | from leapp.libraries.stdlib import api |
5 | 5 | from leapp.models import MemoryInfo, InstalledControlPanel |
| 6 | +from leapp.utils.report import is_inhibitor |
6 | 7 |
|
7 | 8 | from leapp.libraries.common.detectcontrolpanel import ( |
8 | 9 | UNKNOWN_NAME, |
|
12 | 13 |
|
13 | 14 |
|
14 | 15 | def test_check_memory_low(monkeypatch): |
15 | | - minimum_req_error = [] |
16 | 16 | monkeypatch.setattr(api, "current_actor", CurrentActorMocked()) |
17 | | - minimum_req_error = checkmemory._check_memory( |
18 | | - InstalledControlPanel(name=INTEGRATED_NAME), MemoryInfo(mem_total=1024) |
| 17 | + # _check_memory(panel_name, mem_info): panel must be string key for required_memory |
| 18 | + minimum_req_error = checkpanelmemory._check_memory( |
| 19 | + INTEGRATED_NAME, MemoryInfo(mem_total=1024) |
19 | 20 | ) |
20 | 21 | assert minimum_req_error |
21 | 22 |
|
22 | 23 |
|
23 | 24 | def test_check_memory_high(monkeypatch): |
24 | | - minimum_req_error = [] |
25 | 25 | monkeypatch.setattr(api, "current_actor", CurrentActorMocked()) |
26 | | - minimum_req_error = checkmemory._check_memory( |
27 | | - InstalledControlPanel(name=CPANEL_NAME), MemoryInfo(mem_total=16273492) |
| 26 | + minimum_req_error = checkpanelmemory._check_memory( |
| 27 | + CPANEL_NAME, MemoryInfo(mem_total=16273492) |
28 | 28 | ) |
29 | 29 | assert not minimum_req_error |
30 | 30 |
|
31 | 31 |
|
| 32 | +def _mock_consume(panel_name, memory_info): |
| 33 | + """Return a consume that yields the right model type for process().""" |
| 34 | + |
| 35 | + def consume(model): |
| 36 | + if model is InstalledControlPanel: |
| 37 | + return iter([InstalledControlPanel(name=panel_name)]) |
| 38 | + if model is MemoryInfo: |
| 39 | + return iter([memory_info]) |
| 40 | + return iter([]) |
| 41 | + |
| 42 | + return consume |
| 43 | + |
| 44 | + |
32 | 45 | def test_report(monkeypatch): |
33 | 46 | title_msg = "Minimum memory requirements for panel {} are not met".format( |
34 | 47 | UNKNOWN_NAME |
35 | 48 | ) |
36 | 49 | monkeypatch.setattr(api, "current_actor", CurrentActorMocked()) |
37 | | - monkeypatch.setattr(api, "consume", lambda x: iter([MemoryInfo(mem_total=129)])) |
| 50 | + monkeypatch.setattr( |
| 51 | + api, |
| 52 | + "consume", |
| 53 | + _mock_consume(UNKNOWN_NAME, MemoryInfo(mem_total=129)), |
| 54 | + ) |
38 | 55 | monkeypatch.setattr(reporting, "create_report", create_report_mocked()) |
39 | | - checkmemory.process() |
| 56 | + checkpanelmemory.process() |
40 | 57 | assert reporting.create_report.called |
41 | 58 | assert title_msg == reporting.create_report.report_fields["title"] |
42 | | - assert reporting.Flags.INHIBITOR in reporting.create_report.report_fields["flags"] |
| 59 | + assert is_inhibitor(reporting.create_report.report_fields) |
0 commit comments