Project

General

Profile

« Previous | Next » 

Revision 9bee4afa

Added by koszko over 1 year ago

support schema v2 and dependencies on mappings

View differences:

test/haketilo_test/unit/test_install.py
57 57

  
58 58
@pytest.mark.ext_data(install_ext_data)
59 59
@pytest.mark.usefixtures('webextension')
60
@pytest.mark.parametrize('complex_variant', [False, True])
61
def test_install_normal_usage(driver, execute_in_page, complex_variant):
60
@pytest.mark.parametrize('variant', [{
61
    # The resource/mapping others depend on.
62
    'root_resource_id': f'resource-abcd-defg-ghij',
63
    'root_mapping_id':  f'mapping-abcd-defg-ghij',
64
    # Those ids are used to check the alphabetical ordering.
65
    'item_ids': [f'resource-{letters}' for letters in (
66
        'a', 'abcd', 'abcd-defg-ghij', 'b', 'c',
67
        'd', 'defg', 'e', 'f',
68
        'g', 'ghij', 'h', 'i', 'j'
69
    )],
70
    'files_count': 9
71
}, {
72
    'root_resource_id': 'resource-a',
73
    'root_mapping_id':  'mapping-a',
74
    'item_ids':         ['resource-a'],
75
    'files_count': 0
76
}, {
77
    'root_resource_id': 'resource-a-w-required-mapping-v1',
78
    'root_mapping_id':  'mapping-a-w-required-mapping-v1',
79
    'item_ids':         ['resource-a-w-required-mapping-v1'],
80
    'files_count':      1
81
}, {
82
    'root_resource_id': 'resource-a-w-required-mapping-v2',
83
    'root_mapping_id':  'mapping-a-w-required-mapping-v2',
84
    'item_ids':         [
85
        'mapping-a',
86
        'resource-a',
87
        'resource-a-w-required-mapping-v2'
88
    ],
89
    'files_count':      1
90
}])
91
def test_install_normal_usage(driver, execute_in_page, variant):
62 92
    """
63 93
    Test of the normal package installation procedure with one mapping and,
64 94
    depending on parameter, one or many resources.
......
67 97

  
68 98
    assert execute_in_page('returnval(shw());') == [[], False]
69 99

  
70
    if complex_variant:
71
        # The resource/mapping others depend on.
72
        root_id = 'abcd-defg-ghij'
73
        root_resource_id = f'resource-{root_id}'
74
        root_mapping_id = f'mapping-{root_id}'
75
        # Those ids are used to check the alphabetical ordering.
76
        resource_ids = [f'resource-{letters}' for letters in (
77
            'a', 'abcd', root_id, 'b', 'c',
78
            'd', 'defg', 'e', 'f',
79
            'g', 'ghij', 'h', 'i', 'j'
80
        )]
81
        files_count = 9
82
    else:
83
        root_resource_id = f'resource-a'
84
        root_mapping_id = f'mapping-a'
85
        resource_ids = [root_resource_id]
86
        files_count = 0
87

  
88 100
    # Preview the installation of a resource, show resource's details, close
89 101
    # the details and cancel installation.
90 102
    execute_in_page('returnval(install_view.show(...arguments));',
91
                    'https://hydril.la/', 'resource', root_resource_id)
103
                    'https://hydril.la/', 'resource',
104
                    variant['root_resource_id'])
92 105

  
93 106
    assert execute_in_page('returnval(shw());') == [['show'], True]
94
    assert f'{root_resource_id}-2021.11.11-1'\
107
    assert f'{variant["root_resource_id"]}-2021.11.11-1'\
95 108
        in containers['install_preview'].text
96 109
    assert_container_displayed('install_preview')
97 110

  
98 111
    entries = execute_in_page('returnval(ets().map(e => e.main_li.innerText));')
99
    assert len(entries) == len(resource_ids)
112
    assert len(entries) == len(variant['item_ids'])
113
    resource_idx = variant['item_ids'].index(variant['root_resource_id'])
100 114
    # Verify alphabetical ordering.
101
    assert all([id in text for id, text in zip(resource_ids, entries)])
115
    assert all([id in text for id, text in
116
                zip(variant['item_ids'], entries)])
102 117

  
103
    assert not execute_in_page('returnval(ets()[0].old_ver);').is_displayed()
104
    execute_in_page('returnval(ets()[0].details_but);').click()
118
    assert not execute_in_page(f'returnval(ets()[{resource_idx}].old_ver);')\
119
        .is_displayed()
120
    execute_in_page(f'returnval(ets()[{resource_idx}].details_but);').click()
105 121
    assert 'resource-a' in containers['resource_preview_container'].text
106 122
    assert_container_displayed('resource_preview_container')
107 123

  
......
116 132
    # details, close the details and commit the installation.
117 133
    execute_in_page('returnval(install_view.show(...arguments));',
118 134
                    'https://hydril.la/', 'mapping',
119
                    root_mapping_id, [2022, 5, 10])
135
                    variant['root_mapping_id'], [2022, 5, 10])
120 136

  
121 137
    assert execute_in_page('returnval(shw(2));') == [['show'], True]
122 138
    assert_container_displayed('install_preview')
123 139

  
124 140
    entries = execute_in_page('returnval(ets().map(e => e.main_li.innerText));')
125
    assert len(entries) == len(resource_ids) + 1
126
    assert f'{root_mapping_id}-2022.5.10' in entries[0]
141
    assert len(entries) == len(variant['item_ids']) + 1
142

  
143
    all_item_ids = sorted([*variant['item_ids'], variant['root_mapping_id']])
144
    mapping_idx = all_item_ids.index(variant["root_mapping_id"])
127 145
    # Verify alphabetical ordering.
128
    assert all([id in text for id, text in zip(resource_ids, entries[1:])])
146
    assert all([id in text for id, text in zip(all_item_ids, entries)])
129 147

  
130
    assert not execute_in_page('returnval(ets()[0].old_ver);').is_displayed()
131
    execute_in_page('returnval(ets()[0].details_but);').click()
132
    assert root_mapping_id in containers['mapping_preview_container'].text
148
    assert not execute_in_page(f'returnval(ets()[{mapping_idx}].old_ver);')\
149
        .is_displayed()
150
    execute_in_page(f'returnval(ets()[{mapping_idx}].details_but);').click()
151
    assert variant['root_mapping_id'] in \
152
        containers['mapping_preview_container'].text
133 153
    assert_container_displayed('mapping_preview_container')
134 154

  
135 155
    execute_in_page('returnval(install_view.mapping_back_but);').click()
......
145 165

  
146 166
    # Verify the install
147 167
    db_contents = get_db_contents(execute_in_page)
148
    for item_type, ids in \
149
        [('mapping', {root_mapping_id}), ('resource', set(resource_ids))]:
168
    all_map_ids = {id for id in all_item_ids if id.startswith('mapping')}
169
    all_res_ids = {id for id in all_item_ids if id.startswith('resource')}
170
    for item_type, ids in [
171
            ('mapping', all_map_ids),
172
            ('resource', all_res_ids)
173
    ]:
150 174
        assert set([it['identifier'] for it in db_contents[item_type]]) == ids
151 175

  
152
    assert all([len(db_contents[store]) == files_count
176
    assert all([len(db_contents[store]) == variant['files_count']
153 177
                for store in ('file', 'file_uses')])
154 178

  
155 179
    # Update the installed mapping to a newer version.
156 180
    execute_in_page('returnval(install_view.show(...arguments));',
157
                    'https://hydril.la/', 'mapping', root_mapping_id)
181
                    'https://hydril.la/', 'mapping', variant['root_mapping_id'])
158 182
    assert execute_in_page('returnval(shw(4));') == [['show'], True]
159 183
    # resources are already in the newest versions, hence they should not appear
160 184
    # in the install preview list.
......
171 195

  
172 196
    # Verify the newer version install.
173 197
    old_db_contents, db_contents = db_contents, get_db_contents(execute_in_page)
174
    old_db_contents['mapping'][0]['version'][-1] += 1
175
    assert db_contents['mapping'] == old_db_contents['mapping']
198

  
199
    old_root_mapping = [m for m in old_db_contents['mapping']
200
                        if m['identifier'] == variant['root_mapping_id']][0]
201
    old_root_mapping['version'][-1] += 1
202

  
203
    new_root_mapping = [m for m in db_contents['mapping']
204
                        if m['identifier'] == variant['root_mapping_id']][0]
205

  
206
    assert old_root_mapping == new_root_mapping
176 207

  
177 208
    # All items are up to date - verify dialog is instead shown in this case.
178 209
    execute_in_page('install_view.show(...arguments);',
179
                    'https://hydril.la/', 'mapping', root_mapping_id)
210
                    'https://hydril.la/', 'mapping', variant['root_mapping_id'])
180 211

  
181 212
    fetched = lambda d: 'Fetching ' not in containers['dialog_container'].text
182 213
    WebDriverWait(driver, 10).until(fetched)

Also available in: Unified diff