Skip to content

Commit

Permalink
Sync with version 0.0.7 of protean (#6)
Browse files Browse the repository at this point in the history
* Sync with version 0.0.7 of protean

* Bump Version

* Fix Typo in CHANGELOG
  • Loading branch information
abhishek-ram authored and Subhash Bhushan committed Mar 4, 2019
1 parent 4a7fdde commit 4296e09
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ Changelog
------------------

* First release on PyPI.


0.0.6 (2018-12-28)
------------------

* Match with version 0.0.6 of protean


0.0.7 (2019-03-04)
------------------

* Match with version 0.0.7 of protean
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
protean==0.0.7
click==7.0
sqlalchemy==1.2.14
-r requirements/dev.txt
1 change: 0 additions & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ flake8==3.5.0
pylint==2.0.0
tox==3.1.2
twine==1.11.0
git+git://github.com/proteanhq/protean@master#egg=protean
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def read(*names, **kwargs):

setup(
name='protean-sqlalchemy',
version='0.0.6',
version='0.0.7',
license='BSD 3-Clause License',
description='Protean Sqlalachemy Extension',
long_description='%s\n%s' % (
Expand Down Expand Up @@ -64,7 +64,7 @@ def read(*names, **kwargs):
],
install_requires=[
'click==7.0',
'protean==0.0.6',
'protean==0.0.7',
'sqlalchemy==1.2.14'
# eg: 'aspectlib==1.1.1', 'six>=1.7',
],
Expand Down
2 changes: 1 addition & 1 deletion src/protean_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.6'
__version__ = '0.0.7'
7 changes: 2 additions & 5 deletions src/protean_sqlalchemy/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from protean.core.repository import BaseAdapter
from protean.core.repository import BaseModel
from protean.core.repository import Pagination

from sqlalchemy import create_engine
from sqlalchemy import orm
from sqlalchemy.engine.url import make_url
Expand Down Expand Up @@ -103,13 +104,13 @@ def _filter_objects(self, page: int = 1, per_page: int = 10, # noqa: C901
qs = qs.order_by(*order_cols)

# apply limit and offset filters only if per_page is not None
total = qs.count()
if per_page > 0:
offset = (page - 1) * per_page
qs = qs.limit(per_page).offset(offset)

# Return the results
try:
total = qs.count()
result = Pagination(
page=page,
per_page=per_page,
Expand Down Expand Up @@ -170,7 +171,3 @@ def _delete_objects(self, **filters):
self.conn.rollback()
raise
return del_count

def delete_all(self):
""" Delete all records in this model """
self._delete_objects()
10 changes: 5 additions & 5 deletions tests/test_repo_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from protean_sqlalchemy.repository import SqlalchemyModel

from .test_repository import DogModel
from .test_repository import Dog, DogModel


class Human(Entity):
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_create(self):
""" Test creating an entity with all field types"""

# Create the entity and validate the results
human = repo_factory.HumanModel.create(
human = Human.create(
name='John Doe', age='30', weight='13.45',
date_of_birth='01-01-2000',
hobbies=['swimming'],
Expand All @@ -76,14 +76,14 @@ def test_create(self):
assert human.to_dict() == expected

# Check if the object is in the repo
human = repo_factory.HumanModel.get(1)
human = Human.get(1)
assert human is not None
assert human.to_dict() == expected

def test_multiple_dbs(self):
""" Test repository connections to multiple databases"""
humans = repo_factory.HumanModel.filter()
humans = Human.filter()
assert humans is not None

dogs = repo_factory.DogModel.filter()
dogs = Dog.filter()
assert dogs is not None
33 changes: 14 additions & 19 deletions tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def teardown_class(cls):
def test_create(self):
""" Test creating an entity in the repository"""
# Create the entity and validate the results
dog = repo_factory.DogModel.create(name='Johnny', owner='John')
dog = Dog.create(name='Johnny', owner='John')
assert dog is not None
assert dog.id == 1
assert dog.name == 'Johnny'
Expand All @@ -94,14 +94,15 @@ def test_create(self):

# Check for unique validation
with pytest.raises(ValidationError) as e_info:
repo_factory.DogModel.create(name='Johnny', owner='John')
Dog.create(name='Johnny', owner='John')
assert e_info.value.normalized_messages == {
'name': ['`dogs` with this `name` already exists.']}

def test_update(self, mocker):
""" Test updating an entity in the repository"""
# Update the entity and validate the results
dog = repo_factory.DogModel.update(identifier=1, data=dict(age=7))
dog = Dog.get(1)
dog.update(dict(age=7))
assert dog is not None
assert dog.age == 7

Expand All @@ -114,34 +115,33 @@ def test_update(self, mocker):

def test_filter(self):
""" Test reading entities from the repository"""
repo_factory.DogModel.create(name='Cash', owner='John', age=10)
repo_factory.DogModel.create(name='Boxy', owner='Carry', age=4)
repo_factory.DogModel.create(name='Gooey', owner='John', age=2)
Dog.create(name='Cash', owner='John', age=10)
Dog.create(name='Boxy', owner='Carry', age=4)
Dog.create(name='Gooey', owner='John', age=2)

# Filter the entity and validate the results
dogs = repo_factory.DogModel.filter(page=1, per_page=15, order_by='-age',
owner='John')
dogs = Dog.filter(page=1, per_page=15, order_by=['-age'], owner='John')
assert dogs is not None
assert dogs.total == 3
dog_ages = [d.age for d in dogs.items]
assert dog_ages == [10, 7, 2]

# Test In and not in query
dogs = repo_factory.DogModel.filter(name=['Cash', 'Boxy'])
dogs = Dog.filter(name=['Cash', 'Boxy'])
assert dogs.total == 2

dogs = repo_factory.DogModel.filter(excludes_=dict(name=['Cash', 'Gooey']),
owner='John')
dogs = Dog.filter(excludes_=dict(name=['Cash', 'Gooey']), owner='John')
assert dogs.total == 1

# Test for sql alchemy filter
dogs = repo_factory.DogModel.filter(filter_=(DogModel.age > 8))
dogs = Dog.filter(filter_=(DogModel.age > 8))
assert dogs.total == 1

def test_delete(self):
""" Test deleting an entity from the repository"""
# Delete the entity and validate the results
cnt = repo_factory.DogModel.delete(1)
dog = Dog.get(1)
cnt = dog.delete()
assert cnt == 1

# Make sure that the entity is deleted
Expand All @@ -152,14 +152,9 @@ def test_delete(self):
def test_delete_all(self):
""" Test deleting all entries from the repository"""
# Delete the entity and validate the results
cnt = repo_factory.DogModel.filter().total
cnt = Dog.filter().total
assert cnt == 3

# Delete all and make sure that the entity is deleted
repo_factory.DogModel.delete_all()
cnt = repo_factory.DogModel.filter().total
assert cnt == 0

def test_close_connection(self):
""" Test closing connection to the repository """
repo_factory.close_connections()

0 comments on commit 4296e09

Please sign in to comment.