diff --git a/tests/fixtures.py b/tests/fixtures.py index 26247215..92fd5073 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,5 +1,6 @@ from datasette.app import Datasette import itertools +import json import os import pytest import random @@ -98,12 +99,12 @@ def generate_sortable_rows(num): METADATA = { - 'title': 'Datasette Title', - 'description': 'Datasette Description', - 'license': 'License', - 'license_url': 'http://www.example.com/license', - 'source': 'Source', - 'source_url': 'http://www.example.com/source', + 'title': 'Datasette Fixtures', + 'description': 'An example SQLite database demonstrating Datasette', + 'license': 'Apache License 2.0', + 'license_url': 'https://github.com/simonw/datasette/blob/master/LICENSE', + 'source': 'tests/fixtures.py', + 'source_url': 'https://github.com/simonw/datasette/blob/master/tests/fixtures.py', 'databases': { 'fixtures': { 'description': 'Test tables description', @@ -381,10 +382,20 @@ CREATE VIEW simple_view AS ]) if __name__ == '__main__': - filename = sys.argv[-1] - if filename.endswith('.db'): - conn = sqlite3.connect(filename) + # Can be called with data.db OR data.db metadata.json + db_filename = sys.argv[-1] + metadata_filename = None + if db_filename.endswith(".json"): + metadata_filename = db_filename + db_filename = sys.argv[-2] + if db_filename.endswith(".db"): + conn = sqlite3.connect(db_filename) conn.executescript(TABLES) - print('Test tables written to {}'.format(filename)) + print("Test tables written to {}".format(db_filename)) + if metadata_filename: + open(metadata_filename, 'w').write(json.dumps(METADATA)) + print("- metadata written to {}".format(metadata_filename)) else: - print('Usage: {} name_of_file_to_write.db'.format(sys.argv[0])) + print("Usage: {} db_to_write.db [metadata_to_write.json]".format( + sys.argv[0] + )) diff --git a/tests/test_html.py b/tests/test_html.py index 248c95b0..678ce696 100644 --- a/tests/test_html.py +++ b/tests/test_html.py @@ -458,8 +458,8 @@ def test_index_metadata(app_client): response = app_client.get('/') assert response.status == 200 soup = Soup(response.body, 'html.parser') - assert 'Datasette Title' == soup.find('h1').text - assert 'Datasette Description' == inner_html( + assert 'Datasette Fixtures' == soup.find('h1').text + assert 'An example SQLite database demonstrating Datasette' == inner_html( soup.find('div', {'class': 'metadata-description'}) ) assert_footer_links(soup) @@ -547,11 +547,11 @@ def assert_footer_links(soup): assert 3 == len(footer_links) datasette_link, license_link, source_link = footer_links assert 'Datasette' == datasette_link.text.strip() - assert 'Source' == source_link.text.strip() - assert 'License' == license_link.text.strip() + assert 'tests/fixtures.py' == source_link.text.strip() + assert 'Apache License 2.0' == license_link.text.strip() assert 'https://github.com/simonw/datasette' == datasette_link['href'] - assert 'http://www.example.com/source' == source_link['href'] - assert 'http://www.example.com/license' == license_link['href'] + assert 'https://github.com/simonw/datasette/blob/master/tests/fixtures.py' == source_link['href'] + assert 'https://github.com/simonw/datasette/blob/master/LICENSE' == license_link['href'] def inner_html(soup):