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')
def test_generate_index(): records = [ADDONS_DATA, PLUGIN_DATA] template = get_template('collection.tpl') f = mock.mock_open() with mock.patch('amo2kinto.generator.open', f, create=True): generate_index(records, template, 'tmp') f.assert_called_once_with('tmp/index.html', 'w') handle = f() assert handle.write.call_count == 1
def test_generate_record(): template = get_template('record.tpl') f = mock.mock_open() with mock.patch('amo2kinto.generator.os.makedirs'): with mock.patch('amo2kinto.generator.open', f, create=True): generate_record(ADDONS_DATA, template, 'tmp', get_record_filename) f.assert_called_once_with('tmp/i454.html', 'w') handle = f() assert handle.write.call_count == 1
def test_generate_index(): records = [ADDONS_DATA, PLUGIN_DATA] template = get_template('collection.tpl') f = mock.mock_open() with mock.patch('amo2kinto.generator.open', f, create=True): generate_index(records, template, 'tmp') f.assert_called_once_with('tmp/index.html', 'w', encoding='utf-8') handle = f() assert handle.write.call_count == 1
def test_generate_record(): template = get_template('record.tpl') f = mock.mock_open() with mock.patch('amo2kinto.generator.os.makedirs'): with mock.patch('amo2kinto.generator.open', f, create=True): generate_record(ADDONS_DATA, template, 'tmp', get_record_filename) f.assert_called_once_with('tmp/i454.html', 'w', encoding='utf-8') handle = f() assert handle.write.call_count == 1
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')
def test_get_template(): assert isinstance(get_template('collection.tpl'), Template) assert isinstance(get_template('record.tpl'), Template)