From b629180d92f03b49b09f3b2c71f5609bd14f0c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 12 Apr 2017 13:39:47 +0200 Subject: [PATCH 1/7] Fixed creating user_role_table --- .gitignore | 3 ++- flask_permissions/models.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 68830e9..30e4cee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.egg-info dist cover -.coverage \ No newline at end of file +.coverage +*.pyc diff --git a/flask_permissions/models.py b/flask_permissions/models.py index 318d1fb..495177d 100644 --- a/flask_permissions/models.py +++ b/flask_permissions/models.py @@ -127,7 +127,8 @@ def _id_column_name(self): @declared_attr def _roles(self): - user_role_table = make_user_role_table(self.__tablename__, self._id_column_name) + user_role_table = make_user_role_table(self.__tablename__, + self._id_column_name.fget(self)) return db.relationship( 'Role', secondary=user_role_table, backref='users') @@ -170,4 +171,4 @@ def get_id(self): return unicode(getattr(self, self._id_column_name)) def __repr__(self): - return '<{} {}>'.format(self.__tablename__.capitalize(), self.get_id()) \ No newline at end of file + return '<{} {}>'.format(self.__tablename__.capitalize(), self.get_id()) From 3481373308c716012efa53388289a26db83681f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 12 Apr 2017 13:55:35 +0200 Subject: [PATCH 2/7] Suppressed sqlalchemy warning, files parsed with 2to3 --- flask_permissions/models.py | 8 ++++---- flask_permissions/tests.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/flask_permissions/models.py b/flask_permissions/models.py index 495177d..0d691ce 100644 --- a/flask_permissions/models.py +++ b/flask_permissions/models.py @@ -114,14 +114,14 @@ def _id_column_name(self): # the list of the class's columns (with attributes like # 'primary_key', etc.) is accessible in different places # before and after table definition. - if self.__tablename__ in self.metadata.tables.keys(): + if self.__tablename__ in list(self.metadata.tables.keys()): # after definition, it's here columns = self.metadata.tables[self.__tablename__]._columns else: # before, it's here columns = self.__dict__ - for k, v in columns.items(): + for k, v in list(columns.items()): if getattr(v, 'primary_key', False): return k @@ -139,7 +139,7 @@ def roles(self): def __init__(self, roles=None, default_role='user'): # If only a string is passed for roles, convert it to a list containing # that string - if roles and isinstance(roles, basestring): + if roles and isinstance(roles, str): roles = [roles] # If a sequence is passed for roles (or if roles has been converted to @@ -168,7 +168,7 @@ def remove_roles(self, *roles): self.roles = [role for role in self.roles if role not in roles] def get_id(self): - return unicode(getattr(self, self._id_column_name)) + return str(getattr(self, self._id_column_name)) def __repr__(self): return '<{} {}>'.format(self.__tablename__.capitalize(), self.get_id()) diff --git a/flask_permissions/tests.py b/flask_permissions/tests.py index 75d6e08..326c347 100644 --- a/flask_permissions/tests.py +++ b/flask_permissions/tests.py @@ -15,6 +15,7 @@ db_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'app.db') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_path +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) @@ -83,7 +84,7 @@ def test_user_get_id(self): user = User() db.session.add(user) db.session.commit() - self.assertEqual(user.get_id(), unicode(1)) + self.assertEqual(user.get_id(), str(1)) def test_user_repr(self): user = User() From 2fe7368b27ff8da845650aaa436d8fad2766edae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 12 Apr 2017 14:17:02 +0200 Subject: [PATCH 3/7] assertItemsEqual() (removed in python3) tests changed to assertEqual() --- flask_permissions/tests.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/flask_permissions/tests.py b/flask_permissions/tests.py index 326c347..c295924 100644 --- a/flask_permissions/tests.py +++ b/flask_permissions/tests.py @@ -127,7 +127,8 @@ def test_add_roles_with_nonexisting_roles(self): db.session.add(user) db.session.commit() test_user = User.query.get(1) - self.assertItemsEqual(new_roles, test_user.roles) + # self.assertItemsEqual(new_roles, test_user.roles) + self.assertEqual(sorted(new_roles), sorted(test_user.roles)) def test_add_roles_with_existing_roles(self): user = User(default_role=None) @@ -140,7 +141,8 @@ def test_add_roles_with_existing_roles(self): db.session.add(user) db.session.commit() test_user = User.query.get(1) - self.assertItemsEqual(new_roles, test_user.roles) + # self.assertItemsEqual(new_roles, test_user.roles) + self.assertEqual(sorted(new_roles), sorted(test_user.roles)) def test_remove_roles(self): user = User() @@ -153,7 +155,8 @@ def test_remove_roles(self): db.session.add(user) db.session.commit() test_user = User.query.get(1) - self.assertItemsEqual(test_user.roles, ['superadmin']) + # self.assertItemsEqual(test_user.roles, ['superadmin']) + self.assertEqual(sorted(test_user.roles), sorted(['superadmin'])) def test_add_abilities_with_nonexisting_abilities(self): role = Role('admin') @@ -163,7 +166,8 @@ def test_add_abilities_with_nonexisting_abilities(self): db.session.commit() test_role = Role.query.get(1) abilities = [ability.name for ability in test_role.abilities] - self.assertItemsEqual(new_abilities, abilities) + # self.assertItemsEqual(new_abilities, abilities) + self.assertEqual(sorted(new_abilities), sorted(abilities)) def test_add_abilities_with_existing_abilities(self): role = Role('admin') @@ -177,7 +181,8 @@ def test_add_abilities_with_existing_abilities(self): db.session.commit() test_role = Role.query.get(1) abilities = [ability.name for ability in test_role.abilities] - self.assertItemsEqual(new_abilities, abilities) + # self.assertItemsEqual(new_abilities, abilities) + self.assertEqual(sorted(new_abilities), sorted(abilities)) def test_remove_abilities(self): role = Role('admin') @@ -191,7 +196,8 @@ def test_remove_abilities(self): db.session.commit() test_role = Role.query.get(1) abilities = [ability.name for ability in test_role.abilities] - self.assertItemsEqual(abilities, ['create_users']) + # self.assertItemsEqual(abilities, ['create_users']) + self.assertEqual(sorted(abilities), sorted(['create_users'])) class DecoratorsTests(DatabaseTests): @@ -272,3 +278,7 @@ def test_is_tuple_a_sequence(self): def test_is_dict_a_sequence(self): dict_var = {'a': 1, 'b': 2, 'c': 3} self.assertTrue(is_sequence(dict_var)) + + +if __name__ == '__main__': # optional, but makes import and reuse easier + unittest.main() From 2dfc37529eaafa46219a8144650b1dae4e2f7a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 12 Apr 2017 14:36:03 +0200 Subject: [PATCH 4/7] Fixed is_sequence() for python 3 --- flask_permissions/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flask_permissions/utils.py b/flask_permissions/utils.py index 4778015..33b9969 100644 --- a/flask_permissions/utils.py +++ b/flask_permissions/utils.py @@ -1,4 +1,4 @@ def is_sequence(arg): - return (not hasattr(arg, "strip") and - hasattr(arg, "__getitem__") or - hasattr(arg, "__iter__")) + if hasattr(arg, "strip"): + return False + return (hasattr(arg, "__getitem__") or hasattr(arg, "__iter__")) From 2316540d546efb1223df27f37698953fd7855e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 12 Apr 2017 14:48:41 +0200 Subject: [PATCH 5/7] updated requirements.txt and .travis.yml --- .travis.yml | 10 ++++++---- requirements.txt | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 502e915..cee151e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python -python: "2.7" +python: + - "2.7" + - "3.5" install: - - pip install -r requirements.txt --allow-external twill --allow-unverified twill - - pip install coverage nose lxml requests cssselect -script: nosetests --with-coverage --cover-package=flask_permissions \ No newline at end of file + - pip install -r requirements.txt + - pip install nose coverage +script: nosetests --with-coverage --cover-package=flask_permissions diff --git a/requirements.txt b/requirements.txt index 8ef1fe2..e957b76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,13 @@ -Flask==0.10.1 -Flask-Testing==0.4 -Flask-SQLAlchemy==1.0 -Werkzeug==0.9.4 -wsgiref==0.1.2 +appdirs==1.4.3 +click==6.7 +Flask==0.12.1 +Flask-SQLAlchemy==2.2 +Flask-Testing==0.6.2 +itsdangerous==0.24 +Jinja2==2.9.6 +MarkupSafe==1.0 +packaging==16.8 +pyparsing==2.2.0 +six==1.10.0 +SQLAlchemy==1.1.9 +Werkzeug==0.12.1 From 7ebe67dee4e0c010bc5a0213655a9b2e2807733f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 10 May 2017 10:43:22 +0200 Subject: [PATCH 6/7] Requirements cleaned up, updated .travis.yml --- .travis.yml | 2 +- requirements.txt | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index cee151e..0ab26ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ python: - "3.5" install: - pip install -r requirements.txt - - pip install nose coverage + - pip install nose coverage flask_testing script: nosetests --with-coverage --cover-package=flask_permissions diff --git a/requirements.txt b/requirements.txt index e957b76..a8cddf6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,9 @@ -appdirs==1.4.3 click==6.7 Flask==0.12.1 Flask-SQLAlchemy==2.2 -Flask-Testing==0.6.2 itsdangerous==0.24 Jinja2==2.9.6 MarkupSafe==1.0 -packaging==16.8 -pyparsing==2.2.0 -six==1.10.0 SQLAlchemy==1.1.9 Werkzeug==0.12.1 + From 82be1374e238bfcc0d8c850cb4aaf55d58ee2e47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdzis=C5=82aw=20Krajewski?= Date: Wed, 10 May 2017 11:03:15 +0200 Subject: [PATCH 7/7] Requirements for testing freezed in separate file, updated .travis.yml --- .travis.yml | 2 +- requirements_test.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 requirements_test.txt diff --git a/.travis.yml b/.travis.yml index 0ab26ae..b81a2e9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ python: - "3.5" install: - pip install -r requirements.txt - - pip install nose coverage flask_testing + - pip install -r requirements_test.txt script: nosetests --with-coverage --cover-package=flask_permissions diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 0000000..ea1ffad --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1,3 @@ +coverage==4.4 +Flask-Testing==0.6.2 +nose==1.3.7