|
| 1 | +import pytest |
| 2 | + |
| 3 | +@pytest.fixture |
| 4 | +def master(task): |
| 5 | + master = task.master.copy() |
| 6 | + master.empty() |
| 7 | + detail1 = task.detail1.copy() |
| 8 | + detail1.empty() |
| 9 | + master.open() |
| 10 | + for i in range(2): |
| 11 | + master.append() |
| 12 | + master.val.value = i |
| 13 | + master.detail1.open() |
| 14 | + for j in range(2): |
| 15 | + master.detail1.append() |
| 16 | + master.detail1.val.value = j |
| 17 | + master.detail1.post() |
| 18 | + master.post() |
| 19 | + master.apply() |
| 20 | + return task.master.copy() |
| 21 | + |
| 22 | +class TestEditLock: |
| 23 | + |
| 24 | + def test_copy_edit_lock(self, master): |
| 25 | + master.edit_lock = False |
| 26 | + copy = master.copy() |
| 27 | + assert not copy.edit_lock |
| 28 | + |
| 29 | + master.edit_lock = True |
| 30 | + copy = master.copy() |
| 31 | + assert copy.edit_lock |
| 32 | + |
| 33 | + def test_detail_copy_edit_lock(self, master): |
| 34 | + master.detail1.edit_lock = False |
| 35 | + copy = master.copy() |
| 36 | + assert not copy.detail1.edit_lock |
| 37 | + |
| 38 | + master.detail1.edit_lock = True |
| 39 | + copy = master.copy() |
| 40 | + assert copy.detail1.edit_lock |
| 41 | + |
| 42 | + @pytest.mark.parametrize(('master_rec_no, copy_rec_no, master_edit_lock, copy_edit_lock'), [ |
| 43 | + (0, 0, True, True), |
| 44 | + (0, 1, True, True), |
| 45 | + (0, 0, True, False), |
| 46 | + (0, 0, False, True) |
| 47 | + ]) |
| 48 | + |
| 49 | + def test_edit_lock(self, master, master_rec_no, copy_rec_no, master_edit_lock, copy_edit_lock): |
| 50 | + copy = master.copy() |
| 51 | + |
| 52 | + master.edit_lock = master_edit_lock |
| 53 | + copy.edit_lock = copy_edit_lock |
| 54 | + |
| 55 | + master.open() |
| 56 | + copy.open() |
| 57 | + |
| 58 | + assert master.rec_count == 2 |
| 59 | + assert copy.rec_count == 2 |
| 60 | + |
| 61 | + master.rec_no = master_rec_no |
| 62 | + copy.rec_no = copy_rec_no |
| 63 | + |
| 64 | + master.edit() |
| 65 | + master.val.value += 1 |
| 66 | + master.post() |
| 67 | + copy.edit() |
| 68 | + copy.val.value += 1 |
| 69 | + copy.post() |
| 70 | + master.apply() |
| 71 | + if master_rec_no == copy_rec_no and master_edit_lock and master_edit_lock == copy_edit_lock: |
| 72 | + with pytest.raises(Exception): |
| 73 | + copy.apply() |
| 74 | + else: |
| 75 | + copy.apply() |
| 76 | + |
| 77 | + @pytest.mark.parametrize(('master_rec_no, copy_rec_no, master_edit_lock, copy_edit_lock'), [ |
| 78 | + (0, 0, True, True), |
| 79 | + (0, 1, True, True), |
| 80 | + (0, 0, True, False), |
| 81 | + (0, 0, False, True) |
| 82 | + ]) |
| 83 | + |
| 84 | + def test_detail_edit_lock(self, master, master_rec_no, copy_rec_no, master_edit_lock, copy_edit_lock): |
| 85 | + copy = master.copy() |
| 86 | + |
| 87 | + master.edit_lock = False |
| 88 | + copy.edit_lock = False |
| 89 | + |
| 90 | + master.detail1.edit_lock = master_edit_lock |
| 91 | + copy.detail1.edit_lock = copy_edit_lock |
| 92 | + |
| 93 | + master.open() |
| 94 | + master.detail1.open() |
| 95 | + copy.open() |
| 96 | + copy.detail1.open() |
| 97 | + |
| 98 | + master.detail1.rec_no = master_rec_no |
| 99 | + copy.detail1.rec_no = copy_rec_no |
| 100 | + |
| 101 | + master.edit() |
| 102 | + master.detail1.edit() |
| 103 | + master.detail1.val.value += 1 |
| 104 | + master.detail1.post() |
| 105 | + master.post() |
| 106 | + copy.edit() |
| 107 | + copy.detail1.edit() |
| 108 | + copy.detail1.val.value += 1 |
| 109 | + copy.detail1.post() |
| 110 | + copy.post() |
| 111 | + master.apply() |
| 112 | + if master_rec_no == copy_rec_no and master_edit_lock and master_edit_lock == copy_edit_lock: |
| 113 | + with pytest.raises(Exception): |
| 114 | + copy.apply() |
| 115 | + else: |
| 116 | + copy.apply() |
| 117 | + |
0 commit comments