From 4296e0911e0fbc82c30e085f5ac7f7bc0b7e39a4 Mon Sep 17 00:00:00 2001 From: Abhishek Ram Date: Mon, 4 Mar 2019 10:29:04 +0530 Subject: [PATCH] Sync with version 0.0.7 of protean (#6) * Sync with version 0.0.7 of protean * Bump Version * Fix Typo in CHANGELOG --- CHANGELOG.rst | 12 ++++++++++ requirements.txt | 1 + requirements/dev.txt | 1 - setup.py | 4 ++-- src/protean_sqlalchemy/__init__.py | 2 +- src/protean_sqlalchemy/repository.py | 7 ++---- tests/test_repo_ext.py | 10 ++++----- tests/test_repository.py | 33 ++++++++++++---------------- 8 files changed, 37 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a7fa57c..94c77ec 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/requirements.txt b/requirements.txt index b373178..0ff70bf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +protean==0.0.7 click==7.0 sqlalchemy==1.2.14 -r requirements/dev.txt diff --git a/requirements/dev.txt b/requirements/dev.txt index 0bde1b1..48e722f 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -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 diff --git a/setup.py b/setup.py index 9df3914..3091650 100644 --- a/setup.py +++ b/setup.py @@ -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' % ( @@ -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', ], diff --git a/src/protean_sqlalchemy/__init__.py b/src/protean_sqlalchemy/__init__.py index fa9c4ec..2792152 100644 --- a/src/protean_sqlalchemy/__init__.py +++ b/src/protean_sqlalchemy/__init__.py @@ -1 +1 @@ -__version__ = '0.0.6' +__version__ = '0.0.7' diff --git a/src/protean_sqlalchemy/repository.py b/src/protean_sqlalchemy/repository.py index 21ac1ef..12b3509 100644 --- a/src/protean_sqlalchemy/repository.py +++ b/src/protean_sqlalchemy/repository.py @@ -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 @@ -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, @@ -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() diff --git a/tests/test_repo_ext.py b/tests/test_repo_ext.py index b6dc2a1..e41443e 100644 --- a/tests/test_repo_ext.py +++ b/tests/test_repo_ext.py @@ -7,7 +7,7 @@ from protean_sqlalchemy.repository import SqlalchemyModel -from .test_repository import DogModel +from .test_repository import Dog, DogModel class Human(Entity): @@ -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'], @@ -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 diff --git a/tests/test_repository.py b/tests/test_repository.py index 9bfdfdf..94d376c 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -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' @@ -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 @@ -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 @@ -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()