Exemplo n.º 1
0
def test_generate_grabs_addons_and_plugins_records():
    kinto_client = mock.MagicMock()
    kinto_client.get_records.side_effect = [[ADDONS_DATA], [PLUGIN_DATA]]
    collections = [
        '/buckets/blocklists/collections/addons',
        '/buckets/blocklists/collections/plugins'
    ]

    collection_template = get_template('collection.tpl')
    record_template = get_template('record.tpl')

    with mock.patch('amo2kinto.generator.os.makedirs') as mocked_makedirs:
        with mock.patch('amo2kinto.generator.get_template',
                        side_effect=[collection_template, record_template]):
            with mock.patch('amo2kinto.generator.generate_index') as gi:
                with mock.patch('amo2kinto.generator.generate_record') as gr:
                    generate(kinto_client, collections, 'tmp',
                             'collection.tpl', 'record.tpl')

                    assert gi.call_count == 1
                    gi.assert_called_with([ADDONS_DATA, PLUGIN_DATA],
                                          collection_template, 'tmp')

                    assert gr.call_count == 2
                    gr.assert_any_call(ADDONS_DATA, record_template, 'tmp',
                                       get_record_filename)
                    gr.assert_any_call(PLUGIN_DATA, record_template, 'tmp',
                                       get_record_filename)

                    mocked_makedirs.assert_called_with('tmp')
Exemplo n.º 2
0
def test_generate_uses_last_modified_if_created_is_missing():
    kinto_client = mock.MagicMock()
    data = ADDONS_DATA.copy()
    del data['details']['created']
    kinto_client.get_records.return_value = [data]
    collections = ['/buckets/blocklists/collections/addons']

    with mock.patch('amo2kinto.generator.os.makedirs'):
        f = mock.mock_open()
        with mock.patch('amo2kinto.generator.open', f, create=True):
            generate(kinto_client, collections, 'tmp', 'collection.tpl', 'record.tpl')

            assert f.return_value.write.call_count == 2

            # Present in index
            assert b'May 13, 2013' in f.return_value.write.call_args_list[0][0][0]

            # Present in the record file
            assert b'May 13, 2013' in f.return_value.write.call_args_list[1][0][0]
def test_generate_uses_last_modified_if_created_is_missing():
    kinto_client = mock.MagicMock()
    data = ADDONS_DATA.copy()
    del data['details']['created']
    kinto_client.get_records.return_value = [data]
    collections = ['/buckets/blocklists/collections/addons']

    with mock.patch('amo2kinto.generator.os.makedirs'):
        f = mock.mock_open()
        with mock.patch('amo2kinto.generator.open', f, create=True):
            generate(kinto_client, collections, 'tmp', 'collection.tpl', 'record.tpl')

            assert f.return_value.write.call_count == 2

            # Present in index
            assert 'May 13, 2013' in f.return_value.write.call_args_list[0][0][0]

            # Present in the record file
            assert 'May 13, 2013' in f.return_value.write.call_args_list[1][0][0]
Exemplo n.º 4
0
def test_generate_grabs_addons_and_plugins_records():
    kinto_client = mock.MagicMock()
    kinto_client.get_records.side_effect = [[ADDONS_DATA], [PLUGIN_DATA]]
    collections = ['/buckets/blocklists/collections/addons',
                   '/buckets/blocklists/collections/plugins']

    collection_template = get_template('collection.tpl')
    record_template = get_template('record.tpl')

    with mock.patch('amo2kinto.generator.os.makedirs') as mocked_makedirs:
        with mock.patch('amo2kinto.generator.get_template',
                        side_effect=[collection_template, record_template]):
            with mock.patch('amo2kinto.generator.generate_index') as gi:
                with mock.patch('amo2kinto.generator.generate_record') as gr:
                    generate(kinto_client, collections, 'tmp', 'collection.tpl', 'record.tpl')

                    assert gi.call_count == 1
                    gi.assert_called_with([ADDONS_DATA, PLUGIN_DATA], collection_template, 'tmp')

                    assert gr.call_count == 2
                    gr.assert_any_call(ADDONS_DATA, record_template, 'tmp', get_record_filename)
                    gr.assert_any_call(PLUGIN_DATA, record_template, 'tmp', get_record_filename)

                    mocked_makedirs.assert_called_with('tmp')