This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The integration tests require a running PostGIS instance and spatial database. This adds two new tox environments to allow for running the unit tests without needing to have PostGIS set up. The full suite of tests will be run during CI.
- Loading branch information
Mike Graves
committed
Jun 16, 2017
1 parent
677bc03
commit e53718f
Showing
12 changed files
with
177 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
try: | ||
from unittest.mock import patch | ||
except ImportError: | ||
from mock import patch | ||
|
||
from click.testing import CliRunner | ||
from dotenv import load_dotenv, find_dotenv | ||
import pytest | ||
|
||
from slingshot.cli import main | ||
from slingshot.db import engine, metadata | ||
|
||
|
||
@pytest.fixture | ||
def runner(): | ||
return CliRunner() | ||
|
||
|
||
@pytest.fixture | ||
def db(): | ||
load_dotenv(find_dotenv()) | ||
uri = os.environ.get('POSTGIS_DB') | ||
engine.configure(uri) | ||
return engine | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def db_setup(db): | ||
metadata.drop_all() | ||
metadata.clear() | ||
|
||
|
||
def test_bag_loads_shapefile(db, runner, shapefile): | ||
store = tempfile.mkdtemp() | ||
layers = tempfile.mkdtemp() | ||
shutil.copy2(shapefile, layers) | ||
uri = os.environ.get('POSTGIS_DB') | ||
res = runner.invoke(main, ['bag', '--db-uri', uri, '--public', | ||
'mock://example.com', '--secure', | ||
'mock://example.com', layers, store]) | ||
assert res.exit_code == 0 | ||
with db().connect() as conn: | ||
r = conn.execute('SELECT COUNT(*) FROM bermuda').scalar() | ||
assert r == 713 | ||
|
||
|
||
def test_bag_creates_bag(runner, shapefile): | ||
store = tempfile.mkdtemp() | ||
layers = tempfile.mkdtemp() | ||
shutil.copy2(shapefile, layers) | ||
uri = os.environ.get('POSTGIS_DB') | ||
res = runner.invoke(main, ['bag', '--db-uri', uri, '--public', | ||
'mock://example.com', '--secure', | ||
'mock://example.com', layers, store]) | ||
assert res.exit_code == 0 | ||
assert 'Loaded layer bermuda' in res.output | ||
|
||
|
||
def test_bag_skips_existing_layers(runner, shapefile, bags_dir): | ||
uri = os.environ.get('POSTGIS_DB') | ||
res = runner.invoke(main, ['bag', '--db-uri', uri, '--public', | ||
'mock://example.com', '--secure', | ||
'mock://example.com', shapefile, bags_dir]) | ||
assert res.exit_code == 0 | ||
assert 'Skipping existing layer bermuda' in res.output | ||
|
||
|
||
def test_bag_removes_failed_bag(runner, shapefile): | ||
store = tempfile.mkdtemp() | ||
uri = os.environ.get('POSTGIS_DB') | ||
with patch('slingshot.cli.load_layer') as m: | ||
m.side_effect = Exception | ||
res = runner.invoke(main, ['bag', '--db-uri', uri, '--public', | ||
'mock://example.com', '--secure', | ||
'mock://example.com', shapefile, store]) | ||
assert res.exit_code == 0 | ||
assert 'Failed creating bag bermuda' in res.output | ||
assert not os.listdir(store) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from click.testing import CliRunner | ||
import pytest | ||
import requests_mock | ||
|
||
from slingshot.cli import main | ||
|
||
|
||
@pytest.fixture | ||
def runner(): | ||
return CliRunner() | ||
|
||
|
||
def test_publish_publishes_layer(runner, bags_dir): | ||
with requests_mock.Mocker() as m: | ||
m.post('mock://example.com/public/rest/workspaces/mit/datastores' | ||
'/data/featuretypes') | ||
m.post('mock://example.com/solr/update') | ||
m.post('mock://example.com/solr/update/json/docs') | ||
res = runner.invoke(main, ['publish', '--public', | ||
'mock://example.com/public', '--secure', | ||
'mock://example.com/secure', '--solr', | ||
'mock://example.com/solr', bags_dir]) | ||
assert res.exit_code == 0 | ||
assert 'Loaded bermuda' in res.output | ||
|
||
|
||
def test_reindex_deletes_and_reloads(runner, bags_dir): | ||
with requests_mock.Mocker() as m: | ||
m.post('mock://example.com/solr/update') | ||
m.post('mock://example.com/solr/update/json/docs') | ||
res = runner.invoke(main, ['reindex', '--solr', | ||
'mock://example.com/solr', bags_dir]) | ||
assert res.exit_code == 0 | ||
assert m.request_history[0].json() == \ | ||
{'delete': {'query': | ||
'dct_provenance_s:MIT AND dc_format_s:Shapefile'}} | ||
assert 'Indexed bermuda' in res.output | ||
assert m.request_history[2].json() == {'commit': {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.