From d6409eeaf5a88ef36d509e70175905e1b8b834e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lombra=C3=B1a=20Gonz=C3=A1lez?= Date: Thu, 23 Jun 2022 15:32:14 +0200 Subject: [PATCH] chore: fix dependencies. (#2045) * chore: fix dependencies. * chore: update dependencies. * chore: remove PyGobject * chore: fix dependencies. * chore: pin werkzeug version. * chore: pin wtforms version. * chore: pin versions. * chore: remove CSRF check. * chore: fix dependencies --- pybossa/core.py | 10 +- pybossa/repositories/project_repository.py | 93 +++++++----- setup.py | 56 +++---- .../test_project_repository.py | 139 +++++++----------- 4 files changed, 149 insertions(+), 149 deletions(-) diff --git a/pybossa/core.py b/pybossa/core.py index 173fa2946e..b6993974df 100644 --- a/pybossa/core.py +++ b/pybossa/core.py @@ -561,11 +561,11 @@ def _global_template_context(): plugins=plugins, ldap_enabled=ldap_enabled) - @csrf.error_handler - def csrf_error_handler(reason): - response = dict(template='400.html', code=400, - description=reason) - return handle_content_type(response) + # @csrf.error_handler + # def csrf_error_handler(reason): + # response = dict(template='400.html', code=400, + # description=reason) + # return handle_content_type(response) def setup_jinja2_filters(app): diff --git a/pybossa/repositories/project_repository.py b/pybossa/repositories/project_repository.py index 7d7b033cd9..e8d0fa4df0 100644 --- a/pybossa/repositories/project_repository.py +++ b/pybossa/repositories/project_repository.py @@ -42,15 +42,24 @@ def get_by(self, **attributes): def get_all(self): return self.db.session.query(Project).all() - def filter_by(self, limit=None, offset=0, yielded=False, last_id=None, - fulltextsearch=None, desc=False, **filters): - if filters.get('owner_id'): - filters['owner_id'] = filters.get('owner_id') - return self._filter_by(Project, limit, offset, yielded, last_id, - fulltextsearch, desc, **filters) + def filter_by( + self, + limit=None, + offset=0, + yielded=False, + last_id=None, + fulltextsearch=None, + desc=False, + **filters + ): + if filters.get("owner_id"): + filters["owner_id"] = filters.get("owner_id") + return self._filter_by( + Project, limit, offset, yielded, last_id, fulltextsearch, desc, **filters + ) def save(self, project): - self._validate_can_be('saved', project) + self._validate_can_be("saved", project) self._empty_strings_to_none(project) self._creator_is_owner(project) try: @@ -61,10 +70,10 @@ def save(self, project): raise DBIntegrityError(e) def update(self, project): - self._validate_can_be('updated', project) - self._empty_strings_to_none(project) - self._creator_is_owner(project) try: + self._validate_can_be("updated", project) + self._empty_strings_to_none(project) + self._creator_is_owner(project) self.db.session.merge(project) self.db.session.commit() except IntegrityError as e: @@ -72,14 +81,15 @@ def update(self, project): raise DBIntegrityError(e) def delete(self, project): - self._validate_can_be('deleted', project) - project = self.db.session.query(Project).filter(Project.id==project.id).first() + self._validate_can_be("deleted", project) + project = ( + self.db.session.query(Project).filter(Project.id == project.id).first() + ) self.db.session.delete(project) self.db.session.commit() cached_projects.clean(project.id) self._delete_zip_files_from_store(project) - # Methods for Category objects def get_category(self, id=None): if id is None: @@ -92,17 +102,33 @@ def get_category_by(self, **attributes): def get_all_categories(self): return self.db.session.query(Category).all() - def filter_categories_by(self, limit=None, offset=0, yielded=False, - last_id=None, fulltextsearch=None, - orderby='id', - desc=False, **filters): - if filters.get('owner_id'): - del filters['owner_id'] - return self._filter_by(Category, limit, offset, yielded, last_id, - fulltextsearch, desc, orderby, **filters) + def filter_categories_by( + self, + limit=None, + offset=0, + yielded=False, + last_id=None, + fulltextsearch=None, + orderby="id", + desc=False, + **filters + ): + if filters.get("owner_id"): + del filters["owner_id"] + return self._filter_by( + Category, + limit, + offset, + yielded, + last_id, + fulltextsearch, + desc, + orderby, + **filters + ) def save_category(self, category): - self._validate_can_be('saved as a Category', category, klass=Category) + self._validate_can_be("saved as a Category", category, klass=Category) try: self.db.session.add(category) self.db.session.commit() @@ -111,7 +137,7 @@ def save_category(self, category): raise DBIntegrityError(e) def update_category(self, new_category, caller="web"): - self._validate_can_be('updated as a Category', new_category, klass=Category) + self._validate_can_be("updated as a Category", new_category, klass=Category) try: self.db.session.merge(new_category) self.db.session.commit() @@ -120,16 +146,16 @@ def update_category(self, new_category, caller="web"): raise DBIntegrityError(e) def delete_category(self, category): - self._validate_can_be('deleted as a Category', category, klass=Category) - self.db.session.query(Category).filter(Category.id==category.id).delete() + self._validate_can_be("deleted as a Category", category, klass=Category) + self.db.session.query(Category).filter(Category.id == category.id).delete() self.db.session.commit() def _empty_strings_to_none(self, project): - if project.name == '': + if project.name == "": project.name = None - if project.short_name == '': + if project.short_name == "": project.short_name = None - if project.description == '': + if project.description == "": project.description = None def _creator_is_owner(self, project): @@ -141,18 +167,19 @@ def _creator_is_owner(self, project): def _validate_can_be(self, action, element, klass=Project): if not isinstance(element, klass): name = element.__class__.__name__ - msg = '%s cannot be %s by %s' % (name, action, self.__class__.__name__) + msg = "%s cannot be %s by %s" % (name, action, self.__class__.__name__) raise WrongObjectError(msg) def _delete_zip_files_from_store(self, project): from pybossa.core import json_exporter, csv_exporter + global uploader if uploader is None: from pybossa.core import uploader - json_tasks_filename = json_exporter.download_name(project, 'task') - csv_tasks_filename = csv_exporter.download_name(project, 'task') - json_taskruns_filename = json_exporter.download_name(project, 'task_run') - csv_taskruns_filename = csv_exporter.download_name(project, 'task_run') + json_tasks_filename = json_exporter.download_name(project, "task") + csv_tasks_filename = csv_exporter.download_name(project, "task") + json_taskruns_filename = json_exporter.download_name(project, "task_run") + csv_taskruns_filename = csv_exporter.download_name(project, "task_run") container = "user_%s" % project.owner_id uploader.delete_file(json_tasks_filename, container) uploader.delete_file(csv_tasks_filename, container) diff --git a/setup.py b/setup.py index 102b68c075..1aeaac13c4 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -with open('pybossa/version.txt') as f: +with open("pybossa/version.txt") as f: version = f.readline() __version__ = version.rstrip() @@ -14,7 +14,7 @@ "certifi==2018.11.29", "cffi>=1.11.5", "chardet==3.0.4", - "Click==7.0", + "Click==8.0.3", "colorama==0.4.1", "cov-core==1.15.0", "coverage==4.5.2", @@ -27,7 +27,7 @@ "factory-boy==2.4.1", "Faker==1.0.1", "feedparser==5.2.1", - "Flask", + "Flask==1.1.2", "Flask-Assets==0.12", "Flask-Babel>=0.9", "Flask-Cors>=3.0.2", @@ -40,8 +40,8 @@ "Flask-Plugins>=1.6.1", "flask-profiler==1.6", "Flask-SimpleLDAP>=1.1.2", - "Flask-SQLAlchemy>=2.3.2", - "Flask-WTF>=0.9.5", + "Flask-SQLAlchemy==2.4.4", + "Flask-WTF==0.14.3", "flatten-json==0.1.6", "google-api-python-client==1.5.5", "html2text==2014.7.3", @@ -54,7 +54,7 @@ "iso8601==0.1.12", "itsdangerous==1.1.0", "jeepney==0.4", - "Jinja2>=2.10.1", + "Jinja2==2.11.2", "jsmin==2.2.2", "keyring==17.1.1", "keystoneauth1==3.11.2", @@ -95,7 +95,7 @@ "PyLD==1.0.4", "pyldap==3.0.0.post1", "pyOpenSSL==18.0.0", - "pyparsing==2.3.0", + "pyparsing==2.4.7", "python-dateutil==2.7.5", "python-editor==1.0.3", "python-keystoneclient==3.18.0", @@ -132,16 +132,16 @@ "urllib3==1.24.2", "validators==0.12.6", "webassets==0.12.1", - "Werkzeug", + "Werkzeug==1.0.1", "wrapt==1.10.11", - "WTForms>=1.0.5", - "WTForms-Components>=0.10.3", + "WTForms==2.3.3", + "WTForms-Components==0.10.5", "yacryptopan==1.0.0", - "email_validator==1.1.1" + "email_validator==1.1.1", ] setup( - name='pybossa', + name="pybossa", version=__version__, packages=find_packages(), install_requires=requirements, @@ -153,23 +153,23 @@ # 'git+git@github.com:Scifabric/pybossa.git@b8ab2ef199e82ca417d470bbed916c7b8dbda4d4#egg=pybossa' # ] # metadata for upload to PyPI - author='Scifabric LTD', - author_email='info@scifabric.com', - description='Open Source CrowdSourcing framework', - long_description='''PYBOSSA is the ultimate crowdsourcing framework to analyze or enrich data that can't be processed by machines alone.''', - license='AGPLv3', - url='http://pybossa.com', - download_url='https://github.com/Scifabric/pybossa', + author="Scifabric LTD", + author_email="info@scifabric.com", + description="Open Source CrowdSourcing framework", + long_description="""PYBOSSA is the ultimate crowdsourcing framework to analyze or enrich data that can't be processed by machines alone.""", + license="AGPLv3", + url="http://pybossa.com", + download_url="https://github.com/Scifabric/pybossa", include_package_data=True, classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: GNU Affero v3', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Topic :: Software Development :: Libraries :: Python Modules' + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Affero v3", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Topic :: Software Development :: Libraries :: Python Modules", ], - entry_points=''' - ''' + entry_points=""" + """, ) diff --git a/test/test_repository/test_project_repository.py b/test/test_repository/test_project_repository.py index 26100276b1..ac4cf5f600 100644 --- a/test/test_repository/test_project_repository.py +++ b/test/test_repository/test_project_repository.py @@ -25,12 +25,10 @@ class TestProjectRepositoryForProjects(Test): - def setUp(self): super(TestProjectRepositoryForProjects, self).setUp() self.project_repo = ProjectRepository(db) - @with_context def test_get_return_none_if_no_project(self): """Test get method returns None if there is no project with the @@ -40,7 +38,6 @@ def test_get_return_none_if_no_project(self): assert project is None, project - @with_context def test_get_returns_project(self): """Test get method returns a project if exists""" @@ -51,17 +48,15 @@ def test_get_returns_project(self): assert project == retrieved_project, retrieved_project - @with_context def test_get_by_shortname_return_none_if_no_project(self): """Test get_by_shortname returns None when a project with the specified short_name does not exist""" - project = self.project_repo.get_by_shortname('thisprojectdoesnotexist') + project = self.project_repo.get_by_shortname("thisprojectdoesnotexist") assert project is None, project - @with_context def test_get_by_shortname_returns_the_project(self): """Test get_by_shortname returns a project if exists""" @@ -72,29 +67,26 @@ def test_get_by_shortname_returns_the_project(self): assert project == retrieved_project, retrieved_project - @with_context def test_get_by(self): """Test get_by returns a project with the specified attribute""" - project = ProjectFactory.create(name='My Project', short_name='myproject') + project = ProjectFactory.create(name="My Project", short_name="myproject") retrieved_project = self.project_repo.get_by(name=project.name) assert project == retrieved_project, retrieved_project - @with_context def test_get_by_returns_none_if_no_project(self): """Test get_by returns None if no project matches the query""" - ProjectFactory.create(name='My Project', short_name='myproject') + ProjectFactory.create(name="My Project", short_name="myproject") - project = self.project_repo.get_by(name='no_name') + project = self.project_repo.get_by(name="no_name") assert project is None, project - @with_context def get_all_returns_list_of_all_projects(self): """Test get_all returns a list of all the existing projects""" @@ -108,19 +100,17 @@ def get_all_returns_list_of_all_projects(self): for project in retrieved_projects: assert project in projects, project - @with_context def test_filter_by_no_matches(self): """Test filter_by returns an empty list if no projects match the query""" - ProjectFactory.create(name='My Project', short_name='myproject') + ProjectFactory.create(name="My Project", short_name="myproject") - retrieved_projects = self.project_repo.filter_by(name='no_name') + retrieved_projects = self.project_repo.filter_by(name="no_name") assert isinstance(retrieved_projects, list) assert len(retrieved_projects) == 0, retrieved_projects - @with_context def test_filter_by_one_condition(self): """Test filter_by returns a list of projects that meet the filtering @@ -129,27 +119,31 @@ def test_filter_by_one_condition(self): ProjectFactory.create_batch(3, allow_anonymous_contributors=False) should_be_missing = ProjectFactory.create(allow_anonymous_contributors=True) - retrieved_projects = self.project_repo.filter_by(allow_anonymous_contributors=False) + retrieved_projects = self.project_repo.filter_by( + allow_anonymous_contributors=False + ) assert len(retrieved_projects) == 3, retrieved_projects assert should_be_missing not in retrieved_projects, retrieved_projects - @with_context def test_filter_by_multiple_conditions(self): """Test filter_by supports multiple-condition queries""" - ProjectFactory.create_batch(2, allow_anonymous_contributors=False, featured=False) - project = ProjectFactory.create(allow_anonymous_contributors=False, featured=True) + ProjectFactory.create_batch( + 2, allow_anonymous_contributors=False, featured=False + ) + project = ProjectFactory.create( + allow_anonymous_contributors=False, featured=True + ) retrieved_projects = self.project_repo.filter_by( - allow_anonymous_contributors=False, - featured=True) + allow_anonymous_contributors=False, featured=True + ) assert len(retrieved_projects) == 1, retrieved_projects assert project in retrieved_projects, retrieved_projects - @with_context def test_filter_by_limit_offset(self): """Test that filter_by supports limit and offset options""" @@ -165,7 +159,6 @@ def test_filter_by_limit_offset(self): assert first_two == all_projects[:2] assert last_two == all_projects[2:] - @with_context def test_save(self): """Test save persist the project""" @@ -177,7 +170,6 @@ def test_save(self): assert self.project_repo.get(project.id) == project, "Project not saved" - @with_context def test_save_fails_if_integrity_error(self): """Test save raises a DBIntegrityError if the instance to be saved lacks @@ -187,7 +179,6 @@ def test_save_fails_if_integrity_error(self): assert_raises(DBIntegrityError, self.project_repo.save, project) - @with_context def test_save_only_saves_projects(self): """Test save raises a WrongObjectError when an object which is not @@ -197,19 +188,19 @@ def test_save_only_saves_projects(self): assert_raises(WrongObjectError, self.project_repo.save, bad_object) - @with_context def test_update(self): """Test update persists the changes made to the project""" - project = ProjectFactory.create(description='this is a project') - project.description = 'the description has changed' + project = ProjectFactory.create(description="this is a project") + project.description = "the description has changed" self.project_repo.update(project) updated_project = self.project_repo.get(project.id) - assert updated_project.description == 'the description has changed', updated_project - + assert ( + updated_project.description == "the description has changed" + ), updated_project @with_context def test_update_fails_if_integrity_error(self): @@ -221,7 +212,6 @@ def test_update_fails_if_integrity_error(self): assert_raises(DBIntegrityError, self.project_repo.update, project) - @with_context def test_update_only_updates_projects(self): """Test update raises a WrongObjectError when an object which is not @@ -231,7 +221,6 @@ def test_update_only_updates_projects(self): assert_raises(WrongObjectError, self.project_repo.update, bad_object) - @with_context def test_delete(self): """Test delete removes the project instance""" @@ -243,7 +232,6 @@ def test_delete(self): assert deleted is None, deleted - @with_context def test_delete_also_removes_dependant_resources(self): """Test delete removes project tasks and taskruns too""" @@ -263,7 +251,6 @@ def test_delete_also_removes_dependant_resources(self): assert deleted_task is None, deleted_task assert deleted_taskrun is None, deleted_taskrun - @with_context def test_delete_only_deletes_projects(self): """Test delete raises a WrongObjectError if is requested to delete other @@ -274,14 +261,11 @@ def test_delete_only_deletes_projects(self): assert_raises(WrongObjectError, self.project_repo.delete, bad_object) - class TestProjectRepositoryForCategories(Test): - def setUp(self): super(TestProjectRepositoryForCategories, self).setUp() self.project_repo = ProjectRepository(db) - @with_context def test_get_category_return_none_if_no_category(self): """Test get_category method returns None if there is no category with @@ -291,7 +275,6 @@ def test_get_category_return_none_if_no_category(self): assert category is None, category - @with_context def test_get_category_returns_category(self): """Test get_category method returns a category if exists""" @@ -302,29 +285,26 @@ def test_get_category_returns_category(self): assert category == retrieved_category, retrieved_category - @with_context def test_get_category_by(self): """Test get_category returns a category with the specified attribute""" - category = CategoryFactory.create(name='My Cat', short_name='mycat') + category = CategoryFactory.create(name="My Cat", short_name="mycat") retrieved_category = self.project_repo.get_category_by(name=category.name) assert category == retrieved_category, retrieved_category - @with_context def test_get_category_by_returns_none_if_no_category(self): """Test get_category returns None if no category matches the query""" - CategoryFactory.create(name='My Project', short_name='mycategory') + CategoryFactory.create(name="My Project", short_name="mycategory") - category = self.project_repo.get_by(name='no_name') + category = self.project_repo.get_by(name="no_name") assert category is None, category - @with_context def get_all_returns_list_of_all_categories(self): """Test get_all_categories returns a list of all the existing categories""" @@ -338,15 +318,14 @@ def get_all_returns_list_of_all_categories(self): for category in retrieved_categories: assert category in categories, category - @with_context def test_filter_categories_by_no_matches(self): """Test filter_categories_by returns an empty list if no categories match the query""" - CategoryFactory.create(name='My Project', short_name='mycategory') + CategoryFactory.create(name="My Project", short_name="mycategory") - retrieved_categories = self.project_repo.filter_categories_by(name='no_name') + retrieved_categories = self.project_repo.filter_categories_by(name="no_name") assert isinstance(retrieved_categories, list) assert len(retrieved_categories) == 0, retrieved_categories @@ -355,10 +334,11 @@ def test_filter_categories_by_no_matches(self): def test_filter_categories_by_ownerid(self): """Test filter_categories_by removes ownerid from query.""" - CategoryFactory.create(name='My Project', short_name='mycategory') + CategoryFactory.create(name="My Project", short_name="mycategory") - retrieved_categories = self.project_repo.filter_categories_by(short_name='mycategory', - owner_id=1) + retrieved_categories = self.project_repo.filter_categories_by( + short_name="mycategory", owner_id=1 + ) assert isinstance(retrieved_categories, list) assert len(retrieved_categories) == 1, retrieved_categories @@ -368,16 +348,16 @@ def test_filter_categories_by_one_condition(self): """Test filter_categories_by returns a list of categories that meet the filtering condition""" - CategoryFactory.create_batch(3, description='generic category') - should_be_missing = CategoryFactory.create(description='other category') + CategoryFactory.create_batch(3, description="generic category") + should_be_missing = CategoryFactory.create(description="other category") - retrieved_categories = (self.project_repo - .filter_categories_by(description='generic category')) + retrieved_categories = self.project_repo.filter_categories_by( + description="generic category" + ) assert len(retrieved_categories) == 3, retrieved_categories assert should_be_missing not in retrieved_categories, retrieved_categories - @with_context def test_filter_categories_by_limit_offset(self): """Test that filter_categories_by supports limit and offset options""" @@ -393,7 +373,6 @@ def test_filter_categories_by_limit_offset(self): assert first_two == all_categories[:2] assert last_two == all_categories[2:] - @with_context def test_save_category(self): """Test save_category persist the category""" @@ -403,19 +382,19 @@ def test_save_category(self): self.project_repo.save_category(category) - assert self.project_repo.get_category(category.id) == category, "Category not saved" - + assert ( + self.project_repo.get_category(category.id) == category + ), "Category not saved" @with_context def test_save_category_fails_if_integrity_error(self): """Test save_category raises a DBIntegrityError if the instance to be - saved lacks a required value""" + saved lacks a required value""" category = CategoryFactory.build(name=None) assert_raises(DBIntegrityError, self.project_repo.save_category, category) - @with_context def test_save_category_only_saves_categories(self): """Test save_category raises a WrongObjectError when an object which is @@ -425,14 +404,13 @@ def test_save_category_only_saves_categories(self): assert_raises(WrongObjectError, self.project_repo.save_category, bad_object) - @with_context def test_update_category(self): """Test update_category persists the changes made to the category""" - info = {'key': 'val'} + info = {"key": "val"} category = CategoryFactory.create(info=info) - info_new = {'f': 'v'} + info_new = {"f": "v"} category.info = info_new self.project_repo.update_category(category) @@ -440,7 +418,6 @@ def test_update_category(self): assert updated_category.info == info_new, updated_category - @with_context def test_update_category_fails_if_integrity_error(self): """Test update raises a DBIntegrityError if the instance to be updated @@ -451,7 +428,6 @@ def test_update_category_fails_if_integrity_error(self): assert_raises(DBIntegrityError, self.project_repo.update_category, category) - @with_context def test_update_category_only_updates_categories(self): """Test update_category raises a WrongObjectError when an object which is @@ -461,7 +437,6 @@ def test_update_category_only_updates_categories(self): assert_raises(WrongObjectError, self.project_repo.update_category, bad_object) - @with_context def test_delete_category(self): """Test delete_category removes the category instance""" @@ -473,7 +448,6 @@ def test_delete_category(self): assert deleted is None, deleted - @with_context def test_delete_category_only_deletes_categories(self): """Test delete_category raises a WrongObjectError if is requested to @@ -487,15 +461,15 @@ def test_delete_category_only_deletes_categories(self): def test_fulltext_search_category(self): """Test fulltext search in JSON info works.""" category = CategoryFactory.create() - text = 'something word you me bar' - data = {'foo': text} + text = "something word you me bar" + data = {"foo": text} category.info = data self.project_repo.update_category(category) - info = 'foo::word' - res = self.project_repo.filter_categories_by(info=info, fulltextsearch='1') + info = "foo::word" + res = self.project_repo.filter_categories_by(info=info, fulltextsearch="1") assert len(res) == 1, len(res) - assert res[0][0].info['foo'] == text, res[0] + assert res[0][0].info["foo"] == text, res[0] res = self.project_repo.filter_categories_by(info=info) assert len(res) == 0, len(res) @@ -504,27 +478,26 @@ def test_fulltext_search_category(self): def test_fulltext_search_category_01(self): """Test fulltext search in JSON info works.""" category = CategoryFactory.create() - text = 'something word you me bar' - data = {'foo': text, 'bar': 'foo'} + text = "something word you me bar" + data = {"foo": text, "bar": "foo"} category.info = data self.project_repo.update_category(category) - info = 'foo::word&bar|bar::foo' - res = self.project_repo.filter_categories_by(info=info, fulltextsearch='1') + info = "foo::word&bar|bar::foo" + res = self.project_repo.filter_categories_by(info=info, fulltextsearch="1") assert len(res) == 1, len(res) - assert res[0][0].info['foo'] == text, res[0] - + assert res[0][0].info["foo"] == text, res[0] @with_context def test_info_json_search_category(self): """Test search in JSON info works.""" category = CategoryFactory.create() - text = 'bar' - data = {'foo': text} + text = "bar" + data = {"foo": text} category.info = data self.project_repo.update_category(category) - info = 'foo::bar' + info = "foo::bar" res = self.project_repo.filter_categories_by(info=info) assert len(res) == 1, len(res) - assert res[0].info['foo'] == text, res[0] + assert res[0].info["foo"] == text, res[0]