Skip to content

Commit

Permalink
Improve setup and PEP8 validation in test
Browse files Browse the repository at this point in the history
  • Loading branch information
xeBuz committed Oct 4, 2015
1 parent 88095b4 commit 7eacf09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from setuptools import setup


def read(*paths):
"""Build a file path from *paths* and return the contents."""
with open(os.path.join(*paths), 'r') as f:
Expand All @@ -17,14 +18,17 @@ def read(*paths):
packages=['sqlalchemy_elasticquery'],
include_package_data=True,
install_requires=[
'Flask>=0.10',
'SQLAlchemy>=0.7.8',
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Plugins',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Database'
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
14 changes: 9 additions & 5 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy_elasticquery import elastic_query
from sqlalchemy import and_, or_
from flask import Flask

Base = declarative_base()


class City(Base):
__tablename__ = 'city'

Expand All @@ -18,6 +18,7 @@ class City(Base):
def __repr__(self):
return str(self.id)


class User(Base):
__tablename__ = 'users'

Expand All @@ -31,6 +32,7 @@ class User(Base):
def __repr__(self):
return str(self.id)


class TestCase(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -67,7 +69,8 @@ def test_simple_query(self):

def test_and_operator(self):
""" test and operator """
query_string = '{"filter" : {"and" : {"name" : {"like" : "%Jho%"}, "lastname" : "Galt", "uid" : {"like" : "%1957%"} } } }'
query_string = \
'{"filter" : {"and" : {"name" : {"like" : "%Jho%"}, "lastname" : "Galt", "uid" : {"like" : "%1957%"} } } }'
assert(elastic_query(User, query_string, session).count() == 1)

def test_or_operator(self):
Expand All @@ -77,7 +80,8 @@ def test_or_operator(self):

def test_or_and_operator(self):
""" test or and operator """
query_string = '{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Galt" }, "and" : { "uid" : "19571957" } } }'
query_string = \
'{"filter" : {"or" : { "name" : "Jhon", "lastname" : "Galt" }, "and" : { "uid" : "19571957" } } }'
assert(elastic_query(User, query_string, session).count() == 1)

def test_sorting(self):
Expand All @@ -87,7 +91,6 @@ def test_sorting(self):
assert(results[0].name == 'Iron')

def test_flask(self):
#Flask app
app = Flask(__name__)
db = SQLAlchemy(app)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
Expand Down Expand Up @@ -126,7 +129,8 @@ def test_allow_fields_option(self):

def test_search_for_levels(self):
""" test search for levels """
query_string = '{"filter" : {"or" : { "city.name" : "New York", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
query_string = \
'{"filter" : {"or" : { "city.name" : "New York", "lastname" : "Man" } }, "sort": { "name" : "asc" } }'
results = elastic_query(User, query_string, session).all()
assert(results[0].name == 'Iron')

Expand Down

0 comments on commit 7eacf09

Please sign in to comment.