From 8daeccbcf3d3a0a8e6f3a4df4aa26072a3c21b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Lombra=C3=B1a=20Gonz=C3=A1lez?= Date: Sat, 6 Mar 2021 22:02:21 +0100 Subject: [PATCH] chore: fixes to run on python3.8 (#2025) * chore: fixes to run on python3.8 * fix: remove duplicated method. * fix: pin numpy and pandas wheels. * fix: misaka versions * fix: use new method. * fix: remove print. * fix: remove comment. --- circle.yml | 4 +- pybossa/cache/project_stats.py | 31 +- pybossa/core.py | 5 +- pybossa/signer/__init__.py | 2 +- pybossa/uploader/local.py | 4 +- setup.py | 30 +- test/default.py | 7 + test/test_admin_export_users.py | 6 +- test/test_forms.py | 24 +- test/test_importers/__init__.py | 27 +- .../test_epicollect_importer.py | 14 +- .../test_googledocs_importer.py | 30 +- test/test_importers/test_youtube_importer.py | 338 +++++++++--------- test/test_view/test_blog.py | 50 +-- test/test_web.py | 2 + 15 files changed, 289 insertions(+), 285 deletions(-) diff --git a/circle.yml b/circle.yml index 85782bc9c1..34ee14dc61 100644 --- a/circle.yml +++ b/circle.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: ~/circulate docker: - - image: scifabric/python3.6-ldap + - image: scifabric/python3.8-ldap environment: FLASK_CONFIG: testing TEST_DATABASE_URL: postgresql://rtester:rtester@localhost/pybossa_test?sslmode=disable @@ -24,7 +24,7 @@ jobs: command: | git submodule sync --recursive && git submodule update --recursive --init - run: - name: Install Python deps + name: Install Python deps command: | pip install -r requirements.txt - run: diff --git a/pybossa/cache/project_stats.py b/pybossa/cache/project_stats.py index b9ea2acdc9..7225042655 100644 --- a/pybossa/cache/project_stats.py +++ b/pybossa/cache/project_stats.py @@ -16,18 +16,15 @@ # You should have received a copy of the GNU Affero General Public License # along with PYBOSSA. If not, see . """Cache module for project stats.""" -from flask import current_app from sqlalchemy.sql import text from pybossa.core import db from pybossa.cache import memoize, ONE_DAY, FIVE_MINUTES import pybossa.cache.projects as cached_projects from pybossa.model.project_stats import ProjectStats -from flask_babel import gettext import operator import time import datetime -import os session = db.slave_session @@ -396,13 +393,14 @@ def stats_hours(project_id, period='2 week'): @memoize(timeout=ONE_DAY) def stats_format_dates(project_id, dates, dates_anon, dates_auth): """Format dates stats into a JSON format.""" - dayNewStats = dict(label=gettext("Anon + Auth"), values=[]) - dayCompletedTasks = dict(label=gettext("Completed Tasks"), + dayNewStats = dict(label="Anon + Auth", values=[]) + dayCompletedTasks = dict(label="Completed Tasks", disabled="True", values=[]) - dayNewAnonStats = dict(label=gettext("Anonymous"), values=[]) - dayNewAuthStats = dict(label=gettext("Authenticated"), values=[]) + dayNewAnonStats = dict(label="Anonymous", values=[]) + dayNewAuthStats = dict(label="Authenticated", values=[]) - answer_dates = sorted(list(set(list(dates_anon.keys()) + list(dates_auth.keys())))) + answer_dates = sorted( + list(set(list(dates_anon.keys()) + list(dates_auth.keys())))) total = 0 for d in sorted(dates.keys()): @@ -435,10 +433,10 @@ def stats_format_dates(project_id, dates, dates_anon, dates_auth): def stats_format_hours(project_id, hours, hours_anon, hours_auth, max_hours, max_hours_anon, max_hours_auth): """Format hours stats into a JSON format.""" - hourNewStats = dict(label=gettext("Anon + Auth"), + hourNewStats = dict(label="Anon + Auth", disabled="True", values=[], max=0) - hourNewAnonStats = dict(label=gettext("Anonymous"), values=[], max=0) - hourNewAuthStats = dict(label=gettext("Authenticated"), + hourNewAnonStats = dict(label="Anonymous", values=[], max=0) + hourNewAuthStats = dict(label="Authenticated", values=[], max=0) hourNewStats['max'] = max_hours @@ -457,7 +455,8 @@ def stats_format_hours(project_id, hours, hours_anon, hours_auth, if h in list(hours_anon.keys()): if (hours_anon[h] != 0): tmph = (hours_anon[h] * 5) / max_hours - hourNewAnonStats['values'].append([int(h), hours_anon[h], tmph]) + hourNewAnonStats['values'].append( + [int(h), hours_anon[h], tmph]) else: hourNewAnonStats['values'].append([int(h), hours_anon[h], 0]) @@ -465,7 +464,8 @@ def stats_format_hours(project_id, hours, hours_anon, hours_auth, if h in list(hours_auth.keys()): if (hours_auth[h] != 0): tmph = (hours_auth[h] * 5) / max_hours - hourNewAuthStats['values'].append([int(h), hours_auth[h], tmph]) + hourNewAuthStats['values'].append( + [int(h), hours_auth[h], tmph]) else: hourNewAuthStats['values'].append([int(h), hours_auth[h], 0]) return hourNewStats, hourNewAnonStats, hourNewAuthStats @@ -496,7 +496,7 @@ def stats_format_users(project_id, users, anon_users, auth_users): top5_anon.append(dict(ip=u[0], tasks=u[1])) for u in auth_users: - sql = text('''SELECT name, fullname, restrict from "user" + sql = text('''SELECT name, fullname, restrict from "user" where id=:id and restrict=false;''') results = session.execute(sql, dict(id=u[0])) fullname = None @@ -510,7 +510,7 @@ def stats_format_users(project_id, users, anon_users, auth_users): top5_auth.append(dict(name=name, fullname=fullname, tasks=u[1], - restrict=restrict)) + restrict=restrict)) userAnonStats['top5'] = top5_anon[0:5] userAuthStats['top5'] = top5_auth @@ -526,7 +526,6 @@ def update_stats(project_id, period='2 week'): users, anon_users, auth_users = stats_users(project_id, period) dates, dates_anon, dates_auth = stats_dates(project_id, period) - sum(dates.values()) sorted(iter(dates.items()), key=operator.itemgetter(0)) diff --git a/pybossa/core.py b/pybossa/core.py index 825844836d..173fa2946e 100644 --- a/pybossa/core.py +++ b/pybossa/core.py @@ -20,7 +20,7 @@ import logging import humanize from flask import Flask, url_for, request, render_template, \ - flash, _app_ctx_stack, abort, redirect + flash, _app_ctx_stack, abort, redirect, request from flask_login import current_user from flask_babel import gettext from flask_assets import Bundle @@ -276,9 +276,8 @@ def setup_babel(app): @babel.localeselector def _get_locale(): - from flask import request locales = [l[0] for l in app.config.get('LOCALES')] - if current_user.is_authenticated: + if current_user and current_user.is_authenticated: lang = current_user.locale else: lang = request.cookies.get('language') diff --git a/pybossa/signer/__init__.py b/pybossa/signer/__init__.py index f8249bd396..191ecf729a 100644 --- a/pybossa/signer/__init__.py +++ b/pybossa/signer/__init__.py @@ -17,7 +17,7 @@ # along with PYBOSSA. If not, see . from itsdangerous import URLSafeTimedSerializer -from werkzeug import generate_password_hash, check_password_hash +from werkzeug.security import generate_password_hash, check_password_hash class Signer(object): diff --git a/pybossa/uploader/local.py b/pybossa/uploader/local.py index 6c4bef1cd4..6ea4153b69 100644 --- a/pybossa/uploader/local.py +++ b/pybossa/uploader/local.py @@ -23,9 +23,9 @@ * Local class: for uploading files to a local filesystem. """ -from pybossa.uploader import Uploader import os -from werkzeug import secure_filename +from pybossa.uploader import Uploader +from werkzeug.utils import secure_filename class LocalUploader(Uploader): diff --git a/setup.py b/setup.py index f1596d858c..19bb09403c 100644 --- a/setup.py +++ b/setup.py @@ -27,20 +27,20 @@ "factory-boy==2.4.1", "Faker==1.0.1", "feedparser==5.2.1", - "Flask==1.0.2", + "Flask", "Flask-Assets==0.12", - "Flask-Babel==0.9", - "Flask-Cors==3.0.2", + "Flask-Babel>=0.9", + "Flask-Cors>=3.0.2", "Flask-DebugToolbar==0.10.1", - "Flask-HTTPAuth==3.2.4", - "flask-json-multidict==1.0.0", - "Flask-Login==0.4.1", - "Flask-Mail==0.9.1", - "Flask-Misaka==0.3.0", - "Flask-Plugins==1.6.1", + "Flask-HTTPAuth>=3.2.4", + "flask-json-multidict>=1.0.0", + "Flask-Login>=0.4.1", + "Flask-Mail>=0.9.1", + "Flask-Misaka>=1.0.0", + "Flask-Plugins>=1.6.1", "flask-profiler==1.6", - "Flask-SimpleLDAP==1.1.2", - "Flask-SQLAlchemy==2.3.2", + "Flask-SimpleLDAP>=1.1.2", + "Flask-SQLAlchemy>=2.3.2", "Flask-WTF>=0.9.5", "flatten-json==0.1.6", "google-api-python-client==1.5.5", @@ -63,7 +63,7 @@ "Mako==1.0.7", "Markdown==2.6.11", "MarkupSafe==1.1.0", - "misaka==1.0.2", + "misaka==2.1.1", "mock==2.0.0", "msgpack==0.6.0", "ndg-httpsclient==0.5.1", @@ -71,7 +71,7 @@ "netifaces==0.10.9", "nose==1.3.7", "nose-cov==1.6", - "numpy==1.15.4", + "numpy==1.20.1", "oauth2client==4.1.3", "oauthlib==2.1.0", "os-service-types==1.4.0", @@ -80,7 +80,7 @@ "oslo.serialization==2.28.1", "oslo.utils==3.39.0", "otpauth==1.0.1", - "pandas==0.23.4", + "pandas==1.2.3", "pbr>=1.10.0", "Pillow>=6.2.0", "prettytable==0.7.2", @@ -132,7 +132,7 @@ "urllib3==1.24.2", "validators==0.12.6", "webassets==0.12.1", - "Werkzeug==0.15.3", + "Werkzeug", "wrapt==1.10.11", "WTForms>=1.0.5", "WTForms-Components>=0.10.3", diff --git a/test/default.py b/test/default.py index 03dbcc43d0..d5cfa530a0 100644 --- a/test/default.py +++ b/test/default.py @@ -47,6 +47,13 @@ def decorated_function(*args, **kwargs): return f(*args, **kwargs) return decorated_function +def with_request_context(f): + @wraps(f) + def decorated_function(*args, **kwargs): + with flask_app.test_request_context('/'): + return f(*args, **kwargs) + return decorated_function + def with_context_settings(**kwargs): def decorator(f): diff --git a/test/test_admin_export_users.py b/test/test_admin_export_users.py index ff9ce7dcd5..ca98fbd552 100644 --- a/test/test_admin_export_users.py +++ b/test/test_admin_export_users.py @@ -53,7 +53,7 @@ def test_json_returns_all_users(self): self.signin() res = self.app.get('/admin/users/export?format=json', - follow_redirects=True) + follow_redirects=True) data = res.data json_data = json.loads(data) @@ -70,7 +70,7 @@ def test_csv_contains_all_attributes(self): restricted = UserFactory.create(restrict=True, id=5000015) res = self.app.get('/admin/users/export?format=csv', - follow_redirects=True) + follow_redirects=True) data = res.data for attribute in self.exportable_attributes: @@ -94,5 +94,5 @@ def test_csv_returns_all_users(self): data = res.data assert restricted.name not in str(data.decode('utf-8')) import pandas as pd - df = pd.DataFrame.from_csv(io.StringIO(data.decode('utf-8'))) + df = pd.read_csv(io.StringIO(data.decode('utf-8'))) assert df.shape[0] == 3, df.shape[0] diff --git a/test/test_forms.py b/test/test_forms.py index 78f26102f5..e1f087e984 100644 --- a/test/test_forms.py +++ b/test/test_forms.py @@ -20,7 +20,7 @@ from nose.tools import raises, assert_raises from flask import current_app -from default import Test, db, with_context +from default import Test, db, with_context, with_request_context from pybossa.forms.forms import (RegisterForm, LoginForm, EMAIL_MAX_LENGTH, USER_NAME_MAX_LENGTH, USER_FULLNAME_MAX_LENGTH, BulkTaskLocalCSVImportForm, RegisterFormWithUserPrefMetadata, UserPrefMetadataForm) @@ -134,7 +134,7 @@ def test_register_form_validates_with_valid_fields(self): assert form.validate() - @with_context + @with_request_context def test_register_form_unique_name(self): form = RegisterForm(**self.fill_in_data) user = UserFactory.create(name='mylion') @@ -142,7 +142,7 @@ def test_register_form_unique_name(self): assert not form.validate() assert "The user name is already taken" in form.errors['name'], form.errors - @with_context + @with_request_context def test_register_name_length(self): self.fill_in_data['name'] = 'a' form = RegisterForm(**self.fill_in_data) @@ -151,7 +151,7 @@ def test_register_name_length(self): assert not form.validate() assert error_message in form.errors['name'], form.errors - @with_context + @with_request_context def test_register_name_allowed_chars(self): self.fill_in_data['name'] = '$#&\/|' form = RegisterForm(**self.fill_in_data) @@ -159,7 +159,7 @@ def test_register_name_allowed_chars(self): assert not form.validate() assert "$#&\\/| and space symbols are forbidden" in form.errors['name'], form.errors - @with_context + @with_request_context def test_register_name_reserved_name(self): self.fill_in_data['name'] = 'signin' @@ -168,7 +168,7 @@ def test_register_name_reserved_name(self): assert not form.validate() assert 'This name is used by the system.' in form.errors['name'], form.errors - @with_context + @with_request_context def test_register_form_unique_email(self): form = RegisterForm(**self.fill_in_data) user = UserFactory.create(email_addr='tyrion@casterly.rock') @@ -176,7 +176,7 @@ def test_register_form_unique_email(self): assert not form.validate() assert "Email is already taken" in form.errors['email_addr'], form.errors - @with_context + @with_request_context def test_register_email_length(self): self.fill_in_data['email_addr'] = '' form = RegisterForm(**self.fill_in_data) @@ -193,7 +193,7 @@ def test_register_email_valid_format(self): assert not form.validate() assert "Invalid email address." in form.errors['email_addr'], form.errors - @with_context + @with_request_context def test_register_fullname_length(self): self.fill_in_data['fullname'] = 'a' form = RegisterForm(**self.fill_in_data) @@ -202,7 +202,7 @@ def test_register_fullname_length(self): assert not form.validate() assert error_message in form.errors['fullname'], form.errors - @with_context + @with_request_context def test_register_password_required(self): self.fill_in_data['password'] = '' form = RegisterForm(**self.fill_in_data) @@ -210,7 +210,7 @@ def test_register_password_required(self): assert not form.validate() assert "Password cannot be empty" in form.errors['password'], form.errors - @with_context + @with_request_context def test_register_password_missmatch(self): self.fill_in_data['confirm'] = 'badpasswd' form = RegisterForm(**self.fill_in_data) @@ -309,14 +309,14 @@ def setUp(self): timezones=[("", ""), ("ACT", "Australia Central Time")], user_types=[("Researcher", "Researcher"), ("Analyst", "Analyst")]) - @with_context + @with_request_context def test_register_form_with_upref_mdata_contains_fields(self): form = RegisterFormWithUserPrefMetadata() for field in self.fields: assert form.__contains__(field), 'Field %s is not in form' %field - @with_context + @with_request_context def test_register_form_with_upref_mdata_validates_with_valid_fields(self): import pybossa.core pybossa.core.upref_mdata_choices = self.upref_mdata_valid_choices diff --git a/test/test_importers/__init__.py b/test/test_importers/__init__.py index 295f8d470e..8883db1a71 100644 --- a/test/test_importers/__init__.py +++ b/test/test_importers/__init__.py @@ -18,7 +18,7 @@ from mock import patch, Mock from pybossa.importers import Importer -from default import Test, with_context +from default import Test, with_request_context from factories import ProjectFactory, TaskFactory from pybossa.repositories import TaskRepository from pybossa.core import db @@ -29,12 +29,12 @@ class TestImporterPublicMethods(Test): importer = Importer() - @with_context + @with_request_context def test_create_tasks_creates_them_correctly(self, importer_factory): mock_importer = Mock() mock_importer.tasks.return_value = [{'info': {'question': 'question', - 'url': 'url'}, - 'n_answers': 20}] + 'url': 'url'}, + 'n_answers': 20}] importer_factory.return_value = mock_importer project = ProjectFactory.create() form_data = dict(type='csv', csv_url='http://fakecsv.com') @@ -48,7 +48,7 @@ def test_create_tasks_creates_them_correctly(self, importer_factory): importer_factory.assert_called_with(**form_data) mock_importer.tasks.assert_called_with() - @with_context + @with_request_context def test_create_tasks_creates_many_tasks(self, importer_factory): mock_importer = Mock() mock_importer.tasks.return_value = [{'info': {'question': 'question1'}}, @@ -63,7 +63,7 @@ def test_create_tasks_creates_many_tasks(self, importer_factory): assert result.message == '2 new tasks were imported successfully', result importer_factory.assert_called_with(**form_data) - @with_context + @with_request_context def test_create_tasks_not_creates_duplicated_tasks(self, importer_factory): mock_importer = Mock() mock_importer.tasks.return_value = [{'info': {'question': 'question'}}] @@ -79,7 +79,7 @@ def test_create_tasks_not_creates_duplicated_tasks(self, importer_factory): assert result.message == 'It looks like there were no new records to import', result importer_factory.assert_called_with(**form_data) - @with_context + @with_request_context def test_create_tasks_returns_task_report(self, importer_factory): mock_importer = Mock() mock_importer.tasks.return_value = [{'info': {'question': 'question'}}] @@ -95,7 +95,7 @@ def test_create_tasks_returns_task_report(self, importer_factory): assert result.total == 1, result.total assert result.metadata == metadata, result.metadata - @with_context + @with_request_context def test_count_tasks_to_import_returns_number_of_tasks_to_import(self, importer_factory): mock_importer = Mock() mock_importer.count_tasks.return_value = 2 @@ -108,7 +108,7 @@ def test_count_tasks_to_import_returns_number_of_tasks_to_import(self, importer_ assert number_of_tasks == 2, number_of_tasks importer_factory.assert_called_with(**form_data) - @with_context + @with_request_context def test_get_all_importer_names_returns_default_importer_names(self, create): importers = self.importer.get_all_importer_names() expected_importers = ['csv', 'gdocs', 'epicollect', 's3', 'localCSV', @@ -116,11 +116,12 @@ def test_get_all_importer_names_returns_default_importer_names(self, create): assert set(importers) == set(expected_importers) - @with_context + @with_request_context def test_get_all_importers_returns_configured_importers(self, create): flickr_params = {'api_key': self.flask_app.config['FLICKR_API_KEY']} twitter_params = {} - youtube_params = {'youtube_api_server_key': self.flask_app.config['YOUTUBE_API_SERVER_KEY']} + youtube_params = { + 'youtube_api_server_key': self.flask_app.config['YOUTUBE_API_SERVER_KEY']} importer = Importer() importer.register_flickr_importer(flickr_params) importer.register_dropbox_importer() @@ -132,14 +133,14 @@ def test_get_all_importers_returns_configured_importers(self, create): assert 'twitter' in importer.get_all_importer_names() assert 'youtube' in importer.get_all_importer_names() - @with_context + @with_request_context def test_get_autoimporter_names_returns_default_autoimporter_names(self, create): importers = self.importer.get_autoimporter_names() expected_importers = ['csv', 'gdocs', 'epicollect', 'localCSV', 'iiif'] assert set(importers) == set(expected_importers) - @with_context + @with_request_context def test_get_autoimporter_names_returns_configured_autoimporters(self, create): flickr_params = {'api_key': self.flask_app.config['FLICKR_API_KEY']} twitter_params = {} diff --git a/test/test_importers/test_epicollect_importer.py b/test/test_importers/test_epicollect_importer.py index 03c6af54bd..c136c8e2d2 100644 --- a/test/test_importers/test_epicollect_importer.py +++ b/test/test_importers/test_epicollect_importer.py @@ -21,7 +21,7 @@ from nose.tools import assert_raises from pybossa.importers import BulkImportException from pybossa.importers.epicollect import BulkTaskEpiCollectPlusImport -from default import FakeResponse, with_context +from default import FakeResponse, with_request_context @patch('pybossa.importers.epicollect.requests.get') @@ -31,7 +31,7 @@ class TestBulkTaskEpiCollectPlusImport(object): 'epicollect_form': 'fakeform'} importer = BulkTaskEpiCollectPlusImport(**epicollect) - @with_context + @with_request_context def test_count_tasks_raises_exception_if_file_forbidden(self, request): forbidden_request = FakeResponse(text='Forbidden', status_code=403, headers={'content-type': 'text/json'}, @@ -46,7 +46,7 @@ def test_count_tasks_raises_exception_if_file_forbidden(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_tasks_raises_exception_if_file_forbidden(self, request): forbidden_request = FakeResponse(text='Forbidden', status_code=403, headers={'content-type': 'text/json'}, @@ -61,7 +61,7 @@ def test_tasks_raises_exception_if_file_forbidden(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_count_tasks_raises_exception_if_not_json(self, request): html_request = FakeResponse(text='Not an application/json', status_code=200, @@ -76,7 +76,7 @@ def test_count_tasks_raises_exception_if_not_json(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_tasks_raises_exception_if_not_json(self, request): html_request = FakeResponse(text='Not an application/json', status_code=200, @@ -91,7 +91,7 @@ def test_tasks_raises_exception_if_not_json(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_count_tasks_returns_number_of_tasks_in_project(self, request): data = [dict(DeviceID=23), dict(DeviceID=24)] response = FakeResponse(text=json.dumps(data), status_code=200, @@ -103,7 +103,7 @@ def test_count_tasks_returns_number_of_tasks_in_project(self, request): assert number_of_tasks is 2, number_of_tasks - @with_context + @with_request_context def test_tasks_returns_tasks_in_project(self, request): data = [dict(DeviceID=23), dict(DeviceID=24)] response = FakeResponse(text=json.dumps(data), status_code=200, diff --git a/test/test_importers/test_googledocs_importer.py b/test/test_importers/test_googledocs_importer.py index 7854d90db2..92d6d71320 100644 --- a/test/test_importers/test_googledocs_importer.py +++ b/test/test_importers/test_googledocs_importer.py @@ -20,7 +20,7 @@ from nose.tools import assert_raises from pybossa.importers import BulkImportException from pybossa.importers.csv import BulkTaskGDImport -from default import FakeResponse, with_context +from default import FakeResponse, with_request_context @patch('pybossa.importers.csv.requests.get') @@ -30,7 +30,7 @@ def setUp(self): url = 'http://drive.google.com' self.importer = BulkTaskGDImport(googledocs_url=url) - @with_context + @with_request_context def test_count_tasks_returns_0_if_no_rows_other_than_header(self, request): empty_file = FakeResponse(text='CSV,with,no,content\n', status_code=200, headers={'content-type': 'text/plain'}, @@ -44,7 +44,7 @@ def test_count_tasks_returns_0_if_no_rows_other_than_header(self, request): msg = "The file you uploaded is a malformed CSV." assert e.message == msg, e - @with_context + @with_request_context def test_count_tasks_returns_1_for_CSV_with_one_valid_row(self, request): valid_file = FakeResponse(text='Foo,Bar,Baz\n1,2,3', status_code=200, headers={'content-type': 'text/plain'}, @@ -55,10 +55,11 @@ def test_count_tasks_returns_1_for_CSV_with_one_valid_row(self, request): assert number_of_tasks is 1, number_of_tasks - @with_context + @with_request_context def test_count_tasks_raises_exception_if_file_forbidden(self, request): forbidden_request = FakeResponse(text='Forbidden', status_code=403, - headers={'content-type': 'text/plain'}, + headers={ + 'content-type': 'text/plain'}, encoding='utf-8') request.return_value = forbidden_request msg = "Oops! It looks like you don't have permission to access that file" @@ -69,7 +70,7 @@ def test_count_tasks_raises_exception_if_file_forbidden(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_count_tasks_raises_exception_if_not_CSV_file(self, request): html_request = FakeResponse(text='Not a CSV', status_code=200, headers={'content-type': 'text/html'}, @@ -83,7 +84,7 @@ def test_count_tasks_raises_exception_if_not_CSV_file(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_count_tasks_raises_exception_if_dup_header(self, request): empty_file = FakeResponse(text='Foo,Bar,Foo\n1,2,3', status_code=200, headers={'content-type': 'text/plain'}, @@ -95,10 +96,11 @@ def test_count_tasks_raises_exception_if_dup_header(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_tasks_raises_exception_if_file_forbidden(self, request): forbidden_request = FakeResponse(text='Forbidden', status_code=403, - headers={'content-type': 'text/plain'}, + headers={ + 'content-type': 'text/plain'}, encoding='utf-8') request.return_value = forbidden_request msg = "Oops! It looks like you don't have permission to access that file" @@ -109,7 +111,7 @@ def test_tasks_raises_exception_if_file_forbidden(self, request): except BulkImportException as e: assert e.message == msg, e - @with_context + @with_request_context def test_tasks_raises_exception_if_not_CSV_file(self, request): html_request = FakeResponse(text='Not a CSV', status_code=200, headers={'content-type': 'text/html'}, @@ -123,7 +125,7 @@ def test_tasks_raises_exception_if_not_CSV_file(self, request): except BulkImportException as e: assert e.message == msg, e - # @with_context + # @with_request_context # def test_tasks_raises_exception_if_dup_header(self, request): # csv_file = FakeResponse(text='Foo,Bar,Foo\n1,2,3', status_code=200, # headers={'content-type': 'text/plain'}, @@ -140,7 +142,7 @@ def test_tasks_raises_exception_if_not_CSV_file(self, request): # finally: # assert raised, "Exception not raised" - @with_context + @with_request_context def test_tasks_return_tasks_with_only_info_fields(self, request): csv_file = FakeResponse(text='Foo,Bar,Baz\n1,2,3', status_code=200, headers={'content-type': 'text/plain'}, @@ -152,7 +154,7 @@ def test_tasks_return_tasks_with_only_info_fields(self, request): assert task == {"info": {'Bar': 2, 'Foo': 1, 'Baz': 3}}, task - @with_context + @with_request_context def test_tasks_return_tasks_with_non_info_fields_too(self, request): csv_file = FakeResponse(text='Foo,Bar,priority_0\n1,2,3', status_code=200, @@ -166,7 +168,7 @@ def test_tasks_return_tasks_with_non_info_fields_too(self, request): assert task == {'info': {'Foo': 1, 'Bar': 2}, 'priority_0': 3}, task - @with_context + @with_request_context def test_tasks_works_with_encodings_other_than_utf8(self, request): csv_file = FakeResponse(text='Foo\nM\xc3\xbcnchen', status_code=200, headers={'content-type': 'text/plain'}, diff --git a/test/test_importers/test_youtube_importer.py b/test/test_importers/test_youtube_importer.py index 408f1a5304..c8603c8068 100644 --- a/test/test_importers/test_youtube_importer.py +++ b/test/test_importers/test_youtube_importer.py @@ -20,7 +20,8 @@ from nose.tools import assert_raises from pybossa.importers import BulkImportException from pybossa.importers.youtubeapi import BulkTaskYoutubeImport -from default import with_context +from default import with_request_context + @patch('pybossa.importers.youtubeapi.build') class TestBulkYoutubeImport(object): @@ -31,153 +32,152 @@ class TestBulkYoutubeImport(object): } short_playlist_response = { - 'items': [ - { - 'snippet': { - 'playlistId': 'youtubeplaylistid1', - 'thumbnails': { - 'default': { - 'url': 'https://i.ytimg.com/vi/youtubeid2/default.jpg', - 'width': 120, - 'height': 90 - }, - 'high': { - 'url': 'https://i.ytimg.com/vi/youtubeid2/hqdefault.jpg', - 'width': 480, - 'height': 360 - }, - 'medium': { - 'url': 'https://i.ytimg.com/vi/youtubeid2/mqdefault.jpg', - 'width': 320, - 'height': 180 - }, - 'maxres': { - 'url': 'https://i.ytimg.com/vi/youtubeid2/maxresdefault.jpg', - 'width': 1280, - 'height': 720 - }, - 'standard': { - 'url': 'https://i.ytimg.com/vi/youtubeid2/sddefault.jpg', - 'width': 640, - 'height': 480 - } - }, - 'title': 'Best of Test Videos', - 'resourceId': { - 'kind': 'youtube#video', - 'videoId': 'youtubeid2' - }, - 'channelId': 'SomeChannelID', - 'publishedAt': '2016-03-11T18:58:52.000Z', - 'channelTitle': 'Some Youtube Channel', - 'position': 2, - 'description': 'Another long text describing the video here' - }, - 'kind': 'youtube#playlistItem', - 'etag': '\'somelongetaghere1\'', - 'id': 'somelongidhere2' - } - ] + 'items': [ + { + 'snippet': { + 'playlistId': 'youtubeplaylistid1', + 'thumbnails': { + 'default': { + 'url': 'https://i.ytimg.com/vi/youtubeid2/default.jpg', + 'width': 120, + 'height': 90 + }, + 'high': { + 'url': 'https://i.ytimg.com/vi/youtubeid2/hqdefault.jpg', + 'width': 480, + 'height': 360 + }, + 'medium': { + 'url': 'https://i.ytimg.com/vi/youtubeid2/mqdefault.jpg', + 'width': 320, + 'height': 180 + }, + 'maxres': { + 'url': 'https://i.ytimg.com/vi/youtubeid2/maxresdefault.jpg', + 'width': 1280, + 'height': 720 + }, + 'standard': { + 'url': 'https://i.ytimg.com/vi/youtubeid2/sddefault.jpg', + 'width': 640, + 'height': 480 + } + }, + 'title': 'Best of Test Videos', + 'resourceId': { + 'kind': 'youtube#video', + 'videoId': 'youtubeid2' + }, + 'channelId': 'SomeChannelID', + 'publishedAt': '2016-03-11T18:58:52.000Z', + 'channelTitle': 'Some Youtube Channel', + 'position': 2, + 'description': 'Another long text describing the video here' + }, + 'kind': 'youtube#playlistItem', + 'etag': '\'somelongetaghere1\'', + 'id': 'somelongidhere2' + } + ] } long_playlist_response = { - 'items': [ - { - 'snippet': { - 'playlistId': 'youtubeplaylistid0', - 'thumbnails': { - 'default': { - 'url': 'https://i.ytimg.com/vi/youtubeid0/default.jpg', - 'width': 120, - 'height': 90 - }, - 'high': { - 'url': 'https://i.ytimg.com/vi/youtubeid0/hqdefault.jpg', - 'width': 480, - 'height': 360 - }, - 'medium': { - 'url': 'https://i.ytimg.com/vi/youtubeid0/mqdefault.jpg', - 'width': 320, - 'height': 180 - }, - 'maxres': { - 'url': 'https://i.ytimg.com/vi/youtubeid0/maxresdefault.jpg', - 'width': 1280, - 'height': 720 - }, - 'standard': { - 'url': 'https://i.ytimg.com/vi/youtubeid0/sddefault.jpg', - 'width': 640, - 'height': 480 - } + 'items': [ + { + 'snippet': { + 'playlistId': 'youtubeplaylistid0', + 'thumbnails': { + 'default': { + 'url': 'https://i.ytimg.com/vi/youtubeid0/default.jpg', + 'width': 120, + 'height': 90 + }, + 'high': { + 'url': 'https://i.ytimg.com/vi/youtubeid0/hqdefault.jpg', + 'width': 480, + 'height': 360 + }, + 'medium': { + 'url': 'https://i.ytimg.com/vi/youtubeid0/mqdefault.jpg', + 'width': 320, + 'height': 180 + }, + 'maxres': { + 'url': 'https://i.ytimg.com/vi/youtubeid0/maxresdefault.jpg', + 'width': 1280, + 'height': 720 + }, + 'standard': { + 'url': 'https://i.ytimg.com/vi/youtubeid0/sddefault.jpg', + 'width': 640, + 'height': 480 + } + }, + 'title': 'First video', + 'resourceId': { + 'kind': 'youtube#video', + 'videoId': 'youtubeid0' + }, + 'channelId': 'SomeChannelID', + 'publishedAt': '2016-03-11T18:58:52.000Z', + 'channelTitle': 'Some Youtube Channel', + 'position': 0, + 'description': 'Very first video in a long playlist' + }, + 'kind': 'youtube#playlistItem', + 'etag': '\'somelongetaghere0\'', + 'id': 'somelongidher0' }, - 'title': 'First video', - 'resourceId': { - 'kind': 'youtube#video', - 'videoId': 'youtubeid0' + { + 'snippet': { + 'playlistId': 'youtubeplaylistid1', + 'thumbnails': { + 'default': { + 'url': 'https://i.ytimg.com/vi/youtubeid1/default.jpg', + 'width': 120, + 'height': 90 + }, + 'high': { + 'url': 'https://i.ytimg.com/vi/youtubeid1/hqdefault.jpg', + 'width': 480, + 'height': 360 + }, + 'medium': { + 'url': 'https://i.ytimg.com/vi/youtubeid1/mqdefault.jpg', + 'width': 320, + 'height': 180 + }, + 'maxres': { + 'url': 'https://i.ytimg.com/vi/youtubeid1/maxresdefault.jpg', + 'width': 1280, + 'height': 720 + }, + 'standard': { + 'url': 'https://i.ytimg.com/vi/youtubeid1/sddefault.jpg', + 'width': 640, + 'height': 480 + } + }, + 'title': 'Cool Video 1', + 'resourceId': { + 'kind': 'youtube#video', + 'videoId': 'youtubeid1' + }, + 'channelId': 'SomeChannelID', + 'publishedAt': '2016-03-15T05:47:01.000Z', + 'channelTitle': 'Some Youtube Channel', + 'position': 1, + 'description': 'A long text describing the video here' + }, + 'kind': 'youtube#playlistItem', + 'etag': '\'somelongetaghere2\'', + 'id': 'somelongidhere1' }, - 'channelId': 'SomeChannelID', - 'publishedAt': '2016-03-11T18:58:52.000Z', - 'channelTitle': 'Some Youtube Channel', - 'position': 0, - 'description': 'Very first video in a long playlist' - }, - 'kind': 'youtube#playlistItem', - 'etag': '\'somelongetaghere0\'', - 'id': 'somelongidher0' - }, - { - 'snippet': { - 'playlistId': 'youtubeplaylistid1', - 'thumbnails': { - 'default': { - 'url': 'https://i.ytimg.com/vi/youtubeid1/default.jpg', - 'width': 120, - 'height': 90 - }, - 'high': { - 'url': 'https://i.ytimg.com/vi/youtubeid1/hqdefault.jpg', - 'width': 480, - 'height': 360 - }, - 'medium': { - 'url': 'https://i.ytimg.com/vi/youtubeid1/mqdefault.jpg', - 'width': 320, - 'height': 180 - }, - 'maxres': { - 'url': 'https://i.ytimg.com/vi/youtubeid1/maxresdefault.jpg', - 'width': 1280, - 'height': 720 - }, - 'standard': { - 'url': 'https://i.ytimg.com/vi/youtubeid1/sddefault.jpg', - 'width': 640, - 'height': 480 - } - }, - 'title': 'Cool Video 1', - 'resourceId': { - 'kind': 'youtube#video', - 'videoId': 'youtubeid1' - }, - 'channelId': 'SomeChannelID', - 'publishedAt': '2016-03-15T05:47:01.000Z', - 'channelTitle': 'Some Youtube Channel', - 'position': 1, - 'description': 'A long text describing the video here' - }, - 'kind': 'youtube#playlistItem', - 'etag': '\'somelongetaghere2\'', - 'id': 'somelongidhere1' - }, - ], - 'nextPageToken': 'someTokenId' + ], + 'nextPageToken': 'someTokenId' } - - @with_context + @with_request_context def test_tasks_return_emtpy_list_if_no_video_to_import(self, build): form_data = { 'playlist_url': '', @@ -187,16 +187,17 @@ def test_tasks_return_emtpy_list_if_no_video_to_import(self, build): assert number_of_tasks == 0, number_of_tasks - @with_context + @with_request_context def test_call_to_youtube_api_endpoint(self, build): build.return_value.playlistItems.return_value.list.\ return_value.execute.return_value = self.short_playlist_response importer = BulkTaskYoutubeImport(**self.form_data) importer._fetch_all_youtube_videos('fakeId') - build.assert_called_with('youtube', 'v3', developerKey=self.form_data['youtube_api_server_key']) + build.assert_called_with( + 'youtube', 'v3', developerKey=self.form_data['youtube_api_server_key']) - @with_context + @with_request_context def test_call_to_youtube_api_short_playlist(self, build): build.return_value.playlistItems.return_value.list.\ return_value.execute.return_value = self.short_playlist_response @@ -205,48 +206,61 @@ def test_call_to_youtube_api_short_playlist(self, build): assert playlist == self.short_playlist_response, playlist - @with_context + @with_request_context def test_call_to_youtube_api_long_playlist(self, build): build.return_value.playlistItems.return_value.list.\ - return_value.execute.side_effect = [self.long_playlist_response, self.long_playlist_response, self.short_playlist_response] + return_value.execute.side_effect = [ + self.long_playlist_response, self.long_playlist_response, self.short_playlist_response] importer = BulkTaskYoutubeImport(**self.form_data) expected_playlist = {'items': ''} - expected_playlist['items'] = self.long_playlist_response['items'] + self.long_playlist_response['items'] + self.short_playlist_response['items'] + expected_playlist['items'] = self.long_playlist_response['items'] + \ + self.long_playlist_response['items'] + \ + self.short_playlist_response['items'] playlist = importer._fetch_all_youtube_videos('fakeId') assert playlist == expected_playlist, playlist - @with_context + @with_request_context def test_extract_video_info_one_item(self, build): importer = BulkTaskYoutubeImport(**self.form_data) - info = importer._extract_video_info(self.short_playlist_response['items'][0]) + info = importer._extract_video_info( + self.short_playlist_response['items'][0]) assert info['info']['video_url'] == 'https://www.youtube.com/watch?v=youtubeid2' - @with_context + @with_request_context def test_parse_playlist_id(self, build): importer = BulkTaskYoutubeImport(**self.form_data) - id = importer._get_playlist_id('https://www.youtube.com/playlist?list=goodplaylist') + id = importer._get_playlist_id( + 'https://www.youtube.com/playlist?list=goodplaylist') assert id == 'goodplaylist' - id = importer._get_playlist_id('https://www.youtube.com/watch?v=youtubeid&list=anotherplaylist&option=2') + id = importer._get_playlist_id( + 'https://www.youtube.com/watch?v=youtubeid&list=anotherplaylist&option=2') assert id == 'anotherplaylist' # no playlist - assert_raises(BulkImportException, importer._get_playlist_id, 'https://www.youtube.com/watch?v=youtubeid') + assert_raises(BulkImportException, importer._get_playlist_id, + 'https://www.youtube.com/watch?v=youtubeid') # malformed url - assert_raises(BulkImportException, importer._get_playlist_id, 'www.youtube.com/watch?v=youtubeid&list=anotherplaylist&option=2') + assert_raises(BulkImportException, importer._get_playlist_id, + 'www.youtube.com/watch?v=youtubeid&list=anotherplaylist&option=2') - @with_context + @with_request_context def test_non_youtube_url_raises_exception(self, build): importer = BulkTaskYoutubeImport(**self.form_data) - id = importer._get_playlist_id('https://www.youtu.be/playlist?list=goodplaylist') + id = importer._get_playlist_id( + 'https://www.youtu.be/playlist?list=goodplaylist') assert id == 'goodplaylist' - id = importer._get_playlist_id('https://youtu.be/playlist?list=goodplaylist') + id = importer._get_playlist_id( + 'https://youtu.be/playlist?list=goodplaylist') assert id == 'goodplaylist' - assert_raises(BulkImportException, importer._get_playlist_id, 'https://youtubee.com/playlist?list=goodplaylist') - assert_raises(BulkImportException, importer._get_playlist_id, 'https://api.youtube.com/playlist?list=goodplaylist') - assert_raises(BulkImportException, importer._get_playlist_id, 'https://otherdomain.com/playlist?list=goodplaylist') + assert_raises(BulkImportException, importer._get_playlist_id, + 'https://youtubee.com/playlist?list=goodplaylist') + assert_raises(BulkImportException, importer._get_playlist_id, + 'https://api.youtube.com/playlist?list=goodplaylist') + assert_raises(BulkImportException, importer._get_playlist_id, + 'https://otherdomain.com/playlist?list=goodplaylist') - @with_context + @with_request_context def test_all_coverage_tasks_extraction(self, build): build.return_value.playlistItems.return_value.list.\ return_value.execute.return_value = self.short_playlist_response @@ -254,4 +268,4 @@ def test_all_coverage_tasks_extraction(self, build): tasks = importer.tasks() assert tasks == [{'info': {'oembed': '', - 'video_url': 'https://www.youtube.com/watch?v=youtubeid2'}}] + 'video_url': 'https://www.youtube.com/watch?v=youtubeid2'}}] diff --git a/test/test_view/test_blog.py b/test/test_view/test_blog.py index 4e817c0289..29ee2d7037 100644 --- a/test/test_view/test_blog.py +++ b/test/test_view/test_blog.py @@ -29,7 +29,6 @@ user_repo = UserRepository(db) - class TestBlogpostView(web.Helper): @with_context @@ -47,7 +46,6 @@ def test_blogposts_get_all(self): title='titlethree', published=False) - url = "/project/%s/blog" % project.short_name # As anonymous @@ -112,8 +110,6 @@ def test_json_blogposts_get_all(self): assert blogpost['title'] in ['titleone', 'titletwo', 'titlethree'] self.signout() - - @with_context def test_blogpost_get_all_errors(self): """test blogpost get all raises error if the project does not exist""" @@ -122,7 +118,6 @@ def test_blogpost_get_all_errors(self): res = self.app.get(url, follow_redirects=True) assert res.status_code == 404, res.status_code - @with_context def test_json_blogpost_get_all_errors(self): """Test JSON blogpost GET all raises error if the project does not exist""" @@ -133,8 +128,6 @@ def test_json_blogpost_get_all_errors(self): assert res.status_code == 404, res.status_code assert data['code'] == 404 - - @with_context def test_blogpost_get_one(self): """Test blogpost GET with id shows one blogpost""" @@ -180,7 +173,6 @@ def test_blogpost_get_one_draft(self): assert res.status_code == 200, res.status_code assert 'title' in str(res.data) - @with_context def test_blogpost_get_one_errors(self): """Test blogposts GET non existing posts raises errors""" @@ -204,7 +196,6 @@ def test_blogpost_get_one_errors(self): res = self.app.get(url, follow_redirects=True) assert res.status_code == 404, res.status_code - from pybossa.view.projects import redirect @with_context @@ -220,7 +211,7 @@ def test_blogpost_create_by_owner(self, mock_redirect): assert res.status_code == 200, res.status_code res = self.app.post(url, - data={'title':'blogpost title', 'body':'body'}, + data={'title': 'blogpost title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 200, res.status_code mock_redirect.assert_called_with('/project/%E2%9C%93project1/blog') @@ -231,7 +222,6 @@ def test_blogpost_create_by_owner(self, mock_redirect): assert blogpost.user_id == user.id, blogpost.user_id assert blogpost.published is False, blogpost.published - @with_context def test_blogpost_create_by_anonymous(self): """Test blogpost create, anonymous users are redirected to signin""" @@ -243,7 +233,7 @@ def test_blogpost_create_by_anonymous(self): assert "Please sign in to access this page" in str(res.data), res res = self.app.post(url, - data={'title':'blogpost title', 'body':'body'}, + data={'title': 'blogpost title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 200, res.status_code assert "Please sign in to access this page" in str(res.data) @@ -251,7 +241,6 @@ def test_blogpost_create_by_anonymous(self): blogpost = blog_repo.get_by(title='blogpost title') assert blogpost == None, blogpost - @with_context def test_blogpost_create_by_non_owner(self): """Test blogpost create by non owner of the project is forbidden""" @@ -266,11 +255,10 @@ def test_blogpost_create_by_non_owner(self): assert res.status_code == 403, res.status_code res = self.app.post(url, - data={'title':'blogpost title', 'body':'body'}, + data={'title': 'blogpost title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 403, res.status_code - @with_context def test_blogpost_create_errors(self): """Test blogposts create for non existing projects raises errors""" @@ -280,11 +268,10 @@ def test_blogpost_create_errors(self): res = self.app.get(url, follow_redirects=True) assert res.status_code == 404, res.status_code - res = self.app.post(url, data={'title':'blogpost title', 'body':'body'}, + res = self.app.post(url, data={'title': 'blogpost title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 404, res.status_code - @with_context @patch('pybossa.view.projects.redirect', wraps=redirect) def test_blogpost_update_by_owner(self, mock_redirect): @@ -300,8 +287,8 @@ def test_blogpost_update_by_owner(self, mock_redirect): res = self.app.post(url, data={'id': blogpost.id, - 'title':'blogpost title', - 'body':'new body', + 'title': 'blogpost title', + 'body': 'new body', 'published': True}, follow_redirects=True) assert res.status_code == 200, res.status_code @@ -312,7 +299,6 @@ def test_blogpost_update_by_owner(self, mock_redirect): assert blogpost.body == 'new body', blogpost.body assert blogpost.published, blogpost.published - @with_context def test_blogpost_update_by_anonymous(self): """Test blogpost update, anonymous users are redirected to signin""" @@ -325,9 +311,9 @@ def test_blogpost_update_by_anonymous(self): assert "Please sign in to access this page" in str(res.data), res.data res = self.app.post(url, - data={'id':blogpost.id, - 'title':'new title', - 'body':'new body'}, + data={'id': blogpost.id, + 'title': 'new title', + 'body': 'new body'}, follow_redirects=True) assert res.status_code == 200, res.status_code assert "Please sign in to access this page" in str(res.data) @@ -335,14 +321,14 @@ def test_blogpost_update_by_anonymous(self): blogpost = blog_repo.get_by() assert blogpost.title == 'title', blogpost.title - @with_context def test_blogpost_update_by_non_owner(self): """Test blogpost update by non owner of the project is forbidden""" self.register() user = user_repo.get(1) project = ProjectFactory.create(owner=user) - blogpost = BlogpostFactory.create(project=project, title='title', body='body') + blogpost = BlogpostFactory.create( + project=project, title='title', body='body') url = "/project/%s/new-blogpost" % project.short_name self.signout() self.register(name='notowner', email='user2@user.com') @@ -352,14 +338,13 @@ def test_blogpost_update_by_non_owner(self): assert res.status_code == 403, res.status_code res = self.app.post(url, - data={'title':'new title', 'body':'body'}, + data={'title': 'new title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 403, res.status_code blogpost = blog_repo.get_by() assert blogpost.title == 'title', blogpost.title - @with_context def test_blogpost_update_errors(self): """Test blogposts update for non existing projects raises errors""" @@ -371,23 +356,22 @@ def test_blogpost_update_errors(self): # To a non-existing project url = "/project/non-existing-project/%s/update" % blogpost.id - res = self.app.post(url, data={'title':'new title', 'body':'body'}, + res = self.app.post(url, data={'title': 'new title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 404, res.status_code # To a non-existing post url = "/project/%s/999999/update" % project1.short_name - res = self.app.post(url, data={'title':'new title', 'body':'body'}, + res = self.app.post(url, data={'title': 'new title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 404, res.status_code # To an existing post but with a project in the URL it does not belong to url = "/project/%s/%s/update" % (project2.short_name, blogpost.id) - res = self.app.post(url, data={'title':'new title', 'body':'body'}, + res = self.app.post(url, data={'title': 'new title', 'body': 'body'}, follow_redirects=True) assert res.status_code == 404, res.status_code - @with_context @patch('pybossa.view.projects.redirect', wraps=redirect) def test_blogpost_delete_by_owner(self, mock_redirect): @@ -406,8 +390,6 @@ def test_blogpost_delete_by_owner(self, mock_redirect): blogpost = blog_repo.get_by(title='title') assert blogpost is None, blogpost - - @with_context def test_blogpost_delete_by_anonymous(self): """Test blogpost delete, anonymous users are redirected to signin""" @@ -422,7 +404,6 @@ def test_blogpost_delete_by_anonymous(self): blogpost = blog_repo.get_by() assert blogpost is not None - @with_context def test_blogpost_delete_by_non_owner(self): """Test blogpost delete by non owner of the project is forbidden""" @@ -441,7 +422,6 @@ def test_blogpost_delete_by_non_owner(self): blogpost = blog_repo.get_by() assert blogpost is not None - @with_context def test_blogpost_delete_errors(self): """Test blogposts delete for non existing projects raises errors""" diff --git a/test/test_web.py b/test/test_web.py index bcf5e59c80..35308b4ed5 100644 --- a/test/test_web.py +++ b/test/test_web.py @@ -1123,6 +1123,7 @@ def test_register_confirmation_validates_n_updates_email(self, fake_signer): def test_confirm_account_newsletter(self, fake_signer, url_for, newsletter): """Test WEB confirm email shows newsletter or home.""" newsletter.ask_user_to_subscribe.return_value = True + url_for.return_value = 'next_url' with patch.dict(self.flask_app.config, {'MAILCHIMP_API_KEY': 'key'}): self.register() user = db.session.query(User).get(1) @@ -1146,6 +1147,7 @@ def test_confirm_account_newsletter(self, fake_signer, url_for, newsletter): def test_newsletter_json(self, fake_signer, url_for, newsletter): """Test WEB confirm email shows newsletter or home with JSON.""" newsletter.ask_user_to_subscribe.return_value = True + url_for.return_value = 'next_url' with patch.dict(self.flask_app.config, {'MAILCHIMP_API_KEY': 'key'}): self.register() user = db.session.query(User).get(1)