Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: simple JSON test #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio-DB
# Copyright (C) 2015 CERN
# Copyright (C) 2015, 2016 CERN
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
Expand All @@ -21,6 +21,10 @@
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.

addons:
postgresql: "9.4"
mysql: "5.7"

notifications:
email: false

Expand Down Expand Up @@ -48,8 +52,6 @@ env:

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"

before_install:
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@

[pytest]
addopts = --pep8 --ignore=docs --cov=invenio_db --cov-report=term-missing
pep8ignore = W601
10 changes: 3 additions & 7 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015 CERN.
# Copyright (C) 2015, 2016 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand All @@ -21,9 +21,5 @@
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
#
# TODO: Add development versions of some important dependencies here to get a
# warning when there are breaking upstream changes, e.g.:
#
# -e git+git://github.com/mitsuhiko/werkzeug.git#egg=Werkzeug
# -e git+git://github.com/mitsuhiko/jinja2.git#egg=Jinja2

-e git+https://github.com/zzzeek/sqlalchemy.git#egg=sqlalchemy
42 changes: 42 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,45 @@ def test_local_proxy(app, db):
z=LocalProxy(lambda: None),
).fetchone()
assert result == (True, True, True, True)


@pytest.mark.skipif(not hasattr(sa, 'JSON'),
reason='Requires SQLAlchemy>=1.1.0b1')
def test_json(db, app):
"""Test extension initialization."""
from sqlalchemy.dialects import postgresql

InvenioDB(app, db=db)

class TestJSON(db.Model):
__tablename__ = 'test_json'

pk = sa.Column(sa.Integer, primary_key=True)
js = sa.Column(sa.JSON().with_variant(postgresql.JSONB, 'postgresql'))

with app.app_context():
db.drop_all()
db.create_all()

with app.app_context():
db.session.add(TestJSON(pk=1, js={'foo': {'bar': 1}}))
db.session.add(TestJSON(pk=2, js={'baz': 2}))
db.session.commit()

result = TestJSON.query.get(1)
assert 1 == result.js['foo']['bar']

if hasattr(TestJSON.js['foo'], 'astext'):
result = TestJSON.query.filter(
TestJSON.js[('foo', 'bar')].astext.cast(Integer) == 1
).first()
assert 1 == result.pk

if hasattr(TestJSON.js, 'has_key'):
result = TestJSON.query.filter(
TestJSON.js.has_key('baz')
).first()
assert 2 == result.pk

with app.app_context():
db.drop_all()
4 changes: 2 additions & 2 deletions tests/test_versioning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015 CERN.
# Copyright (C) 2015, 2016 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_disabled_versioning(db, app):


@pytest.mark.parametrize("versioning,tables", [
(False, 1), (True, 3)
(False, 1), (True, 3)
])
def test_disabled_versioning_with_custom_table(db, app, versioning, tables):
"""Test SQLAlchemy-Continuum table loading."""
Expand Down