Permalink
Comparing changes
Open a pull request
- 7 commits
- 8 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
54 additions
and 41 deletions.
- +9 −0 .buildkite/bin/test-backend
- +15 −0 .buildkite/bin/test-frontend
- +0 −3 .travis.yml
- +2 −2 Dockerfile
- +0 −3 Makefile
- +0 −1 conf/test.ini
- +0 −14 h/conftest.py
- +28 −18 h/test/models_test.py
| @@ -0,0 +1,9 @@ | ||
| #!/bin/sh | ||
| set -eu | ||
| echo "--- Installing dependencies" | ||
| pip install -e .[dev,testing,YAML] | ||
| echo "+++ Running tests"t | ||
| exec python setup.py test --cov |
| @@ -0,0 +1,15 @@ | ||
| #!/bin/sh | ||
| set -eu | ||
| export DEBIAN_FRONTEND=noninteractive | ||
| echo "--- Installing PhantomJS" | ||
| apt-get update | ||
| apt-get install -y phantomjs | ||
| echo "--- Installing dependencies" | ||
| npm install | ||
| echo "+++ Running tests" | ||
| exec $(npm bin)/karma start h/static/scripts/karma.config.js --single-run |
| @@ -2,9 +2,6 @@ language: | ||
| - python | ||
| python: | ||
| - '2.7' | ||
| before_install: | ||
| - sudo /usr/share/elasticsearch/bin/plugin -install elasticsearch/elasticsearch-analysis-icu/2.4.1 | ||
| - sudo service elasticsearch restart | ||
| install: | ||
| - gem install sass | ||
| - gem install compass | ||
| @@ -51,12 +51,12 @@ ADD gunicorn.conf.py /src/h/ | ||
| ADD bin /src/h/bin | ||
| ADD conf /src/h/conf | ||
| ADD h /src/h/h | ||
| ADD .buildkite /src/h/.buildkite | ||
| RUN pip install -r requirements.txt | ||
| # Services (for runit) | ||
| ADD ./svc /etc/service | ||
| # Startup and ports | ||
| ENTRYPOINT ["/sbin/my_init"] | ||
| CMD [] | ||
| CMD ["/sbin/my_init"] | ||
| EXPOSE 8000 | ||
| @@ -24,9 +24,6 @@ dev: | ||
| @gunicorn --reload --paste conf/development.ini | ||
| test: | ||
| @echo -n "Checking to see if elasticsearch is running..." | ||
| $(eval es := $(shell wget --quiet --output-document - http://localhost:9200)) | ||
| @if [ -n '${es}' ] ; then echo "yes." ; else echo "no!"; exit 1; fi | ||
| @python setup.py test | ||
| @"$$(npm bin)"/karma start h/static/scripts/karma.config.js --single-run | ||
| @"$$(npm bin)"/karma start h/browser/chrome/karma.config.js --single-run | ||
| @@ -2,7 +2,6 @@ | ||
| use: egg:h | ||
| es.host: http://localhost:9200 | ||
| es.index: annotator_test | ||
| sqlalchemy.url: sqlite:// | ||
| @@ -15,9 +15,6 @@ | ||
| from sqlalchemy.orm import scoped_session, sessionmaker | ||
| from zope.sqlalchemy import ZopeTransactionExtension | ||
| from h.api.db import create_db, delete_db | ||
| from h.api.db import store_from_settings | ||
| @pytest.fixture(scope='session', autouse=True) | ||
| def settings(): | ||
| @@ -90,17 +87,6 @@ def flush(self): | ||
| return sess | ||
| @pytest.fixture() | ||
| def es_connection(request, settings): | ||
| es = store_from_settings(settings) | ||
| create_db() | ||
| # Pylint issue #258: https://bitbucket.org/logilab/pylint/issue/258 | ||
| # | ||
| # pylint: disable=unexpected-keyword-arg | ||
| es.conn.cluster.health(wait_for_status='yellow') | ||
| request.addfinalizer(delete_db) | ||
| @pytest.fixture() | ||
| def mailer(config): | ||
| from pyramid_mailer.interfaces import IMailer | ||
| @@ -1,9 +1,9 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import unittest | ||
| import pytest | ||
| from pytest import fixture, raises | ||
| from pyramid import security | ||
| import re | ||
| from h import models | ||
| @@ -60,20 +60,30 @@ def test_group_authenticated(self): | ||
| assert actual == expect | ||
| @pytest.mark.usefixtures('es_connection') | ||
| def test_uri_mapping(): | ||
| permissions = { | ||
| 'read': ['group:__world__'], | ||
| } | ||
| a1 = models.Annotation(uri='http://example.com/page#hashtag', | ||
| permissions=permissions) | ||
| a1.save() | ||
| a2 = models.Annotation(uri='http://example.com/page', | ||
| permissions=permissions) | ||
| a2.save() | ||
| a3 = models.Annotation(uri='http://totallydifferent.domain.com/', | ||
| permissions=permissions) | ||
| a3.save() | ||
| res = models.Annotation.search(query={'uri': 'example.com/page'}) | ||
| assert len(res) == 2 | ||
| analysis = models.Annotation.__analysis__ | ||
| index_patterns = analysis['filter']['uri_index']['patterns'] | ||
| search_patterns = analysis['filter']['uri_search']['patterns'] | ||
| def test_uri_search_indexes_hash_variants(): | ||
| caps = _pattern_captures(index_patterns, 'http://example.com/page#hash') | ||
| assert 'example.com/page' in caps | ||
| def test_uri_search_searches_hash_variants(): | ||
| caps = _pattern_captures(search_patterns, 'http://example.com/page#hash') | ||
| assert 'example.com/page' in caps | ||
| # Simulate the ElasticSearch pattern_capture filter! | ||
| def _pattern_captures(patterns, uri): | ||
| result = [] | ||
| patterns_re = [re.compile(p) for p in patterns] | ||
| for p in patterns_re: | ||
| m = p.search(uri) | ||
| if m is not None: | ||
| result.append(m.group(1)) | ||
| return result | ||