misc: apply pyupgrade (#55490)
This commit is contained in:
parent
10153bdfca
commit
ff0d3779c0
2
setup.py
2
setup.py
|
@ -131,7 +131,7 @@ def get_version():
|
|||
tag exists, take 0.0- and add the length of the commit log.
|
||||
"""
|
||||
if os.path.exists('VERSION'):
|
||||
with open('VERSION', 'r') as v:
|
||||
with open('VERSION') as v:
|
||||
return v.read()
|
||||
if os.path.exists('.git'):
|
||||
p = subprocess.Popen(
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
|
|
@ -182,4 +182,4 @@ def test_api_access_roles(pub, api_access):
|
|||
resp = resp.form.submit('submit')
|
||||
|
||||
api_access = ApiAccess.get(api_access.id)
|
||||
assert set(x.id for x in api_access.get_roles()) == {role_a.id, role_b.id}
|
||||
assert {x.id for x in api_access.get_roles()} == {role_a.id, role_b.id}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from wcs.carddef import CardDef
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from wcs.categories import Category
|
||||
|
@ -248,8 +246,8 @@ def test_categories_edit_roles(pub):
|
|||
resp = resp.form.submit('submit')
|
||||
|
||||
category = Category.get(category.id)
|
||||
assert set(x.id for x in category.export_roles) == {role_a.id, role_b.id}
|
||||
assert set(x.id for x in category.statistics_roles) == {role_a.id}
|
||||
assert {x.id for x in category.export_roles} == {role_a.id, role_b.id}
|
||||
assert {x.id for x in category.statistics_roles} == {role_a.id}
|
||||
|
||||
resp = app.get('/backoffice/forms/categories/1/edit')
|
||||
assert resp.form['export_roles$element0'].value == role_a.id
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import xml.etree.ElementTree as ET
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from webtest import Upload
|
||||
|
||||
|
@ -242,7 +240,7 @@ def test_data_sources_view(pub):
|
|||
# check unicode
|
||||
data_source.data_source = {
|
||||
'type': 'formula',
|
||||
'value': repr([('Y', 'Domicilié'), ('N', u'Pas domicilié')]),
|
||||
'value': repr([('Y', 'Domicilié'), ('N', 'Pas domicilié')]),
|
||||
}
|
||||
data_source.store()
|
||||
resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import tarfile
|
||||
import time
|
||||
import xml.etree.ElementTree as ET
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from webtest import Upload
|
||||
|
||||
|
@ -1656,10 +1654,10 @@ def test_form_edit_item_field_data_source(pub):
|
|||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/forms/1/fields/1/')
|
||||
assert resp.form['data_source$type'].options == [
|
||||
(u'None', True, u'None'),
|
||||
(u'json', False, u'JSON URL'),
|
||||
(u'jsonp', False, u'JSONP URL'),
|
||||
(u'python', False, u'Python Expression'),
|
||||
('None', True, 'None'),
|
||||
('json', False, 'JSON URL'),
|
||||
('jsonp', False, 'JSONP URL'),
|
||||
('python', False, 'Python Expression'),
|
||||
]
|
||||
resp = resp.form.submit('submit').follow()
|
||||
|
||||
|
@ -1671,11 +1669,11 @@ def test_form_edit_item_field_data_source(pub):
|
|||
|
||||
resp = app.get('/backoffice/forms/1/fields/1/')
|
||||
assert resp.form['data_source$type'].options == [
|
||||
(u'None', True, u'None'),
|
||||
(u'foobar', False, u'Foobar'),
|
||||
(u'json', False, u'JSON URL'),
|
||||
(u'jsonp', False, u'JSONP URL'),
|
||||
(u'python', False, u'Python Expression'),
|
||||
('None', True, 'None'),
|
||||
('foobar', False, 'Foobar'),
|
||||
('json', False, 'JSON URL'),
|
||||
('jsonp', False, 'JSONP URL'),
|
||||
('python', False, 'Python Expression'),
|
||||
]
|
||||
resp.form['data_mode'].value = 'data-source'
|
||||
resp.form['data_source$type'].value = 'foobar'
|
||||
|
@ -1691,11 +1689,11 @@ def test_form_edit_item_field_data_source(pub):
|
|||
|
||||
resp = app.get('/backoffice/forms/1/fields/1/')
|
||||
assert resp.form['data_source$type'].options == [
|
||||
(u'None', False, u'None'),
|
||||
(u'foobar', True, u'Foobar'),
|
||||
(u'json', False, u'JSON URL'),
|
||||
(u'jsonp', False, u'JSONP URL'),
|
||||
(u'python', False, u'Python Expression'),
|
||||
('None', False, 'None'),
|
||||
('foobar', True, 'Foobar'),
|
||||
('json', False, 'JSON URL'),
|
||||
('jsonp', False, 'JSONP URL'),
|
||||
('python', False, 'Python Expression'),
|
||||
]
|
||||
|
||||
carddef.digest_template = 'plop'
|
||||
|
@ -1703,12 +1701,12 @@ def test_form_edit_item_field_data_source(pub):
|
|||
|
||||
resp = app.get('/backoffice/forms/1/fields/1/')
|
||||
assert resp.form['data_source$type'].options == [
|
||||
(u'None', False, u'None'),
|
||||
(u'carddef:%s' % carddef.url_name, False, u'Baz'),
|
||||
(u'foobar', True, u'Foobar'),
|
||||
(u'json', False, u'JSON URL'),
|
||||
(u'jsonp', False, u'JSONP URL'),
|
||||
(u'python', False, u'Python Expression'),
|
||||
('None', False, 'None'),
|
||||
('carddef:%s' % carddef.url_name, False, 'Baz'),
|
||||
('foobar', True, 'Foobar'),
|
||||
('json', False, 'JSON URL'),
|
||||
('jsonp', False, 'JSONP URL'),
|
||||
('python', False, 'Python Expression'),
|
||||
]
|
||||
|
||||
resp.form['data_source$type'].value = 'carddef:%s' % carddef.url_name
|
||||
|
@ -1828,8 +1826,8 @@ def test_form_edit_items_field(pub):
|
|||
resp = resp.follow()
|
||||
resp = resp.click('Edit', href='1/')
|
||||
assert resp.forms[0]['prefill$type'].options == [
|
||||
(u'None', True, u'None'),
|
||||
(u'Python Expression', False, u'Python Expression'),
|
||||
('None', True, 'None'),
|
||||
('Python Expression', False, 'Python Expression'),
|
||||
]
|
||||
|
||||
# change configuration for datasource
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
|
||||
import pytest
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from wcs.formdef import FormDef
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
|
@ -11,7 +9,8 @@ try:
|
|||
except ImportError:
|
||||
lasso = None
|
||||
|
||||
import mock
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from quixote.http_request import Upload as QuixoteUpload
|
||||
from webtest import Upload
|
||||
|
@ -819,8 +818,8 @@ def test_settings_permissions(pub):
|
|||
resp.forms[0]['permissions$c-2-3'].checked = True
|
||||
resp = resp.forms[0].submit()
|
||||
pub.reload_cfg()
|
||||
assert set(pub.cfg['admin-permissions']['forms']) == set([role2.id, role3.id])
|
||||
assert set(pub.cfg['admin-permissions']['workflows']) == set([role3.id])
|
||||
assert set(pub.cfg['admin-permissions']['forms']) == {role2.id, role3.id}
|
||||
assert set(pub.cfg['admin-permissions']['workflows']) == {role3.id}
|
||||
|
||||
# remove accesses
|
||||
resp = app.get('/backoffice/settings/admin-permissions')
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from wcs import fields
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from quixote.http_request import Upload as QuixoteUpload
|
||||
from webtest import Upload
|
||||
|
@ -1667,13 +1665,13 @@ def test_workflows_functions(pub):
|
|||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
resp = resp.click('add function')
|
||||
resp = resp.forms[0].submit('cancel')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver'])
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == {'_receiver'}
|
||||
|
||||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
resp = resp.click('add function')
|
||||
resp.forms[0]['name'] = 'Other Function'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function'])
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == {'_receiver', '_other-function'}
|
||||
assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Function'
|
||||
|
||||
# test rename
|
||||
|
@ -1685,7 +1683,7 @@ def test_workflows_functions(pub):
|
|||
resp = resp.click('Other Function')
|
||||
resp.forms[0]['name'] = 'Other Renamed Function'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function'])
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == {'_receiver', '_other-function'}
|
||||
assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Renamed Function'
|
||||
|
||||
# test new function with older name
|
||||
|
@ -1693,9 +1691,11 @@ def test_workflows_functions(pub):
|
|||
resp = resp.click('add function')
|
||||
resp.forms[0]['name'] = 'Other Function'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(
|
||||
['_receiver', '_other-function', '_other-function-2']
|
||||
)
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == {
|
||||
'_receiver',
|
||||
'_other-function',
|
||||
'_other-function-2',
|
||||
}
|
||||
assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Renamed Function'
|
||||
assert Workflow.get(workflow.id).roles['_other-function-2'] == 'Other Function'
|
||||
|
||||
|
@ -1703,7 +1703,7 @@ def test_workflows_functions(pub):
|
|||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
resp = resp.click('Other Renamed Function')
|
||||
resp = resp.forms[0].submit('delete')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function-2'])
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == {'_receiver', '_other-function-2'}
|
||||
|
||||
# make sure it's not possible to remove the "_receiver" key
|
||||
resp = app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
|
@ -1733,11 +1733,9 @@ def test_workflows_functions_vs_visibility(pub):
|
|||
resp = resp.click('add function')
|
||||
resp.forms[0]['name'] = 'Other Function'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == set(['_receiver', '_other-function'])
|
||||
assert set(Workflow.get(workflow.id).roles.keys()) == {'_receiver', '_other-function'}
|
||||
assert Workflow.get(workflow.id).roles['_other-function'] == 'Other Function'
|
||||
assert set(Workflow.get(workflow.id).possible_status[0].visibility) == set(
|
||||
['_receiver', '_other-function']
|
||||
)
|
||||
assert set(Workflow.get(workflow.id).possible_status[0].visibility) == {'_receiver', '_other-function'}
|
||||
|
||||
# restrict visibility in a different status, check it gets all the
|
||||
# functions
|
||||
|
@ -1746,9 +1744,7 @@ def test_workflows_functions_vs_visibility(pub):
|
|||
resp = resp.click('Change Display Settings')
|
||||
resp.forms[0]['hide_status_from_user'].checked = True
|
||||
resp = resp.forms[0].submit()
|
||||
assert set(Workflow.get(workflow.id).possible_status[2].visibility) == set(
|
||||
['_receiver', '_other-function']
|
||||
)
|
||||
assert set(Workflow.get(workflow.id).possible_status[2].visibility) == {'_receiver', '_other-function'}
|
||||
|
||||
|
||||
def test_workflows_global_actions(pub):
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
@ -178,7 +176,7 @@ def test_wscalls_import(pub, wscall):
|
|||
resp.forms[0]['file'] = Upload('wscall.wcs', wscall_xml)
|
||||
resp = resp.forms[0].submit()
|
||||
assert NamedWsCall.count() == 1
|
||||
assert set([wc.slug for wc in NamedWsCall.select()]) == set(['foobar'])
|
||||
assert {wc.slug for wc in NamedWsCall.select()} == {'foobar'}
|
||||
|
||||
# check slug
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
|
@ -186,13 +184,13 @@ def test_wscalls_import(pub, wscall):
|
|||
resp.forms[0]['file'] = Upload('wscall.wcs', wscall_xml)
|
||||
resp = resp.forms[0].submit()
|
||||
assert NamedWsCall.count() == 2
|
||||
assert set([wc.slug for wc in NamedWsCall.select()]) == set(['foobar', 'xxx'])
|
||||
assert {wc.slug for wc in NamedWsCall.select()} == {'foobar', 'xxx'}
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
resp = resp.click(href='import')
|
||||
resp.forms[0]['file'] = Upload('wscall.wcs', wscall_xml)
|
||||
resp = resp.forms[0].submit()
|
||||
assert NamedWsCall.count() == 3
|
||||
assert set([wc.slug for wc in NamedWsCall.select()]) == set(['foobar', 'xxx', 'xxx_1'])
|
||||
assert {wc.slug for wc in NamedWsCall.select()} == {'foobar', 'xxx', 'xxx_1'}
|
||||
|
||||
# import an invalid file
|
||||
resp = app.get('/backoffice/settings/wscalls/')
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import hashlib
|
||||
|
@ -215,7 +213,7 @@ def test_get_user_from_api_query_string_error_success_sha1(pub, local_user):
|
|||
base64.b64encode(hmac.new(b'1234', force_bytes(query), hashlib.sha1).digest())
|
||||
)
|
||||
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature))
|
||||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
assert output.json['user_display_name'] == 'Jean Darmette'
|
||||
|
||||
|
||||
def test_get_user_from_api_query_string_error_invalid_signature_algo_mismatch(pub, local_user):
|
||||
|
@ -245,7 +243,7 @@ def test_get_user_from_api_query_string_error_success_sha256(pub, local_user):
|
|||
base64.b64encode(hmac.new(b'1234', force_bytes(query), hashlib.sha256).digest())
|
||||
)
|
||||
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature))
|
||||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
assert output.json['user_display_name'] == 'Jean Darmette'
|
||||
|
||||
|
||||
def test_sign_url(pub, local_user):
|
||||
|
@ -256,7 +254,7 @@ def test_sign_url(pub, local_user):
|
|||
)
|
||||
url = signed_url[len('http://example.net') :]
|
||||
output = get_app(pub).get(url)
|
||||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
assert output.json['user_display_name'] == 'Jean Darmette'
|
||||
|
||||
# try to add something after signed url
|
||||
get_app(pub).get('%s&foo=bar' % url, status=403)
|
||||
|
@ -283,7 +281,7 @@ def test_get_user(pub, local_user):
|
|||
)
|
||||
url = signed_url[len('http://example.net') :]
|
||||
output = get_app(pub).get(url)
|
||||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
assert output.json['user_display_name'] == 'Jean Darmette'
|
||||
assert [x['name'] for x in output.json['user_roles']] == ['Foo bar']
|
||||
assert [x['slug'] for x in output.json['user_roles']] == ['foo-bar']
|
||||
|
||||
|
@ -317,7 +315,7 @@ def test_api_access_from_xml_storable_object(pub, local_user, admin_user):
|
|||
)
|
||||
url = signed_url[len('http://example.net') :]
|
||||
output = get_app(pub).get(url)
|
||||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
assert output.json['user_display_name'] == 'Jean Darmette'
|
||||
|
||||
|
||||
def test_is_url_signed_check_nonce(pub, local_user, freezer):
|
||||
|
@ -369,4 +367,4 @@ def test_get_user_compat_endpoint(pub, local_user):
|
|||
)
|
||||
url = signed_url[len('http://example.net') :]
|
||||
output = get_app(pub).get(url)
|
||||
assert output.json['user_display_name'] == u'Jean Darmette'
|
||||
assert output.json['user_display_name'] == 'Jean Darmette'
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from quixote import get_publisher
|
||||
|
||||
|
@ -118,7 +116,7 @@ def test_validate_condition(pub):
|
|||
|
||||
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=un+%C3%A9l%C3%A9phant')
|
||||
assert resp.json['klass'] == 'error'
|
||||
assert resp.json['msg'].startswith(u"syntax error: Unused 'éléphant'")
|
||||
assert resp.json['msg'].startswith("syntax error: Unused 'éléphant'")
|
||||
resp = get_app(pub).get('/api/validate-condition?type=django&value_django=~2')
|
||||
assert resp.json['klass'] == 'error'
|
||||
assert resp.json['msg'].startswith('syntax error')
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import urllib.parse
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.utils.encoding import force_text
|
||||
from quixote import get_publisher
|
||||
|
@ -233,7 +231,7 @@ def test_cards_import_csv(pub, local_user, auth):
|
|||
)
|
||||
assert resp.json == {'err': 0}
|
||||
assert carddef.data_class().count() == 2
|
||||
assert set([x.data['0'] for x in carddef.data_class().select()]) == {'first entry', 'second entry'}
|
||||
assert {x.data['0'] for x in carddef.data_class().select()} == {'first entry', 'second entry'}
|
||||
|
||||
# async mode
|
||||
carddef.data_class().wipe()
|
||||
|
@ -245,7 +243,7 @@ def test_cards_import_csv(pub, local_user, auth):
|
|||
)
|
||||
# afterjobs are not async in tests: job is already completed during request
|
||||
assert carddef.data_class().count() == 2
|
||||
assert set([x.data['0'] for x in carddef.data_class().select()]) == {'first entry', 'second entry'}
|
||||
assert {x.data['0'] for x in carddef.data_class().select()} == {'first entry', 'second entry'}
|
||||
assert resp.json['err'] == 0
|
||||
assert 'job' in resp.json['data']
|
||||
job_id = resp.json['data']['job']['id']
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
@ -87,7 +85,7 @@ def test_categories(pub):
|
|||
assert resp.json['data'][0]['title'] == 'Category'
|
||||
assert resp.json['data'][0]['url'] == 'http://example.net/category/'
|
||||
assert resp.json['data'][0]['description'] == '<p>hello world</p>'
|
||||
assert set(resp.json['data'][0]['keywords']) == set(['foobar', 'mobile', 'test'])
|
||||
assert set(resp.json['data'][0]['keywords']) == {'foobar', 'mobile', 'test'}
|
||||
assert 'forms' not in resp.json['data'][0]
|
||||
|
||||
# check HTML description
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import os
|
||||
import xml.etree.ElementTree as ET
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import io
|
||||
|
@ -248,9 +246,7 @@ def test_formdata(pub, local_user):
|
|||
|
||||
assert [x.get('id') for x in resp.json['roles']['_receiver']] == [str(role.id)]
|
||||
assert [x.get('id') for x in resp.json['roles']['_foobar']] == [str(another_role.id)]
|
||||
assert set([x.get('id') for x in resp.json['roles']['concerned']]) == set(
|
||||
[str(role.id), str(another_role.id)]
|
||||
)
|
||||
assert {x.get('id') for x in resp.json['roles']['concerned']} == {str(role.id), str(another_role.id)}
|
||||
assert [x.get('id') for x in resp.json['roles']['actions']] == [str(role.id)]
|
||||
|
||||
# check the ?format=json endpoint returns 403
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import io
|
||||
|
@ -7,8 +5,8 @@ import json
|
|||
import os
|
||||
import time
|
||||
import urllib.parse
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.utils.encoding import force_text
|
||||
from quixote import get_publisher
|
||||
|
@ -406,26 +404,24 @@ def test_formdef_schema(pub):
|
|||
|
||||
# check schema
|
||||
assert resp.json == resp2.json
|
||||
assert set(resp.json.keys()) >= set(
|
||||
[
|
||||
'enable_tracking_codes',
|
||||
'url_name',
|
||||
'description',
|
||||
'workflow',
|
||||
'expiration_date',
|
||||
'discussion',
|
||||
'has_captcha',
|
||||
'always_advertise',
|
||||
'name',
|
||||
'disabled',
|
||||
'only_allow_one',
|
||||
'fields',
|
||||
'keywords',
|
||||
'publication_date',
|
||||
'detailed_emails',
|
||||
'disabled_redirection',
|
||||
]
|
||||
)
|
||||
assert set(resp.json.keys()) >= {
|
||||
'enable_tracking_codes',
|
||||
'url_name',
|
||||
'description',
|
||||
'workflow',
|
||||
'expiration_date',
|
||||
'discussion',
|
||||
'has_captcha',
|
||||
'always_advertise',
|
||||
'name',
|
||||
'disabled',
|
||||
'only_allow_one',
|
||||
'fields',
|
||||
'keywords',
|
||||
'publication_date',
|
||||
'detailed_emails',
|
||||
'disabled_redirection',
|
||||
}
|
||||
assert resp.json['name'] == 'test'
|
||||
|
||||
# fields checks
|
||||
|
@ -443,9 +439,9 @@ def test_formdef_schema(pub):
|
|||
|
||||
assert len(resp3.json['fields'][1]['structured_items']) == 3
|
||||
assert resp3.json['fields'][1]['structured_items'][0]['id'] == 0
|
||||
assert resp3.json['fields'][1]['structured_items'][0]['text'] == u'zéro'
|
||||
assert resp3.json['fields'][1]['structured_items'][0]['text'] == 'zéro'
|
||||
assert resp3.json['fields'][1]['structured_items'][0]['foo'] == 'bar'
|
||||
assert resp3.json['fields'][1]['items'][0] == u'zéro'
|
||||
assert resp3.json['fields'][1]['items'][0] == 'zéro'
|
||||
|
||||
assert resp3.json['fields'][2]['label'] == 'foobar2'
|
||||
assert resp3.json['fields'][2]['type'] == 'items'
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import hashlib
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import io
|
||||
import json
|
||||
|
@ -8,8 +6,8 @@ import random
|
|||
import re
|
||||
import time
|
||||
import zipfile
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from quixote import get_publisher
|
||||
from quixote.http_request import Upload as QuixoteUpload
|
||||
|
@ -976,23 +974,23 @@ def test_backoffice_item_filter(pub):
|
|||
|
||||
resp.forms['listing-settings']['filter-4-value'].value = 'â'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â</td>') > 0
|
||||
assert resp.text.count(u'<td>b</td>') == 0
|
||||
assert resp.text.count(u'<td>d</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') > 0
|
||||
assert resp.text.count('<td>b</td>') == 0
|
||||
assert resp.text.count('<td>d</td>') == 0
|
||||
|
||||
resp.forms['listing-settings']['filter-4-value'].value = 'b'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â</td>') == 0
|
||||
assert resp.text.count(u'<td>b</td>') > 0
|
||||
assert resp.text.count(u'<td>d</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') == 0
|
||||
assert resp.text.count('<td>b</td>') > 0
|
||||
assert resp.text.count('<td>d</td>') == 0
|
||||
|
||||
if not pub.is_using_postgresql():
|
||||
# in pickle all options are always displayed
|
||||
resp.forms['listing-settings']['filter-4-value'].value = 'c'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â</td>') == 0
|
||||
assert resp.text.count(u'<td>b</td>') == 0
|
||||
assert resp.text.count(u'<td>c</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') == 0
|
||||
assert resp.text.count('<td>b</td>') == 0
|
||||
assert resp.text.count('<td>c</td>') == 0
|
||||
|
||||
else:
|
||||
# in postgresql, option 'c' is never used so not even listed
|
||||
|
@ -1001,7 +999,7 @@ def test_backoffice_item_filter(pub):
|
|||
|
||||
# check json view used to fill select filters from javascript
|
||||
resp2 = app.get(resp.request.path + 'filter-options?filter_field_id=4&' + resp.request.query_string)
|
||||
assert [x['id'] for x in resp2.json['data']] == [u'â', u'b', u'd']
|
||||
assert [x['id'] for x in resp2.json['data']] == ['â', 'b', 'd']
|
||||
resp2 = app.get(
|
||||
resp.request.path + 'filter-options?filter_field_id=4&_search=d&' + resp.request.query_string
|
||||
)
|
||||
|
@ -1019,7 +1017,7 @@ def test_backoffice_item_filter(pub):
|
|||
if status == 'accepted':
|
||||
assert [x['id'] for x in resp2.json['data']] == []
|
||||
else:
|
||||
assert [x['id'] for x in resp2.json['data']] == [u'â', u'b', u'd']
|
||||
assert [x['id'] for x in resp2.json['data']] == ['â', 'b', 'd']
|
||||
|
||||
|
||||
def test_backoffice_item_double_filter(pub):
|
||||
|
@ -1146,23 +1144,23 @@ def test_backoffice_bofield_item_filter(pub):
|
|||
|
||||
resp.forms['listing-settings']['filter-bo0-1-value'].value = 'â'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â</td>') > 0
|
||||
assert resp.text.count(u'<td>b</td>') == 0
|
||||
assert resp.text.count(u'<td>d</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') > 0
|
||||
assert resp.text.count('<td>b</td>') == 0
|
||||
assert resp.text.count('<td>d</td>') == 0
|
||||
|
||||
resp.forms['listing-settings']['filter-bo0-1-value'].value = 'b'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â</td>') == 0
|
||||
assert resp.text.count(u'<td>b</td>') > 0
|
||||
assert resp.text.count(u'<td>d</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') == 0
|
||||
assert resp.text.count('<td>b</td>') > 0
|
||||
assert resp.text.count('<td>d</td>') == 0
|
||||
|
||||
if not pub.is_using_postgresql():
|
||||
# in pickle all options are always displayed
|
||||
resp.forms['listing-settings']['filter-bo0-1-value'].value = 'c'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â</td>') == 0
|
||||
assert resp.text.count(u'<td>b</td>') == 0
|
||||
assert resp.text.count(u'<td>c</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') == 0
|
||||
assert resp.text.count('<td>b</td>') == 0
|
||||
assert resp.text.count('<td>c</td>') == 0
|
||||
|
||||
else:
|
||||
# in postgresql, option 'c' is never used so not even listed
|
||||
|
@ -1173,7 +1171,7 @@ def test_backoffice_bofield_item_filter(pub):
|
|||
resp2 = app.get(
|
||||
resp.request.path + 'filter-options?filter_field_id=bo0-1&' + resp.request.query_string
|
||||
)
|
||||
assert [x['id'] for x in resp2.json['data']] == [u'â', u'b', u'd']
|
||||
assert [x['id'] for x in resp2.json['data']] == ['â', 'b', 'd']
|
||||
resp2 = app.get(
|
||||
resp.request.path + 'filter-options?filter_field_id=bo0-1&_search=d&' + resp.request.query_string
|
||||
)
|
||||
|
@ -1188,7 +1186,7 @@ def test_backoffice_bofield_item_filter(pub):
|
|||
if status == 'accepted':
|
||||
assert [x['id'] for x in resp2.json['data']] == []
|
||||
else:
|
||||
assert [x['id'] for x in resp2.json['data']] == [u'â', u'b', u'd']
|
||||
assert [x['id'] for x in resp2.json['data']] == ['â', 'b', 'd']
|
||||
|
||||
|
||||
def test_backoffice_items_filter(pub):
|
||||
|
@ -1230,15 +1228,15 @@ def test_backoffice_items_filter(pub):
|
|||
|
||||
resp.forms['listing-settings']['filter-4-value'].value = 'â'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â, b</td>') > 0
|
||||
assert resp.text.count(u'<td>â</td>') > 0
|
||||
assert resp.text.count(u'<td>b, d</td>') == 0
|
||||
assert resp.text.count('<td>â, b</td>') > 0
|
||||
assert resp.text.count('<td>â</td>') > 0
|
||||
assert resp.text.count('<td>b, d</td>') == 0
|
||||
|
||||
resp.forms['listing-settings']['filter-4-value'].value = 'b'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â, b</td>') > 0
|
||||
assert resp.text.count(u'<td>â</td>') == 0
|
||||
assert resp.text.count(u'<td>b, d</td>') > 0
|
||||
assert resp.text.count('<td>â, b</td>') > 0
|
||||
assert resp.text.count('<td>â</td>') == 0
|
||||
assert resp.text.count('<td>b, d</td>') > 0
|
||||
|
||||
if pub.is_using_postgresql():
|
||||
# option 'c' is never used so not even listed
|
||||
|
@ -1247,9 +1245,9 @@ def test_backoffice_items_filter(pub):
|
|||
else:
|
||||
resp.forms['listing-settings']['filter-4-value'].value = 'c'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count(u'<td>â, b</td>') == 0
|
||||
assert resp.text.count(u'<td>â</td>') == 0
|
||||
assert resp.text.count(u'<td>b, d</td>') == 0
|
||||
assert resp.text.count('<td>â, b</td>') == 0
|
||||
assert resp.text.count('<td>â</td>') == 0
|
||||
assert resp.text.count('<td>b, d</td>') == 0
|
||||
assert resp.text.count('data-link') == 0 # no rows
|
||||
|
||||
|
||||
|
@ -4376,14 +4374,14 @@ def test_backoffice_workflow_form_with_live_data_source(pub):
|
|||
resp = login(app).get(formdata.get_url(backoffice=True))
|
||||
assert 'fblah_1' in resp.form.fields
|
||||
assert 'fblah_2' in resp.form.fields
|
||||
assert resp.form.fields['fblah_2'][0].options == [(u'A', False, u'hello'), (u'B', False, u'world')]
|
||||
assert resp.form.fields['fblah_2'][0].options == [('A', False, 'hello'), ('B', False, 'world')]
|
||||
|
||||
live_url = resp.html.find('form').attrs['data-live-url']
|
||||
resp.form['fblah_1'] = 'toto'
|
||||
live_resp = app.post(live_url + '?modified_field_id=blah_1', params=resp.form.submit_fields())
|
||||
assert live_resp.json['result']['blah_2']['items'] == [
|
||||
{u'text': u'hello', u'id': u'C'},
|
||||
{u'text': u'world', u'id': u'D'},
|
||||
{'text': 'hello', 'id': 'C'},
|
||||
{'text': 'world', 'id': 'D'},
|
||||
]
|
||||
|
||||
|
||||
|
@ -4600,7 +4598,7 @@ def test_inspect_page(pub, local_user):
|
|||
formdata = [x for x in formdef.data_class().select() if x.status == 'wf-new'][0]
|
||||
# temper with field 3 structured values
|
||||
formdata.data['3_structured'] = {
|
||||
'unicode': u'uné',
|
||||
'unicode': 'uné',
|
||||
'str_but_non_utf8': b'\xed\xa0\x00', # not actually supposed to happen
|
||||
'non_unicode_convertible': IHateUnicode(),
|
||||
'very_long_string': '0' * 100000,
|
||||
|
@ -4639,7 +4637,7 @@ def test_inspect_page(pub, local_user):
|
|||
assert '0' * 1000 in resp.text
|
||||
assert len(resp.text) < 100000
|
||||
pq = resp.pyquery.remove_namespaces()
|
||||
assert pq('[title="form_var_foo_unicode"]').parents('li').children('div.value span').text() == u'uné'
|
||||
assert pq('[title="form_var_foo_unicode"]').parents('li').children('div.value span').text() == 'uné'
|
||||
assert (
|
||||
pq('[title="form_var_foo_non_unicode_convertible"]')
|
||||
.parents('li')
|
||||
|
@ -5680,7 +5678,7 @@ def test_backoffice_forms_condition_on_button(pub):
|
|||
assert 'button_reject' not in resp.text
|
||||
|
||||
formdef = FormDef.get_by_urlname('form-title')
|
||||
assert formdef.data_class().get(formdata.id).actions_roles == set(['1'])
|
||||
assert formdef.data_class().get(formdata.id).actions_roles == {'1'}
|
||||
|
||||
# accept
|
||||
workflow.possible_status[1].items[1].condition = {'type': 'python', 'value': 'False'}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import os
|
||||
import uuid
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
|
||||
|
@ -443,9 +442,11 @@ def test_backoffice_custom_view_visibility(pub):
|
|||
resp.forms['save-custom-view']['title'] = 'shared view'
|
||||
resp.forms['save-custom-view']['visibility'] = 'any'
|
||||
resp = resp.forms['save-custom-view'].submit()
|
||||
assert set([(x.slug, x.visibility) for x in get_publisher().custom_view_class.select()]) == set(
|
||||
[('custom-test-view', 'owner'), ('shared-view', 'any'), ('shared-view-2', 'any')]
|
||||
)
|
||||
assert {(x.slug, x.visibility) for x in get_publisher().custom_view_class.select()} == {
|
||||
('custom-test-view', 'owner'),
|
||||
('shared-view', 'any'),
|
||||
('shared-view-2', 'any'),
|
||||
}
|
||||
|
||||
|
||||
def test_backoffice_custom_view_is_default(pub):
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import io
|
||||
import os
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import os
|
||||
import re
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
|
@ -9,8 +7,8 @@ import time
|
|||
import urllib.parse
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from webtest import Hidden, Radio, Upload
|
||||
|
||||
|
@ -2448,7 +2446,7 @@ def form_password_field_submit(app, password):
|
|||
def test_form_password_field_submit(pub):
|
||||
create_user(pub)
|
||||
form_password_field_submit(get_app(pub), 'foobar')
|
||||
form_password_field_submit(get_app(pub), force_str(u'• 83003706'))
|
||||
form_password_field_submit(get_app(pub), force_str('• 83003706'))
|
||||
form_password_field_submit(login(get_app(pub), username='foo', password='foo'), 'foobar\u00eb')
|
||||
|
||||
|
||||
|
@ -3702,8 +3700,8 @@ def test_form_table_field_submit(pub, emails):
|
|||
id='0',
|
||||
label='table',
|
||||
type='table',
|
||||
rows=[force_str(u'à'), 'b'],
|
||||
columns=['c', 'd', force_str(u'e')],
|
||||
rows=[force_str('à'), 'b'],
|
||||
columns=['c', 'd', force_str('e')],
|
||||
required=False,
|
||||
)
|
||||
]
|
||||
|
@ -4301,7 +4299,7 @@ def test_form_text_field_submit(pub):
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert 'too many characters (limit is 10)' in resp.text
|
||||
# check it counts characters, not bytes
|
||||
resp.forms[0]['f0'] = u'☭' * 10
|
||||
resp.forms[0]['f0'] = '☭' * 10
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert 'Check values then click submit.' in resp.text
|
||||
|
||||
|
@ -4555,7 +4553,7 @@ def test_form_autosave_with_items_field(pub):
|
|||
id='3',
|
||||
label='items',
|
||||
type='items',
|
||||
items=[force_str(x) for x in (u'pomme', u'poire', u'pêche', u'abricot')],
|
||||
items=[force_str(x) for x in ('pomme', 'poire', 'pêche', 'abricot')],
|
||||
),
|
||||
]
|
||||
formdef.enable_tracking_codes = True
|
||||
|
@ -5350,9 +5348,9 @@ def test_item_field_from_cards(pub):
|
|||
|
||||
resp = get_app(pub).get('/test/')
|
||||
assert resp.form['f0'].options == [
|
||||
(u'2', False, u'bar'),
|
||||
(u'3', False, u'baz'),
|
||||
(u'1', False, u'foo'),
|
||||
('2', False, 'bar'),
|
||||
('3', False, 'baz'),
|
||||
('1', False, 'foo'),
|
||||
]
|
||||
resp.form['f0'] = '2'
|
||||
resp = resp.form.submit('submit') # -> validation page
|
||||
|
@ -5430,7 +5428,7 @@ def test_item_field_from_custom_view_on_cards(pub):
|
|||
|
||||
resp = get_app(pub).get('/test/')
|
||||
assert len(resp.form['f0'].options) == 10
|
||||
assert set([x[0] for x in resp.form['f0'].options]) == baz_ids
|
||||
assert {x[0] for x in resp.form['f0'].options} == baz_ids
|
||||
resp = resp.form.submit('submit') # -> validation page
|
||||
resp = resp.form.submit('submit') # -> submit
|
||||
assert formdef.data_class().select()[0].data['0'] in baz_ids
|
||||
|
@ -5524,7 +5522,7 @@ def test_dynamic_item_field_from_custom_view_on_cards(pub):
|
|||
resp.form['f0'] = 'baz'
|
||||
live_resp = app.post('/test/live?modified_field_id=0', params=resp.form.submit_fields())
|
||||
assert len(live_resp.json['result']['1']['items']) == 10
|
||||
assert set([x['id'] for x in live_resp.json['result']['1']['items']]) == baz_ids
|
||||
assert {x['id'] for x in live_resp.json['result']['1']['items']} == baz_ids
|
||||
|
||||
resp.form['f1'].options = []
|
||||
for item in live_resp.json['result']['1']['items']:
|
||||
|
@ -5553,7 +5551,7 @@ def test_dynamic_item_field_from_custom_view_on_cards(pub):
|
|||
new_select2_url = live_resp.json['result']['1']['source_url']
|
||||
resp_json = app.get(new_select2_url + '?q=')
|
||||
assert len(resp_json.json['data']) == 10
|
||||
assert set([str(x['id']) for x in resp_json.json['data']]) == baz_ids
|
||||
assert {str(x['id']) for x in resp_json.json['data']} == baz_ids
|
||||
|
||||
resp.form['f1'].force_value(str(resp_json.json['data'][0]['id']))
|
||||
resp.form.fields['f1_display'].force_value(resp_json.json['data'][0]['text'])
|
||||
|
@ -6778,7 +6776,7 @@ def test_email_actions(pub, emails):
|
|||
|
||||
app = get_app(pub)
|
||||
resp = app.get(action_url)
|
||||
assert u'Accepté!' in resp.text
|
||||
assert 'Accepté!' in resp.text
|
||||
resp = resp.form.submit()
|
||||
assert 'The action has been confirmed.' in resp.text
|
||||
assert formdef.data_class().count() == 1
|
||||
|
@ -7088,7 +7086,7 @@ def test_field_unicode_condition_in_array(pub):
|
|||
resp = resp.form.submit('submit')
|
||||
assert 'f3' in resp.form.fields # check it's ok in field condition
|
||||
resp.form['f3'] = 'hop'
|
||||
assert u'>Poire, Pêche<' in resp.text # check it's displayed correctly
|
||||
assert '>Poire, Pêche<' in resp.text # check it's displayed correctly
|
||||
assert 'CHECK OK' in resp.text # check it's ok in template condition
|
||||
resp = resp.form.submit('submit')
|
||||
assert 'Check values then click submit.' in resp.text
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import json
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from webtest import Upload
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import io
|
||||
import json
|
||||
|
@ -8,8 +6,8 @@ import os
|
|||
import urllib.parse
|
||||
import xml.etree.ElementTree as ET
|
||||
import zipfile
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.utils.encoding import force_bytes
|
||||
from quixote.http_request import Upload as QuixoteUpload
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import collections
|
||||
import os
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import psycopg2
|
||||
import pytest
|
||||
from django.core.management import CommandError, call_command
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import codecs
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import urllib.parse
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from wcs import data_sources, fields
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from wcs import fields
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
|
||||
from wcs import data_sources
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import base64
|
||||
import json
|
||||
import urllib.parse
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from quixote import cleanup, get_session_manager
|
||||
|
||||
|
@ -15,7 +15,7 @@ PROFILE = {
|
|||
'description': '',
|
||||
'required': True,
|
||||
'user_visible': True,
|
||||
'label': u'Prenoms',
|
||||
'label': 'Prenoms',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': True,
|
||||
|
@ -161,7 +161,7 @@ def test_fc_login_page(caplog):
|
|||
assert pub.user_class.count() == 1
|
||||
user = pub.user_class.select()[0]
|
||||
assert user.form_data == {'_email': 'john.doe@example.com', '_nom': 'Doe', '_prenoms': 'John'}
|
||||
assert set(user.verified_fields) == set(['_nom', '_prenoms', '_email'])
|
||||
assert set(user.verified_fields) == {'_nom', '_prenoms', '_email'}
|
||||
assert user.email == 'john.doe@example.com'
|
||||
assert user.name_identifiers == ['ymca']
|
||||
assert user.name == 'John Doe'
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import re
|
||||
import shutil
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from quixote import get_publisher
|
||||
from quixote.http_request import Upload
|
||||
|
@ -1122,20 +1120,20 @@ def test_lazy_formdata_queryset_distance(pub, variable_test_data):
|
|||
# compute distance against map field of lazy formdata
|
||||
nearby = lazy_formdata.objects.distance_filter(200000)
|
||||
assert len(nearby) == 6
|
||||
assert set([x.number for x in nearby]) == set(['1-1', '1-3', '1-4', '1-8', '1-9', '1-10'])
|
||||
assert {x.number for x in nearby} == {'1-1', '1-3', '1-4', '1-8', '1-9', '1-10'}
|
||||
nearby = lazy_carddata.objects.set_geo_center(lazy_formdata).distance_filter(200000)
|
||||
assert len(nearby) == 6
|
||||
assert set([x.number for x in nearby]) == set(['1-1', '1-3', '1-4', '1-8', '1-9', '1-10'])
|
||||
assert {x.number for x in nearby} == {'1-1', '1-3', '1-4', '1-8', '1-9', '1-10'}
|
||||
|
||||
# compute distance against geolocation
|
||||
lazy_formdata._formdata.geolocations = {'base': {'lat': 2, 'lon': 2.5}}
|
||||
nearby = lazy_formdata.objects.distance_filter(200000)
|
||||
assert len(nearby) == 6
|
||||
assert set([x.number for x in nearby]) == set(['1-1', '1-4', '1-5', '1-9', '1-10', '1-11'])
|
||||
assert {x.number for x in nearby} == {'1-1', '1-4', '1-5', '1-9', '1-10', '1-11'}
|
||||
assert bool(nearby) is True
|
||||
nearby = lazy_carddata.objects.set_geo_center(lazy_formdata).distance_filter(200000)
|
||||
assert len(nearby) == 6
|
||||
assert set([x.number for x in nearby]) == set(['1-1', '1-4', '1-5', '1-9', '1-10', '1-11'])
|
||||
assert {x.number for x in nearby} == {'1-1', '1-4', '1-5', '1-9', '1-10', '1-11'}
|
||||
assert bool(nearby) is True
|
||||
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
|
@ -1485,7 +1483,7 @@ def test_lazy_formdata_queryset_filter(pub, variable_test_data):
|
|||
'foo',
|
||||
'foo',
|
||||
]
|
||||
assert set(LazyFormData(formdata).objects.getlist('unknown')) == set([None])
|
||||
assert set(LazyFormData(formdata).objects.getlist('unknown')) == {None}
|
||||
tmpl = Template('{{form_objects|pending|getlist:"foo_foo"|is_empty}}')
|
||||
assert tmpl.render(context) == 'False'
|
||||
tmpl = Template('{{form_objects|filter_by:"foo_foo"|filter_value:"foo"|getlist:"foo_foo"|is_empty}}')
|
||||
|
|
|
@ -539,7 +539,7 @@ def test_get_formdefs_of_all_kinds(pub):
|
|||
|
||||
formdefs = get_formdefs_of_all_kinds()
|
||||
assert len(formdefs) == 6
|
||||
assert sorted([(f.name, f.__class__) for f in formdefs]) == [
|
||||
assert sorted((f.name, f.__class__) for f in formdefs) == [
|
||||
(
|
||||
'Backoffice fields of workflow "workflow with backoffice fields formdef"',
|
||||
WorkflowBackofficeFieldsFormDef,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import shutil
|
||||
import time
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import collections
|
||||
import copy
|
||||
import json
|
||||
|
@ -8,8 +7,8 @@ import shutil
|
|||
import sys
|
||||
import tempfile
|
||||
import urllib.parse
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
from quixote import cleanup
|
||||
|
||||
from wcs import fields, sql
|
||||
|
@ -73,7 +72,7 @@ HOBO_JSON = {
|
|||
'description': '',
|
||||
'required': False,
|
||||
'user_visible': True,
|
||||
'label': u'Civilité',
|
||||
'label': 'Civilité',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
|
@ -84,7 +83,7 @@ HOBO_JSON = {
|
|||
'description': '',
|
||||
'required': True,
|
||||
'user_visible': True,
|
||||
'label': u'Prénom',
|
||||
'label': 'Prénom',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': True,
|
||||
|
@ -106,7 +105,7 @@ HOBO_JSON = {
|
|||
'description': '',
|
||||
'required': True,
|
||||
'user_visible': True,
|
||||
'label': u'Adresse électronique',
|
||||
'label': 'Adresse électronique',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
|
@ -150,7 +149,7 @@ HOBO_JSON = {
|
|||
'description': '',
|
||||
'required': False,
|
||||
'user_visible': True,
|
||||
'label': u'Téléphone',
|
||||
'label': 'Téléphone',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
@ -35,27 +34,27 @@ def pub(request):
|
|||
|
||||
def test_process_notification_role_wrong_audience(pub):
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'coin'],
|
||||
'@type': 'provision',
|
||||
'audience': ['coin'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'description': 'Rôle du service petite enfance',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-etat-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'name': 'Service état civil',
|
||||
'slug': 'service-etat-civil',
|
||||
'description': 'Rôle du service état civil',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails': ['etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
],
|
||||
|
@ -80,26 +79,26 @@ def test_process_notification_role(pub):
|
|||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'details': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'details': 'Rôle du service petite enfance',
|
||||
'uuid': uuid1,
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'details': u'Rôle du service état civil',
|
||||
'name': 'Service état civil',
|
||||
'slug': 'service-ett-civil',
|
||||
'details': 'Rôle du service état civil',
|
||||
'uuid': uuid2,
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails': ['etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
],
|
||||
|
@ -130,19 +129,19 @@ def test_process_notification_role(pub):
|
|||
assert new_role.emails == ['petite-enfance@example.com']
|
||||
assert new_role.emails_to_members is False
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'description': 'Rôle du service petite enfance',
|
||||
'uuid': uuid1,
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
],
|
||||
|
@ -163,18 +162,18 @@ def test_process_notification_internal_role(pub):
|
|||
pub.role_class.wipe()
|
||||
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'_service-enfance',
|
||||
'details': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': '_service-enfance',
|
||||
'details': 'Rôle du service petite enfance',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
],
|
||||
|
@ -191,26 +190,26 @@ def test_process_notification_role_description(pub):
|
|||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'description': 'Rôle du service petite enfance',
|
||||
'uuid': uuid1,
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'name': 'Service état civil',
|
||||
'slug': 'service-ett-civil',
|
||||
'description': 'Rôle du service état civil',
|
||||
'uuid': uuid2,
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails': ['etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
],
|
||||
|
@ -240,19 +239,19 @@ def test_process_notification_role_description(pub):
|
|||
assert new_role.emails == ['petite-enfance@example.com']
|
||||
assert new_role.emails_to_members is False
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'@type': 'role',
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'description': 'Rôle du service petite enfance',
|
||||
'uuid': uuid1,
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
],
|
||||
|
@ -272,8 +271,8 @@ def test_process_notification_role_description(pub):
|
|||
def test_process_notification_role_deprovision(pub):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
notification = {
|
||||
'@type': u'deprovision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'deprovision',
|
||||
'audience': ['test'],
|
||||
'full': False,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
|
@ -317,7 +316,7 @@ PROFILE = {
|
|||
'description': '',
|
||||
'required': False,
|
||||
'user_visible': True,
|
||||
'label': u'Civilité',
|
||||
'label': 'Civilité',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
|
@ -328,7 +327,7 @@ PROFILE = {
|
|||
'description': '',
|
||||
'required': True,
|
||||
'user_visible': True,
|
||||
'label': u'Prénom',
|
||||
'label': 'Prénom',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': True,
|
||||
|
@ -350,7 +349,7 @@ PROFILE = {
|
|||
'description': '',
|
||||
'required': True,
|
||||
'user_visible': True,
|
||||
'label': u'Adresse électronique',
|
||||
'label': 'Adresse électronique',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
|
@ -394,7 +393,7 @@ PROFILE = {
|
|||
'description': '',
|
||||
'required': False,
|
||||
'user_visible': True,
|
||||
'label': u'Téléphone',
|
||||
'label': 'Téléphone',
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
|
@ -449,26 +448,26 @@ def test_process_notification_user_provision(pub):
|
|||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'description': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'description': 'Rôle du service petite enfance',
|
||||
'uuid': uuid1,
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
},
|
||||
{
|
||||
'name': u'Service état civil',
|
||||
'slug': u'service-ett-civil',
|
||||
'description': u'Rôle du service état civil',
|
||||
'name': 'Service état civil',
|
||||
'slug': 'service-ett-civil',
|
||||
'description': 'Rôle du service état civil',
|
||||
'uuid': uuid2,
|
||||
'emails': [u'etat-civil@example.com'],
|
||||
'emails': ['etat-civil@example.com'],
|
||||
'emails_to_members': True,
|
||||
},
|
||||
],
|
||||
|
@ -499,30 +498,30 @@ def test_process_notification_user_provision(pub):
|
|||
assert new_role.emails_to_members is False
|
||||
|
||||
notification = {
|
||||
u'@type': u'provision',
|
||||
u'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
u'audience': [u'test'],
|
||||
u'objects': {
|
||||
u'@type': 'user',
|
||||
u'data': [
|
||||
'@type': 'provision',
|
||||
'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
'audience': ['test'],
|
||||
'objects': {
|
||||
'@type': 'user',
|
||||
'data': [
|
||||
{
|
||||
u'uuid': u'a' * 32,
|
||||
u'first_name': u'John',
|
||||
u'last_name': u'Doé',
|
||||
u'email': u'john.doe@example.net',
|
||||
u'zipcode': u'13400',
|
||||
u'is_superuser': False,
|
||||
'uuid': 'a' * 32,
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doé',
|
||||
'email': 'john.doe@example.net',
|
||||
'zipcode': '13400',
|
||||
'is_superuser': False,
|
||||
'is_active': True,
|
||||
u'roles': [
|
||||
'roles': [
|
||||
{
|
||||
u'uuid': uuid1,
|
||||
u'name': u'Service petite enfance',
|
||||
u'description': u'etc.',
|
||||
'uuid': uuid1,
|
||||
'name': 'Service petite enfance',
|
||||
'description': 'etc.',
|
||||
},
|
||||
{
|
||||
u'uuid': uuid2,
|
||||
u'name': u'Service état civil',
|
||||
u'description': u'etc.',
|
||||
'uuid': uuid2,
|
||||
'name': 'Service état civil',
|
||||
'description': 'etc.',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -536,40 +535,40 @@ def test_process_notification_user_provision(pub):
|
|||
assert user.form_data['_email'] == 'john.doe@example.net'
|
||||
assert user.email == 'john.doe@example.net'
|
||||
assert user.form_data['_first_name'] == 'John'
|
||||
assert user.form_data['_last_name'] == force_str(u'Doé')
|
||||
assert user.form_data['_last_name'] == force_str('Doé')
|
||||
assert user.form_data['_zipcode'] == '13400'
|
||||
assert user.form_data['_birthdate'] is None
|
||||
assert user.name_identifiers == ['a' * 32]
|
||||
assert user.is_admin is False
|
||||
assert user.is_active is True
|
||||
assert set(user.roles) == set([new_role.id, old_role.id])
|
||||
assert set(user.roles) == {new_role.id, old_role.id}
|
||||
|
||||
notification = {
|
||||
u'@type': u'provision',
|
||||
u'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
u'audience': [u'test'],
|
||||
u'objects': {
|
||||
u'@type': 'user',
|
||||
u'data': [
|
||||
'@type': 'provision',
|
||||
'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
'audience': ['test'],
|
||||
'objects': {
|
||||
'@type': 'user',
|
||||
'data': [
|
||||
{
|
||||
u'uuid': u'a' * 32,
|
||||
u'first_name': u'John',
|
||||
u'last_name': u'Doe',
|
||||
u'email': u'john.doe@example.net',
|
||||
u'zipcode': u'13600',
|
||||
u'birthdate': u'2000-01-01',
|
||||
u'is_superuser': True,
|
||||
'uuid': 'a' * 32,
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'email': 'john.doe@example.net',
|
||||
'zipcode': '13600',
|
||||
'birthdate': '2000-01-01',
|
||||
'is_superuser': True,
|
||||
'is_active': False,
|
||||
u'roles': [
|
||||
'roles': [
|
||||
{
|
||||
u'uuid': uuid2,
|
||||
u'name': u'Service état civil',
|
||||
u'description': u'etc.',
|
||||
'uuid': uuid2,
|
||||
'name': 'Service état civil',
|
||||
'description': 'etc.',
|
||||
},
|
||||
{
|
||||
u'uuid': str(uuid.uuid4()),
|
||||
u'name': u'Service enfance',
|
||||
u'description': u'',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'name': 'Service enfance',
|
||||
'description': '',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -589,29 +588,29 @@ def test_process_notification_user_provision(pub):
|
|||
assert user.name_identifiers == ['a' * 32]
|
||||
assert user.is_admin is True
|
||||
assert user.is_active is False
|
||||
assert set(user.roles) == set([old_role.id])
|
||||
assert set(user.roles) == {old_role.id}
|
||||
|
||||
for birthdate in ('baddate', '', None):
|
||||
notification = {
|
||||
u'@type': u'provision',
|
||||
u'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
u'audience': [u'test'],
|
||||
u'objects': {
|
||||
u'@type': 'user',
|
||||
u'data': [
|
||||
'@type': 'provision',
|
||||
'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
'audience': ['test'],
|
||||
'objects': {
|
||||
'@type': 'user',
|
||||
'data': [
|
||||
{
|
||||
u'uuid': u'a' * 32,
|
||||
u'first_name': u'John',
|
||||
u'last_name': u'Doe',
|
||||
u'email': u'john.doe@example.net',
|
||||
u'zipcode': u'13600',
|
||||
u'birthdate': birthdate,
|
||||
u'is_superuser': True,
|
||||
u'roles': [
|
||||
'uuid': 'a' * 32,
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'email': 'john.doe@example.net',
|
||||
'zipcode': '13600',
|
||||
'birthdate': birthdate,
|
||||
'is_superuser': True,
|
||||
'roles': [
|
||||
{
|
||||
u'uuid': uuid2,
|
||||
u'name': u'Service état civil',
|
||||
u'description': u'etc.',
|
||||
'uuid': uuid2,
|
||||
'name': 'Service état civil',
|
||||
'description': 'etc.',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -679,25 +678,25 @@ def test_process_notification_user_with_errors(pub):
|
|||
CmdCheckHobos().update_profile(PROFILE, pub)
|
||||
|
||||
notification = {
|
||||
u'@type': u'provision',
|
||||
u'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
u'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'issuer': 'http://idp.example.net/idp/saml/metadata',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
u'objects': {
|
||||
u'@type': 'user',
|
||||
u'data': [
|
||||
'objects': {
|
||||
'@type': 'user',
|
||||
'data': [
|
||||
{
|
||||
u'uuid': u'a' * 32,
|
||||
u'first_name': u'John',
|
||||
u'last_name': u'Doe',
|
||||
u'email': u'john.doe@example.net',
|
||||
u'zipcode': u'13400',
|
||||
u'is_superuser': False,
|
||||
u'roles': [
|
||||
'uuid': 'a' * 32,
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'email': 'john.doe@example.net',
|
||||
'zipcode': '13400',
|
||||
'is_superuser': False,
|
||||
'roles': [
|
||||
{
|
||||
u'uuid': u'xyz',
|
||||
u'name': u'Service état civil',
|
||||
u'description': u'etc.',
|
||||
'uuid': 'xyz',
|
||||
'name': 'Service état civil',
|
||||
'description': 'etc.',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
@ -736,18 +735,18 @@ def test_process_notification_role_with_errors(pub):
|
|||
User.wipe()
|
||||
pub.role_class.wipe()
|
||||
notification = {
|
||||
'@type': u'provision',
|
||||
'audience': [u'test'],
|
||||
'@type': 'provision',
|
||||
'audience': ['test'],
|
||||
'full': True,
|
||||
'objects': {
|
||||
'@type': 'role',
|
||||
'data': [
|
||||
{
|
||||
'name': u'Service enfance',
|
||||
'slug': u'service-enfance',
|
||||
'details': u'Rôle du service petite enfance',
|
||||
'name': 'Service enfance',
|
||||
'slug': 'service-enfance',
|
||||
'details': 'Rôle du service petite enfance',
|
||||
# 'uuid': u'12345',
|
||||
'emails': [u'petite-enfance@example.com'],
|
||||
'emails': ['petite-enfance@example.com'],
|
||||
'emails_to_members': False,
|
||||
}
|
||||
],
|
||||
|
@ -758,7 +757,7 @@ def test_process_notification_role_with_errors(pub):
|
|||
assert e.value.args == ('role without uuid',)
|
||||
assert pub.role_class.count() == 0
|
||||
|
||||
notification['objects']['data'][0]['uuid'] = u'12345'
|
||||
notification['objects']['data'][0]['uuid'] = '12345'
|
||||
del notification['objects']['data'][0]['name']
|
||||
with pytest.raises(ValueError) as e:
|
||||
CmdHoboNotify.process_notification(notification)
|
||||
|
@ -789,7 +788,7 @@ def test_process_user_deprovision(pub):
|
|||
'@type': 'user',
|
||||
'data': [
|
||||
{
|
||||
'uuid': u'a' * 32,
|
||||
'uuid': 'a' * 32,
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -838,7 +837,7 @@ def test_process_user_deprovision_with_data(pub):
|
|||
'@type': 'user',
|
||||
'data': [
|
||||
{
|
||||
'uuid': u'a' * 32,
|
||||
'uuid': 'a' * 32,
|
||||
}
|
||||
],
|
||||
},
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import io
|
||||
import os
|
||||
|
@ -344,7 +342,7 @@ def test_mail_templates_import(pub, superuser, mail_template):
|
|||
resp.forms[0]['file'] = Upload('mail_template.wcs', mail_template_xml)
|
||||
resp = resp.forms[0].submit()
|
||||
assert MailTemplate.count() == 1
|
||||
assert set([wc.slug for wc in MailTemplate.select()]) == set(['foobar'])
|
||||
assert {wc.slug for wc in MailTemplate.select()} == {'foobar'}
|
||||
|
||||
# check slug
|
||||
resp = app.get('/backoffice/workflows/mail-templates/')
|
||||
|
@ -352,13 +350,13 @@ def test_mail_templates_import(pub, superuser, mail_template):
|
|||
resp.forms[0]['file'] = Upload('mail_template.wcs', mail_template_xml)
|
||||
resp = resp.forms[0].submit()
|
||||
assert MailTemplate.count() == 2
|
||||
assert set([wc.slug for wc in MailTemplate.select()]) == set(['foobar', 'test-mt'])
|
||||
assert {wc.slug for wc in MailTemplate.select()} == {'foobar', 'test-mt'}
|
||||
resp = app.get('/backoffice/workflows/mail-templates/')
|
||||
resp = resp.click(href='import')
|
||||
resp.forms[0]['file'] = Upload('mail_template.wcs', mail_template_xml)
|
||||
resp = resp.forms[0].submit()
|
||||
assert MailTemplate.count() == 3
|
||||
assert set([wc.slug for wc in MailTemplate.select()]) == set(['foobar', 'test-mt', 'test-mt-1'])
|
||||
assert {wc.slug for wc in MailTemplate.select()} == {'foobar', 'test-mt', 'test-mt-1'}
|
||||
|
||||
# import an invalid file
|
||||
resp = app.get('/backoffice/workflows/mail-templates/')
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
import json
|
||||
|
@ -8,8 +6,8 @@ import pwd
|
|||
import re
|
||||
import socket
|
||||
import time
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.core.cache import cache
|
||||
from django.utils import translation
|
||||
|
@ -93,9 +91,10 @@ def test_humantime(seconds, expected):
|
|||
def test_parse_mimetypes():
|
||||
assert FileTypesDirectory.parse_mimetypes('application/pdf') == ['application/pdf']
|
||||
assert FileTypesDirectory.parse_mimetypes('.pdf') == ['application/pdf']
|
||||
assert set(FileTypesDirectory.parse_mimetypes('.pdf, .odt')) == set(
|
||||
['application/pdf', 'application/vnd.oasis.opendocument.text']
|
||||
)
|
||||
assert set(FileTypesDirectory.parse_mimetypes('.pdf, .odt')) == {
|
||||
'application/pdf',
|
||||
'application/vnd.oasis.opendocument.text',
|
||||
}
|
||||
|
||||
|
||||
def test_format_mimetypes():
|
||||
|
@ -142,7 +141,7 @@ def test_simplify_apostrophes():
|
|||
|
||||
|
||||
def test_simplify_accented():
|
||||
assert simplify(u'cliché') == 'cliche'
|
||||
assert simplify('cliché') == 'cliche'
|
||||
|
||||
|
||||
def test_simplify_remove():
|
||||
|
@ -151,17 +150,17 @@ def test_simplify_remove():
|
|||
|
||||
|
||||
def test_simplify_mix():
|
||||
assert simplify(u' this is: (a) "cliché" ') == 'this-is-a-cliche'
|
||||
assert simplify(u' À "cliché"; again? ') == 'a-cliche-again'
|
||||
assert simplify(' this is: (a) "cliché" ') == 'this-is-a-cliche'
|
||||
assert simplify(' À "cliché"; again? ') == 'a-cliche-again'
|
||||
|
||||
|
||||
def test_json_str_decoder():
|
||||
json_str = json.dumps({'lst': [{'a': 'b'}, 1, 2], 'bla': u'éléphant'})
|
||||
json_str = json.dumps({'lst': [{'a': 'b'}, 1, 2], 'bla': 'éléphant'})
|
||||
|
||||
assert isinstance(list(json_loads(json_str).keys())[0], str)
|
||||
assert isinstance(json_loads(json_str)['lst'][0]['a'], str)
|
||||
assert isinstance(json_loads(json_str)['bla'], str)
|
||||
assert json_loads(json_str)['bla'] == force_str(u'éléphant')
|
||||
assert json_loads(json_str)['bla'] == force_str('éléphant')
|
||||
|
||||
|
||||
def test_format_time():
|
||||
|
|
|
@ -8,8 +8,8 @@ import sys
|
|||
import tempfile
|
||||
import time
|
||||
import zipfile
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
|
@ -124,7 +122,7 @@ def test_user_password_accents(pub):
|
|||
PasswordAccount.wipe()
|
||||
pub.cfg['passwords'] = {'generate': False, 'hashing_algo': None}
|
||||
pub.write_cfg()
|
||||
password = force_str(u'fooë')
|
||||
password = force_str('fooë')
|
||||
do_user_registration(pub, password=password)
|
||||
|
||||
account = PasswordAccount.get('foo')
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pickle
|
||||
|
||||
from quixote import get_publisher
|
||||
|
|
|
@ -10,7 +10,8 @@ try:
|
|||
except ImportError:
|
||||
lasso = None
|
||||
|
||||
import mock
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from quixote import get_session_manager
|
||||
from quixote.errors import RequestError
|
||||
|
|
|
@ -111,7 +111,7 @@ def test_sessions_visiting_objects(pub, http_request):
|
|||
session1.mark_visited_object(MockFormData(2))
|
||||
session1.store()
|
||||
assert len(pub.session_class.get_visited_objects()) == 2
|
||||
assert set([x[0] for x in pub.session_class.get_object_visitors(MockFormData(2))]) == set(['FOO'])
|
||||
assert {x[0] for x in pub.session_class.get_object_visitors(MockFormData(2))} == {'FOO'}
|
||||
|
||||
# mark a visit as being in the past
|
||||
session1.visiting_objects['formdata-foobar-1'] = time.time() - 35 * 60
|
||||
|
@ -162,8 +162,8 @@ def test_sessions_visiting_objects(pub, http_request):
|
|||
assert list(pub.session_class.get_visited_objects(exclude_user='BAR')) == ['formdata-foobar-2']
|
||||
|
||||
# check visitors
|
||||
assert set([x[0] for x in pub.session_class.get_object_visitors(MockFormData(2))]) == set(['FOO', 'BAR'])
|
||||
assert set([x[0] for x in pub.session_class.get_object_visitors(MockFormData(1))]) == set([])
|
||||
assert {x[0] for x in pub.session_class.get_object_visitors(MockFormData(2))} == {'FOO', 'BAR'}
|
||||
assert {x[0] for x in pub.session_class.get_object_visitors(MockFormData(1))} == set()
|
||||
|
||||
|
||||
def test_session_do_not_reuse_id(pub, user, app):
|
||||
|
|
|
@ -373,7 +373,7 @@ def test_sql_get_ids_with_indexed_value():
|
|||
id3 = formdata.id
|
||||
|
||||
ids = data_class.get_ids_with_indexed_value('user_id', '2')
|
||||
assert set(ids) == set([id2, id3])
|
||||
assert set(ids) == {id2, id3}
|
||||
|
||||
|
||||
def test_sql_get_ids_from_query():
|
||||
|
@ -408,15 +408,15 @@ def test_sql_get_ids_from_query():
|
|||
id4 = formdata.id
|
||||
|
||||
ids = data_class.get_ids_from_query('text')
|
||||
assert set(ids) == set([id1, id3])
|
||||
assert set(ids) == {id1, id3}
|
||||
|
||||
ids = data_class.get_ids_from_query('classical')
|
||||
assert set(ids) == set([id2])
|
||||
assert set(ids) == {id2}
|
||||
|
||||
ids = data_class.get_ids_from_query('FOO')
|
||||
assert set(ids) == set([id4])
|
||||
assert set(ids) == {id4}
|
||||
ids = data_class.get_ids_from_query('cessna')
|
||||
assert set(ids) == set([id4])
|
||||
assert set(ids) == {id4}
|
||||
|
||||
|
||||
def test_sql_fts_index_with_missing_block():
|
||||
|
@ -464,7 +464,7 @@ def test_sql_get_ids_with_indexed_value_dict():
|
|||
id3 = formdata.id
|
||||
|
||||
ids = data_class.get_ids_with_indexed_value('workflow_roles', '2')
|
||||
assert set(ids) == set([id2, id3])
|
||||
assert set(ids) == {id2, id3}
|
||||
|
||||
|
||||
def test_create_user():
|
||||
|
@ -1023,7 +1023,7 @@ def test_sql_criteria_fts():
|
|||
|
||||
# check unaccent
|
||||
user = sql.SqlUser()
|
||||
user.name = force_str(u'Frédéric')
|
||||
user.name = force_str('Frédéric')
|
||||
user.store()
|
||||
t.user_id = user.id
|
||||
t.store()
|
||||
|
|
|
@ -388,7 +388,7 @@ def test_items():
|
|||
test = Foobar()
|
||||
test.store()
|
||||
|
||||
assert sorted([(int(x), int(y.id)) for (x, y) in Foobar.items()]) == list(zip(range(1, 51), range(1, 51)))
|
||||
assert sorted((int(x), int(y.id)) for (x, y) in Foobar.items()) == list(zip(range(1, 51), range(1, 51)))
|
||||
|
||||
|
||||
def test_reversed_order():
|
||||
|
@ -439,8 +439,8 @@ def test_concurrent_hashed_indexes():
|
|||
|
||||
assert Foobar.count() == 100
|
||||
for i in range(10):
|
||||
manual_selection = set([x.id for x in Foobar.select() if x.dict_value == {'plop': i}])
|
||||
index_selection = set([x.id for x in Foobar.get_with_indexed_value('dict_value', i)])
|
||||
manual_selection = {x.id for x in Foobar.select() if x.dict_value == {'plop': i}}
|
||||
index_selection = {x.id for x in Foobar.get_with_indexed_value('dict_value', i)}
|
||||
assert manual_selection == index_selection
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import string
|
||||
|
@ -1190,8 +1188,7 @@ def test_convert_as_list():
|
|||
assert tmpl.render({'foo': ['foo']}) == 'foo'
|
||||
|
||||
def list_generator():
|
||||
for i in range(5):
|
||||
yield i
|
||||
yield from range(5)
|
||||
|
||||
assert tmpl.render({'foo': list_generator}) == '0'
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from django.utils.encoding import force_bytes
|
||||
from webtest import Upload
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import shutil
|
||||
|
@ -147,7 +145,7 @@ def test_table_list_rows():
|
|||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'])
|
||||
form = MockHtmlForm(widget)
|
||||
mock_form_submission(req, widget, {'test$element0$col0': 'bar', 'test$element1$col1': 'foo'})
|
||||
assert widget.parse() == [[u'bar', None, None], [None, u'foo', None]]
|
||||
assert widget.parse() == [['bar', None, None], [None, 'foo', None]]
|
||||
|
||||
|
||||
def test_table_list_rows_add_row():
|
||||
|
@ -207,7 +205,7 @@ def test_table_widget():
|
|||
assert 'value="1"' in form.as_html
|
||||
|
||||
mock_form_submission(req, widget, {'test$c-0-0': 'X', 'test$c-0-1': 'Y'})
|
||||
assert widget.parse() == [[u'X', u'Y', None], [u'1', None, None]]
|
||||
assert widget.parse() == [['X', 'Y', None], ['1', None, None]]
|
||||
|
||||
|
||||
def test_passwordentry_widget_success():
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import io
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import shutil
|
|||
import time
|
||||
import urllib.parse
|
||||
import zipfile
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
try:
|
||||
|
@ -146,12 +146,12 @@ def test_get_json_export_dict(pub):
|
|||
|
||||
workflow.roles['_other'] = 'Other Function'
|
||||
root = workflow.get_json_export_dict()
|
||||
assert set(root.keys()) >= set(['statuses', 'name', 'functions'])
|
||||
assert set(root.keys()) >= {'statuses', 'name', 'functions'}
|
||||
|
||||
assert root['name'] == 'wf'
|
||||
assert len(root['statuses']) == 2
|
||||
assert set(st['id'] for st in root['statuses']) == set(['st1', 'st2'])
|
||||
assert all(set(status.keys()) >= set(['id', 'name', 'forced_endpoint']) for status in root['statuses'])
|
||||
assert {st['id'] for st in root['statuses']} == {'st1', 'st2'}
|
||||
assert all(set(status.keys()) >= {'id', 'name', 'forced_endpoint'} for status in root['statuses'])
|
||||
assert root['statuses'][0]['id'] == 'st1'
|
||||
assert root['statuses'][0]['name'] == 'Status1'
|
||||
assert root['statuses'][0]['forced_endpoint'] is False
|
||||
|
@ -2212,7 +2212,7 @@ def test_webservice_call(http_requests, pub):
|
|||
item.perform(formdata)
|
||||
assert http_requests.get_last('method') == 'GET'
|
||||
qs = urllib.parse.parse_qs(http_requests.get_last('url').split('?')[1])
|
||||
assert set(qs.keys()) == set(['in_url', 'str', 'one', 'evalme', 'django', 'ezt'])
|
||||
assert set(qs.keys()) == {'in_url', 'str', 'one', 'evalme', 'django', 'ezt'}
|
||||
assert qs['in_url'] == ['1', '2']
|
||||
assert qs['one'] == ['1']
|
||||
assert qs['evalme'] == [formdata.get_display_id()]
|
||||
|
@ -3433,7 +3433,7 @@ def test_workflow_roles(pub, emails):
|
|||
get_response().process_after_jobs()
|
||||
assert emails.count() == 1
|
||||
assert emails.get('Foobar')
|
||||
assert set(emails.get('Foobar')['email_rcpt']) == set(['foo@localhost', 'bar@localhost', 'baz@localhost'])
|
||||
assert set(emails.get('Foobar')['email_rcpt']) == {'foo@localhost', 'bar@localhost', 'baz@localhost'}
|
||||
|
||||
workflow.roles['_slug-with-dash'] = 'Dashed Function'
|
||||
workflow.store()
|
||||
|
@ -5720,8 +5720,8 @@ def test_workflow_action_condition(two_pubs):
|
|||
formdata2.just_created()
|
||||
formdata2.store()
|
||||
|
||||
assert formdata1.get_actions_roles() == set([role.id])
|
||||
assert formdata2.get_actions_roles() == set([role.id])
|
||||
assert formdata1.get_actions_roles() == {role.id}
|
||||
assert formdata2.get_actions_roles() == {role.id}
|
||||
|
||||
assert len(FormDef.get(formdef.id).data_class().get_actionable_ids([role.id])) == 2
|
||||
|
||||
|
@ -5729,7 +5729,7 @@ def test_workflow_action_condition(two_pubs):
|
|||
workflow.store()
|
||||
|
||||
with two_pubs.substitutions.temporary_feed(formdata1):
|
||||
assert FormDef.get(formdef.id).data_class().get(formdata1.id).get_actions_roles() == set([role.id])
|
||||
assert FormDef.get(formdef.id).data_class().get(formdata1.id).get_actions_roles() == {role.id}
|
||||
with two_pubs.substitutions.temporary_feed(formdata2):
|
||||
assert FormDef.get(formdef.id).data_class().get(formdata2.id).get_actions_roles() == set()
|
||||
|
||||
|
@ -5827,12 +5827,10 @@ def test_notifications(pub, http_requests):
|
|||
item.to = ['_receiver']
|
||||
item.perform(formdata)
|
||||
assert http_requests.count() == 2
|
||||
assert set(x['url'] for x in http_requests.requests) == set(
|
||||
[
|
||||
'https://portal/api/notification/add/?NameID=xxy1',
|
||||
'https://portal/api/notification/add/?NameID=xxy2',
|
||||
]
|
||||
)
|
||||
assert {x['url'] for x in http_requests.requests} == {
|
||||
'https://portal/api/notification/add/?NameID=xxy1',
|
||||
'https://portal/api/notification/add/?NameID=xxy2',
|
||||
}
|
||||
|
||||
# test inactive users are ignored
|
||||
user2.is_active = False
|
||||
|
@ -5840,18 +5838,16 @@ def test_notifications(pub, http_requests):
|
|||
http_requests.empty()
|
||||
item.perform(formdata)
|
||||
assert http_requests.count() == 1
|
||||
assert set(x['url'] for x in http_requests.requests) == set(
|
||||
['https://portal/api/notification/add/?NameID=xxy1']
|
||||
)
|
||||
assert {x['url'] for x in http_requests.requests} == {'https://portal/api/notification/add/?NameID=xxy1'}
|
||||
|
||||
# check notifications are sent to interco portal if it exists
|
||||
pub.site_options.set('variables', '_interco_portal_url', 'https://interco-portal/')
|
||||
http_requests.empty()
|
||||
item.perform(formdata)
|
||||
assert http_requests.count() == 1
|
||||
assert set(x['url'] for x in http_requests.requests) == set(
|
||||
['https://interco-portal/api/notification/add/?NameID=xxy1']
|
||||
)
|
||||
assert {x['url'] for x in http_requests.requests} == {
|
||||
'https://interco-portal/api/notification/add/?NameID=xxy1'
|
||||
}
|
||||
|
||||
|
||||
def test_workflow_field_migration(pub):
|
||||
|
|
|
@ -404,7 +404,7 @@ class HttpRequestsMocking:
|
|||
try:
|
||||
with open(url[7:]) as fd:
|
||||
status, data = 200, fd.read()
|
||||
except IOError:
|
||||
except OSError:
|
||||
status = 404
|
||||
|
||||
data = force_bytes(data)
|
||||
|
|
|
@ -344,13 +344,13 @@ class NamedDataSourcePage(Directory):
|
|||
if data_source.get('type') == 'geojson':
|
||||
additional_keys.add('geometry_coordinates')
|
||||
additional_keys.add('geometry_type')
|
||||
additional_keys |= set('properties_%s' % k for k in item.get('properties', {}).keys())
|
||||
additional_keys |= {'properties_%s' % k for k in item.get('properties', {}).keys()}
|
||||
else:
|
||||
additional_keys |= set(item.keys())
|
||||
if len(items) > 10:
|
||||
r += htmltext('<li>...</li>')
|
||||
r += htmltext('</ul>')
|
||||
additional_keys -= set(['id', 'text', 'properties_id', 'properties_text'])
|
||||
additional_keys -= {'id', 'text', 'properties_id', 'properties_text'}
|
||||
if additional_keys:
|
||||
r += htmltext('<p>%s %s</p>') % (
|
||||
_('Additional keys are available:'),
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2010 Entr'ouvert
|
||||
|
@ -319,7 +318,7 @@ class FieldsDirectory(Directory):
|
|||
r += htmltext('<p class="details">')
|
||||
if field.type != 'page':
|
||||
r += htmltext('<span class="type">%s</span>') % _(type_label)
|
||||
if hasattr(field, str('required')):
|
||||
if hasattr(field, 'required'):
|
||||
if field.required:
|
||||
required = ''
|
||||
else:
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2010 Entr'ouvert
|
||||
|
@ -65,7 +64,7 @@ from .logged_errors import LoggedErrorsDirectory
|
|||
|
||||
|
||||
def get_categories(category_class):
|
||||
t = sorted([(misc.simplify(x.name), x.id, x.name, x.id) for x in category_class.select()])
|
||||
t = sorted((misc.simplify(x.name), x.id, x.name, x.id) for x in category_class.select())
|
||||
return [x[1:] for x in t]
|
||||
|
||||
|
||||
|
@ -82,7 +81,7 @@ class FormDefUI:
|
|||
@classmethod
|
||||
def get_workflows(cls, condition=lambda x: True):
|
||||
default_workflow = cls.formdef_class.get_default_workflow()
|
||||
t = sorted([(misc.simplify(x.name), x.id, x.name, x.id) for x in Workflow.select() if condition(x)])
|
||||
t = sorted((misc.simplify(x.name), x.id, x.name, x.id) for x in Workflow.select() if condition(x))
|
||||
return [(None, default_workflow.name, '')] + [x[1:] for x in t]
|
||||
|
||||
def new_form_ui(self):
|
||||
|
@ -173,11 +172,11 @@ class AdminFieldsDirectory(FieldsDirectory):
|
|||
def index_bottom(self):
|
||||
if self.objectdef.is_readonly():
|
||||
return
|
||||
if hasattr(self.objectdef, str('disabled')) and self.objectdef.disabled:
|
||||
if hasattr(self.objectdef, 'disabled') and self.objectdef.disabled:
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<div class="warningnotice">')
|
||||
r += _('This form is currently disabled.')
|
||||
if hasattr(self.objectdef, str('disabled_redirection')) and self.objectdef.disabled_redirection:
|
||||
if hasattr(self.objectdef, 'disabled_redirection') and self.objectdef.disabled_redirection:
|
||||
r += htmltext(' (<a href="%s">') % self.objectdef.disabled_redirection
|
||||
r += _('redirection')
|
||||
r += htmltext('</a>)')
|
||||
|
@ -691,7 +690,7 @@ class FormDefPage(Directory):
|
|||
elif self.formdef.workflow_options:
|
||||
# there are no variables defined but there are some values
|
||||
# in workflow_options, this is probably the legacy stuff.
|
||||
if any((x for x in self.formdef.workflow_options if '*' in x)):
|
||||
if any(x for x in self.formdef.workflow_options if '*' in x):
|
||||
r += self.add_option_line('workflow-options', _('Options'), '')
|
||||
|
||||
if self.formdef.workflow.roles:
|
||||
|
@ -1626,7 +1625,7 @@ class FormDefPage(Directory):
|
|||
if not had_options:
|
||||
form.widgets.append(HtmlWidget('<h3>%s</h3>' % status.name))
|
||||
had_options = True
|
||||
label = getattr(item, str('label'), None) or _(item.description)
|
||||
label = getattr(item, 'label', None) or _(item.description)
|
||||
form.widgets.append(HtmlWidget('<h4>%s</h4>' % label))
|
||||
item.add_parameters_widgets(form, parameters, prefix=prefix, formdef=self.formdef)
|
||||
form.add_submit('submit', _('Submit'))
|
||||
|
|
|
@ -347,7 +347,7 @@ class FileTypesDirectory(Directory):
|
|||
l = []
|
||||
ellipsis = '...'
|
||||
for mimetype in types:
|
||||
if sum([len(x) for x in l]) > 80:
|
||||
if sum(len(x) for x in l) > 80:
|
||||
# string got too long already, stop this now and we'll get an
|
||||
# ellipsis
|
||||
break
|
||||
|
@ -832,8 +832,8 @@ class SettingsDirectory(QommonSettingsDirectory):
|
|||
themes = template.get_themes()
|
||||
if str(request.form['theme']) in themes:
|
||||
branding_cfg = get_cfg('branding', {})
|
||||
branding_cfg[str('theme')] = str(request.form['theme'])
|
||||
get_publisher().cfg[str('branding')] = branding_cfg
|
||||
branding_cfg['theme'] = str(request.form['theme'])
|
||||
get_publisher().cfg['branding'] = branding_cfg
|
||||
get_publisher().write_cfg()
|
||||
return redirect('.')
|
||||
|
||||
|
@ -1307,7 +1307,7 @@ class SettingsDirectory(QommonSettingsDirectory):
|
|||
try:
|
||||
get_publisher().initialize_sql()
|
||||
except Exception as e:
|
||||
postgresql_cfg[str('postgresql')] = postgresql_cfg
|
||||
postgresql_cfg['postgresql'] = postgresql_cfg
|
||||
form.set_error('database', str(e))
|
||||
else:
|
||||
return redirect('.')
|
||||
|
|
|
@ -158,7 +158,7 @@ class UserPage(Directory):
|
|||
if formdef:
|
||||
if self.user.form_data:
|
||||
for field in formdef.fields:
|
||||
if not hasattr(field, str('get_view_value')):
|
||||
if not hasattr(field, 'get_view_value'):
|
||||
continue
|
||||
value = self.user.form_data.get(field.id)
|
||||
r += htmltext('<div class="title">')
|
||||
|
@ -299,7 +299,7 @@ class UserPage(Directory):
|
|||
else:
|
||||
ident_methods = get_cfg('identification', {}).get('methods', [])
|
||||
for klass in [x for x in ident.get_method_classes() if x.key in ident_methods]:
|
||||
if hasattr(klass, str('delete')):
|
||||
if hasattr(klass, 'delete'):
|
||||
klass().delete(self.user)
|
||||
self.user.remove_self()
|
||||
return redirect('..')
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2010 Entr'ouvert
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2010 Entr'ouvert
|
||||
|
@ -644,7 +643,7 @@ class WorkflowStatusPage(Directory):
|
|||
for formdef in FormDef.select():
|
||||
if formdef.workflow_id != self.workflow.id:
|
||||
continue
|
||||
if any(formdef.data_class().get_with_indexed_value(str('status'), 'wf-%s' % self.status.id)):
|
||||
if any(formdef.data_class().get_with_indexed_value('status', 'wf-%s' % self.status.id)):
|
||||
return redirect('reassign')
|
||||
del self.workflow.possible_status[self.workflow.possible_status.index(self.status)]
|
||||
self.workflow.store(comment=_('Deletion of status %s') % self.status.name)
|
||||
|
@ -708,9 +707,7 @@ class WorkflowStatusPage(Directory):
|
|||
for formdef in FormDef.select():
|
||||
if formdef.workflow_id != self.workflow.id:
|
||||
continue
|
||||
items = list(
|
||||
formdef.data_class().get_with_indexed_value(str('status'), 'wf-%s' % self.status.id)
|
||||
)
|
||||
items = list(formdef.data_class().get_with_indexed_value('status', 'wf-%s' % self.status.id))
|
||||
r += htmltext('<li>%s: %s</li>') % (formdef.name, _('%s items') % len(items))
|
||||
r += htmltext('</ul>')
|
||||
|
||||
|
@ -725,12 +722,12 @@ class WorkflowStatusPage(Directory):
|
|||
def submit_reassign(self, form):
|
||||
nb_forms = 0
|
||||
action = form.get_widget('action').parse()
|
||||
if action.startswith(str('reassign-')):
|
||||
if action.startswith('reassign-'):
|
||||
new_status = 'wf-%s' % str(action)[9:]
|
||||
for formdef in FormDef.select():
|
||||
if formdef.workflow_id != self.workflow.id:
|
||||
continue
|
||||
for item in formdef.data_class().get_with_indexed_value(str('status'), 'wf-%s' % self.status.id):
|
||||
for item in formdef.data_class().get_with_indexed_value('status', 'wf-%s' % self.status.id):
|
||||
nb_forms += 1
|
||||
if action == 'remove':
|
||||
item.remove_self()
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2019 Entr'ouvert
|
||||
|
|
|
@ -267,7 +267,7 @@ class UserViewDirectory(Directory):
|
|||
formdef = UserFieldsFormDef()
|
||||
r += htmltext('<div class="form">')
|
||||
for field in formdef.get_all_fields():
|
||||
if not hasattr(field, str('get_view_value')):
|
||||
if not hasattr(field, 'get_view_value'):
|
||||
continue
|
||||
value = self.user.form_data.get(field.id)
|
||||
if not value:
|
||||
|
@ -594,7 +594,7 @@ class ManagementDirectory(Directory):
|
|||
formdatas = sql.AnyFormData.select([Equal('id_display', query)])
|
||||
if formdatas:
|
||||
return redirect(formdatas[0].get_url(backoffice=True))
|
||||
if any((x for x in FormDef.select(lightweight=True) if x.enable_tracking_codes)):
|
||||
if any(x for x in FormDef.select(lightweight=True) if x.enable_tracking_codes):
|
||||
try:
|
||||
tracking_code = get_publisher().tracking_code_class.get(query)
|
||||
formdata = tracking_code.formdata
|
||||
|
@ -802,7 +802,7 @@ class ManagementDirectory(Directory):
|
|||
category_formdefs_ids = [x.id for x in category_formdefs]
|
||||
if not category_formdefs:
|
||||
return
|
||||
cat_counts = dict([(x, y) for x, y in counts.items() if x in category_formdefs_ids])
|
||||
cat_counts = {x: y for x, y in counts.items() if x in category_formdefs_ids}
|
||||
if sum(cat_counts.values()) == 0:
|
||||
return
|
||||
r += htmltext('<div class="bo-block">')
|
||||
|
@ -1645,7 +1645,7 @@ class FormPage(Directory):
|
|||
|
||||
seen_parents = set()
|
||||
for field in sorted(self.get_formdef_fields(), key=get_column_position):
|
||||
if not hasattr(field, str('get_view_value')):
|
||||
if not hasattr(field, 'get_view_value'):
|
||||
continue
|
||||
classnames = ''
|
||||
attrs = ''
|
||||
|
@ -2981,10 +2981,8 @@ class FormBackOfficeStatusPage(FormStatusPage):
|
|||
)
|
||||
|
||||
if not formdata.is_draft() and (
|
||||
(
|
||||
get_publisher().get_backoffice_root().is_accessible('forms')
|
||||
or get_publisher().get_backoffice_root().is_accessible('workflows')
|
||||
)
|
||||
get_publisher().get_backoffice_root().is_accessible('forms')
|
||||
or get_publisher().get_backoffice_root().is_accessible('workflows')
|
||||
):
|
||||
r += htmltext('<div class="extra-context">')
|
||||
r += htmltext('<p><a href="%sinspect">' % formdata.get_url(backoffice=True))
|
||||
|
@ -3788,7 +3786,7 @@ class MassActionAfterJob(AfterJob):
|
|||
return
|
||||
|
||||
formdatas = formdef.data_class().get_ids(item_ids, order_by='receipt_time')
|
||||
self.completion_status = '{}/{}'.format(0, len(formdatas))
|
||||
self.completion_status = f'0/{len(formdatas)}'
|
||||
self.store()
|
||||
|
||||
publisher = get_publisher()
|
||||
|
@ -3815,7 +3813,7 @@ class MassActionAfterJob(AfterJob):
|
|||
else:
|
||||
# global action
|
||||
formdata.perform_global_action(action['action'].id, user)
|
||||
self.completion_status = '{}/{}'.format(i + 1, len(formdatas))
|
||||
self.completion_status = f'{i + 1}/{len(formdatas)}'
|
||||
self.store()
|
||||
|
||||
def done_action_url(self):
|
||||
|
|
|
@ -250,7 +250,7 @@ class RootDirectory(BackofficeRootDirectory):
|
|||
if len(item) == 2:
|
||||
item = list(item) + [{}]
|
||||
k, v, options = item
|
||||
slug = k.strip(str('/'))
|
||||
slug = k.strip('/')
|
||||
if not slug:
|
||||
continue
|
||||
display_function = options.get('check_display_function')
|
||||
|
|
|
@ -188,7 +188,7 @@ class CmdCheckHobos(Command):
|
|||
try:
|
||||
with open(os.path.join(self.THEMES_DIRECTORY, theme_module, 'themes.json')) as fd:
|
||||
themes_json = json.load(fd)
|
||||
except IOError:
|
||||
except OSError:
|
||||
continue
|
||||
if not isinstance(themes_json, dict): # compat
|
||||
themes_json = {'themes': themes_json}
|
||||
|
|
|
@ -82,8 +82,7 @@ class Command(TenantCommand):
|
|||
def get_rows(args):
|
||||
for arg in args:
|
||||
with open(arg) as fd:
|
||||
for row in json.load(fd):
|
||||
yield row
|
||||
yield from json.load(fd)
|
||||
|
||||
|
||||
def get_status_ids_accepting_trigger(workflow, trigger):
|
||||
|
|
|
@ -108,7 +108,7 @@ class CustomView(StorableObject):
|
|||
]
|
||||
if self.visibility == 'owner':
|
||||
clauses.append(Equal('user_id', self.user_id))
|
||||
existing_slugs = set([x.slug for x in self.select(clauses)])
|
||||
existing_slugs = {x.slug for x in self.select(clauses)}
|
||||
base_slug = simplify(self.title)
|
||||
if base_slug.startswith('user-'):
|
||||
# prevent a slug starting with user- as it's used in URLs
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2010 Entr'ouvert
|
||||
|
@ -1757,7 +1756,7 @@ class MapOptionsMixin:
|
|||
)
|
||||
# noqa pylint: disable=too-many-boolean-expressions
|
||||
if (initial_zoom and min_zoom and int(initial_zoom) < int(min_zoom)) or (
|
||||
(initial_zoom and max_zoom and int(initial_zoom) > int(max_zoom))
|
||||
initial_zoom and max_zoom and int(initial_zoom) > int(max_zoom)
|
||||
):
|
||||
form.get_widget('initial_zoom').set_error(
|
||||
_('Initial zoom level must be between minimal and maximal zoom levels.')
|
||||
|
@ -1918,7 +1917,7 @@ class ItemField(WidgetField, MapOptionsMixin, ItemFieldMixin):
|
|||
first_items = [x for x in kwargs['options'][:3]]
|
||||
else:
|
||||
first_items = [x[1] for x in kwargs['options'][:3]]
|
||||
length_first_items = sum([len(x) for x in first_items])
|
||||
length_first_items = sum(len(x) for x in first_items)
|
||||
# display radio buttons on a single line if there's just a few
|
||||
# short options.
|
||||
# TODO: absence/presence of delimitor should be an option
|
||||
|
@ -2040,7 +2039,7 @@ class ItemField(WidgetField, MapOptionsMixin, ItemFieldMixin):
|
|||
return
|
||||
|
||||
value = data_source.get_structured_value(data.get(field_id))
|
||||
if value is None or set(value.keys()) == set(['id', 'text']):
|
||||
if value is None or set(value.keys()) == {'id', 'text'}:
|
||||
return
|
||||
return value
|
||||
|
||||
|
@ -2461,7 +2460,7 @@ class PageCondition(Condition):
|
|||
form_live_data = {}
|
||||
if dict_vars is not None:
|
||||
live_data = get_dict_with_varnames(formdef.fields, dict_vars)
|
||||
form_live_data = dict(('form_' + x, y) for x, y in live_data.items())
|
||||
form_live_data = {'form_' + x: y for x, y in live_data.items()}
|
||||
|
||||
# 1) feed the form_var_* variables in the global substitution system,
|
||||
# they will shadow formdata context variables with their new "live"
|
||||
|
@ -3040,7 +3039,7 @@ class MapField(WidgetField, MapOptionsMixin):
|
|||
|
||||
def convert_value_from_str(self, value):
|
||||
try:
|
||||
dummy, dummy = [float(x) for x in value.split(';')]
|
||||
dummy, dummy = (float(x) for x in value.split(';'))
|
||||
except (AttributeError, ValueError):
|
||||
return None
|
||||
return value
|
||||
|
|
|
@ -692,8 +692,8 @@ class FormData(StorableObject):
|
|||
return set()
|
||||
if isinstance(role_id, list):
|
||||
return set(role_id)
|
||||
return set([str(role_id)])
|
||||
return set([str(role_name)])
|
||||
return {str(role_id)}
|
||||
return {str(role_name)}
|
||||
|
||||
def get_handling_role_id(self):
|
||||
# TODO: look at current status and return the role(s) actually
|
||||
|
@ -890,9 +890,9 @@ class FormData(StorableObject):
|
|||
d.update(item.get_substitution_variables(self))
|
||||
|
||||
# Add variables from evolution parts classes
|
||||
evolution_parts_classes = set(
|
||||
evolution_parts_classes = {
|
||||
part.__class__ for evolution in self.evolution or [] for part in evolution.parts or []
|
||||
)
|
||||
}
|
||||
for klass in evolution_parts_classes:
|
||||
if hasattr(klass, 'get_substitution_variables'):
|
||||
d.update(klass.get_substitution_variables(self))
|
||||
|
@ -1304,8 +1304,7 @@ class FormData(StorableObject):
|
|||
|
||||
def iter_evolution_parts(self):
|
||||
for evo in self.evolution or []:
|
||||
for part in evo.parts or []:
|
||||
yield part
|
||||
yield from evo.parts or []
|
||||
|
||||
def iter_target_datas(self, objectdef=None, object_type=None, status_item=None):
|
||||
# objectdef, object_type and status_item are provided when called from a workflow action
|
||||
|
|
|
@ -235,7 +235,7 @@ class FormDef(StorableObject):
|
|||
changed = True
|
||||
|
||||
if self.max_field_id is None and self.fields:
|
||||
self.max_field_id = max([lax_int(x.id) for x in self.fields])
|
||||
self.max_field_id = max(lax_int(x.id) for x in self.fields)
|
||||
changed = True
|
||||
|
||||
if isinstance(self.category_id, int):
|
||||
|
@ -257,7 +257,7 @@ class FormDef(StorableObject):
|
|||
workflow_roles_list = self.workflow_roles.items()
|
||||
for role_id in self.workflow_roles.values():
|
||||
if isinstance(role_id, int):
|
||||
self.workflow_roles = dict([(x, str(y)) for x, y in workflow_roles_list])
|
||||
self.workflow_roles = {x: str(y) for x, y in workflow_roles_list}
|
||||
changed = True
|
||||
break
|
||||
|
||||
|
@ -748,8 +748,7 @@ class FormDef(StorableObject):
|
|||
for field in fields:
|
||||
yield field
|
||||
if field.key == 'block':
|
||||
for subfield in field.block.fields:
|
||||
yield subfield
|
||||
yield from field.block.fields
|
||||
|
||||
for field in get_all_fields():
|
||||
if field.condition:
|
||||
|
@ -821,7 +820,7 @@ class FormDef(StorableObject):
|
|||
root['workflow'] = self.workflow.get_json_export_dict(include_id=include_id)
|
||||
|
||||
if self.max_field_id is None and self.fields:
|
||||
self.max_field_id = max([lax_int(x.id) for x in self.fields])
|
||||
self.max_field_id = max(lax_int(x.id) for x in self.fields)
|
||||
|
||||
more_attributes = []
|
||||
if self.max_field_id:
|
||||
|
@ -863,7 +862,7 @@ class FormDef(StorableObject):
|
|||
|
||||
def unicode2str(v):
|
||||
if isinstance(v, dict):
|
||||
return dict([(unicode2str(k), unicode2str(v)) for k, v in v.items()])
|
||||
return {unicode2str(k): unicode2str(v) for k, v in v.items()}
|
||||
elif isinstance(v, list):
|
||||
return [unicode2str(x) for x in v]
|
||||
elif isinstance(v, str):
|
||||
|
@ -925,7 +924,7 @@ class FormDef(StorableObject):
|
|||
formdef.fields.append(field_o)
|
||||
|
||||
if formdef.fields and not formdef.max_field_id:
|
||||
formdef.max_field_id = max([lax_int(x.id) for x in formdef.fields])
|
||||
formdef.max_field_id = max(lax_int(x.id) for x in formdef.fields)
|
||||
|
||||
if value.get('options'):
|
||||
formdef.workflow_options = value.get('options')
|
||||
|
@ -979,7 +978,7 @@ class FormDef(StorableObject):
|
|||
elem.attrib['workflow_id'] = str(self.workflow.id)
|
||||
|
||||
if self.max_field_id is None and self.fields:
|
||||
self.max_field_id = max([lax_int(x.id) for x in self.fields])
|
||||
self.max_field_id = max(lax_int(x.id) for x in self.fields)
|
||||
|
||||
if self.max_field_id:
|
||||
ET.SubElement(root, 'max_field_id').text = str(self.max_field_id)
|
||||
|
@ -1094,7 +1093,7 @@ class FormDef(StorableObject):
|
|||
|
||||
# fix max_field_id if necessary
|
||||
if formdef.max_field_id is not None:
|
||||
max_field_id = max([lax_int(x.id) for x in formdef.fields])
|
||||
max_field_id = max(lax_int(x.id) for x in formdef.fields)
|
||||
formdef.max_field_id = max(max_field_id, formdef.max_field_id)
|
||||
|
||||
# check if all field id are unique
|
||||
|
@ -1158,7 +1157,7 @@ class FormDef(StorableObject):
|
|||
if value is not None:
|
||||
formdef.max_field_id = int(value.text)
|
||||
else:
|
||||
formdef.max_field_id = max([lax_int(x.id) for x in formdef.fields])
|
||||
formdef.max_field_id = max(lax_int(x.id) for x in formdef.fields)
|
||||
|
||||
formdef.workflow_options = {}
|
||||
for option in tree.findall('options/option'):
|
||||
|
@ -1463,7 +1462,7 @@ class FormDef(StorableObject):
|
|||
if isinstance(role_id, list):
|
||||
role_ids = set(role_id)
|
||||
else:
|
||||
role_ids = set([role_id])
|
||||
role_ids = {role_id}
|
||||
if user_roles.intersection(role_ids):
|
||||
return True
|
||||
|
||||
|
@ -1491,7 +1490,7 @@ class FormDef(StorableObject):
|
|||
def ensure_role_are_strings(roles):
|
||||
# makes sure all roles are defined as strings, as different origins
|
||||
# (formdef, user, workflow status...) may define them differently.
|
||||
return set([str(x) for x in roles if x])
|
||||
return {str(x) for x in roles if x}
|
||||
|
||||
user_roles = ensure_role_are_strings(user_roles)
|
||||
|
||||
|
|
|
@ -312,7 +312,7 @@ class FormDefUI:
|
|||
r += htmltext('<td class="%s">' % css_class)
|
||||
else:
|
||||
r += htmltext('<td>')
|
||||
r += field_value.replace(str('[download]'), str('%sdownload' % link))
|
||||
r += field_value.replace('[download]', str('%sdownload' % link))
|
||||
r += htmltext('</td>')
|
||||
r += htmltext('</tr>\n')
|
||||
return r.getvalue()
|
||||
|
|
|
@ -235,7 +235,7 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
r += _('Your case is handled by:')
|
||||
r += htmltext('</p>')
|
||||
r += htmltext('<p id="receiver">')
|
||||
r += htmltext(handling_role.details.replace(str('\n'), str('<br />')))
|
||||
r += htmltext(handling_role.details.replace('\n', '<br />'))
|
||||
r += htmltext('</p>')
|
||||
return r.getvalue()
|
||||
|
||||
|
@ -378,7 +378,7 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
url += '#action-zone'
|
||||
response = get_response()
|
||||
response.set_status(303)
|
||||
response.headers[str('location')] = url
|
||||
response.headers['location'] = url
|
||||
response.content_type = 'text/plain'
|
||||
return "Your browser should redirect you"
|
||||
|
||||
|
@ -524,7 +524,7 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
else:
|
||||
r += htmltext('<div class="value">')
|
||||
s = f.get_view_value(value, summary=True, **value_details)
|
||||
s = s.replace(str('[download]'), str('%sdownload' % form_url))
|
||||
s = s.replace('[download]', str('%sdownload' % form_url))
|
||||
r += s
|
||||
r += htmltext('</div>')
|
||||
r += htmltext('</div>')
|
||||
|
@ -626,9 +626,7 @@ class FormStatusPage(Directory, FormTemplateMixin):
|
|||
if not locked:
|
||||
if (self.filled.get_status() and self.filled.get_status().backoffice_info_text) or (
|
||||
form
|
||||
and any(
|
||||
(getattr(button, 'backoffice_info_text', None) for button in form.get_submit_widgets())
|
||||
)
|
||||
and any(getattr(button, 'backoffice_info_text', None) for button in form.get_submit_widgets())
|
||||
):
|
||||
r += htmltext('<div class="backoffice-description bo-block">')
|
||||
if self.filled.get_status().backoffice_info_text:
|
||||
|
|
|
@ -256,7 +256,7 @@ class FormPage(Directory, FormTemplateMixin):
|
|||
if self.user:
|
||||
user_roles = set(self.user.get_roles())
|
||||
else:
|
||||
user_roles = set([])
|
||||
user_roles = set()
|
||||
other_roles = self.formdef.roles or []
|
||||
if self.formdef.workflow_roles:
|
||||
other_roles.extend(self.formdef.workflow_roles.values())
|
||||
|
@ -1676,7 +1676,7 @@ class RootDirectory(AccessControlled, Directory):
|
|||
return list_forms, advertised_forms
|
||||
|
||||
def _q_index(self):
|
||||
if get_request().get_header(str('Accept'), '') == 'application/json':
|
||||
if get_request().get_header('Accept', '') == 'application/json':
|
||||
return self.json()
|
||||
|
||||
if not self.category:
|
||||
|
@ -1719,7 +1719,7 @@ class RootDirectory(AccessControlled, Directory):
|
|||
|
||||
formdefs = [x for x in all_formdefs if (not x.is_disabled() or x.disabled_redirection)]
|
||||
|
||||
if not self.category and any((x for x in formdefs if x.enable_tracking_codes)):
|
||||
if not self.category and any(x for x in formdefs if x.enable_tracking_codes):
|
||||
r += htmltext('<div id="side">')
|
||||
r += htmltext('<div id="tracking-code">')
|
||||
r += htmltext('<h3>%s</h3>') % _('Tracking code')
|
||||
|
|
|
@ -111,7 +111,7 @@ class WcsPublisher(QommonPublisher):
|
|||
|
||||
@classmethod
|
||||
def register_cronjobs(cls):
|
||||
super(WcsPublisher, cls).register_cronjobs()
|
||||
super().register_cronjobs()
|
||||
# every hour: check for global action timeouts
|
||||
cls.register_cronjob(
|
||||
CronJob(cls.apply_global_action_timeouts, name='evaluate_global_action_timeouts', minutes=[0])
|
||||
|
|
|
@ -42,7 +42,7 @@ class LoggerDirectory(Directory):
|
|||
r = TemplateIO(html=False)
|
||||
request = get_request()
|
||||
logfile = str(request.get_field('logfile', get_publisher().APP_NAME + '.log'))
|
||||
if not logfile.startswith(str(get_publisher().APP_NAME + '.log')) or str('/') in str(logfile):
|
||||
if not logfile.startswith(str(get_publisher().APP_NAME + '.log')) or '/' in str(logfile):
|
||||
return error_page('logs/', _('Bad log file: %s') % logfile)
|
||||
logfilename = str(os.path.join(get_publisher().app_dir, logfile))
|
||||
|
||||
|
@ -112,7 +112,7 @@ class LoggerDirectory(Directory):
|
|||
if not userlabel:
|
||||
try:
|
||||
user = get_publisher().user_class.get(user_id)
|
||||
userlabel = htmltext(user.display_name.replace(str(' '), str(' ')))
|
||||
userlabel = htmltext(user.display_name.replace(' ', ' '))
|
||||
except KeyError:
|
||||
userlabel = _('Unknown')
|
||||
userlabels[user_id] = userlabel
|
||||
|
@ -139,9 +139,7 @@ class LoggerDirectory(Directory):
|
|||
r += htmltext('</ul>')
|
||||
|
||||
logfiles = [
|
||||
x
|
||||
for x in os.listdir(get_publisher().app_dir)
|
||||
if x.startswith(get_publisher().APP_NAME + str('.log'))
|
||||
x for x in os.listdir(get_publisher().app_dir) if x.startswith(get_publisher().APP_NAME + '.log')
|
||||
]
|
||||
if len(logfiles) > 1:
|
||||
options = []
|
||||
|
@ -175,7 +173,7 @@ class LoggerDirectory(Directory):
|
|||
def download(self):
|
||||
request = get_request()
|
||||
logfile = request.get_field('logfile', get_publisher().APP_NAME + '.log')
|
||||
if not logfile.startswith(get_publisher().APP_NAME + '.log') or str('/') in logfile:
|
||||
if not logfile.startswith(get_publisher().APP_NAME + '.log') or '/' in logfile:
|
||||
return error_page('logs/', _('Bad log file: %s') % logfile)
|
||||
logfilename = os.path.join(get_publisher().app_dir, logfile)
|
||||
response = get_response()
|
||||
|
|
|
@ -105,10 +105,10 @@ class SettingsDirectory(AccessControlled, Directory):
|
|||
title=_('Display Exceptions'),
|
||||
value=debug_cfg.get('display_exceptions', ''),
|
||||
options=[
|
||||
(str(''), _('No display')),
|
||||
(str('text'), _('Display as Text')),
|
||||
(str('text-in-html'), _('Display as Text in an HTML error page')),
|
||||
(str('html'), _('Display as HTML')),
|
||||
('', _('No display')),
|
||||
('text', _('Display as Text')),
|
||||
('text-in-html', _('Display as Text in an HTML error page')),
|
||||
('html', _('Display as HTML')),
|
||||
],
|
||||
)
|
||||
form.add(CheckboxWidget, 'logger', title=_('Logger'), value=debug_cfg.get('logger', True))
|
||||
|
|
|
@ -137,7 +137,7 @@ class Ctl:
|
|||
self.load_all_commands()
|
||||
print()
|
||||
|
||||
commands = sorted([(x.name, x.doc) for x in self.get_commands().values()])
|
||||
commands = sorted((x.name, x.doc) for x in self.get_commands().values())
|
||||
print('Available commands:')
|
||||
for name, description in commands:
|
||||
print(' %-15s %s' % (name, description))
|
||||
|
|
|
@ -355,7 +355,7 @@ def create_smtp_server(emails_cfg, smtp_timeout=None):
|
|||
except socket.timeout:
|
||||
get_logger().error('Failed to connect to SMTP server (timeout)')
|
||||
raise errors.EmailError('Failed to connect to SMTP server (timeout)')
|
||||
except socket.error:
|
||||
except OSError:
|
||||
# XXX: write message in a queue somewhere?
|
||||
get_logger().error('Failed to connect to SMTP server')
|
||||
raise errors.EmailError('Failed to connect to SMTP server')
|
||||
|
|
|
@ -43,7 +43,7 @@ except ImportError:
|
|||
|
||||
try:
|
||||
import DNS
|
||||
except (ImportError, IOError):
|
||||
except (ImportError, OSError):
|
||||
DNS = None
|
||||
|
||||
try:
|
||||
|
@ -2289,7 +2289,7 @@ class JsonpSingleSelectWidget(Widget):
|
|||
if Template.is_template_string(self.url):
|
||||
vars = get_publisher().substitutions.get_context_variables(mode='lazy')
|
||||
# skip variables that were not set (None)
|
||||
vars = dict((x, y) for x, y in vars.items() if y is not None)
|
||||
vars = {x: y for x, y in vars.items() if y is not None}
|
||||
url = misc.get_variadic_url(self.url, vars, encode_query=False)
|
||||
else:
|
||||
url = self.url
|
||||
|
@ -2322,7 +2322,7 @@ class AutocompleteStringWidget(WcsExtraStringWidget):
|
|||
if Template.is_template_string(self.url):
|
||||
vars = get_publisher().substitutions.get_context_variables(mode='lazy')
|
||||
# skip variables that were not set (None)
|
||||
vars = dict((x, y) for x, y in vars.items() if y is not None)
|
||||
vars = {x: y for x, y in vars.items() if y is not None}
|
||||
url = misc.get_variadic_url(self.url, vars, encode_query=False)
|
||||
else:
|
||||
url = self.url
|
||||
|
|
|
@ -170,9 +170,9 @@ class HTTPRequest(quixote.http_request.HTTPRequest):
|
|||
# remove characters that are not valid XML so it doesn't have to happen
|
||||
# down the chain.
|
||||
illegal_xml_chars = re.compile(r'[\x00-\x08\x0b\x0c\x0e-\x1f\ud800-\udfff\ufffe\uffff]')
|
||||
self.form = dict(
|
||||
(k, illegal_xml_chars.sub('', v) if isinstance(v, str) else v) for k, v in self.form.items()
|
||||
)
|
||||
self.form = {
|
||||
k: illegal_xml_chars.sub('', v) if isinstance(v, str) else v for k, v in self.form.items()
|
||||
}
|
||||
self.parsed = True
|
||||
|
||||
@property
|
||||
|
|
|
@ -60,7 +60,7 @@ def is_idp_managing_user_roles():
|
|||
|
||||
def get_file_content(filename):
|
||||
try:
|
||||
with open(filename, 'r') as fd:
|
||||
with open(filename) as fd:
|
||||
return fd.read()
|
||||
except Exception:
|
||||
return None
|
||||
|
@ -449,7 +449,7 @@ class AdminIDPDir(Directory):
|
|||
form.set_error('metadata_url', _('Failed to retrieve file'))
|
||||
else:
|
||||
s = rfd.read()
|
||||
metadata_pathname = tempfile.mkstemp(str('.metadata'))[1]
|
||||
metadata_pathname = tempfile.mkstemp('.metadata')[1]
|
||||
atomic_write(metadata_pathname, force_bytes(s))
|
||||
try:
|
||||
lasso.Provider(lasso.PROVIDER_ROLE_IDP, metadata_pathname, None, None)
|
||||
|
@ -476,7 +476,7 @@ class AdminIDPDir(Directory):
|
|||
form.set_error('publickey_url', _('Failed to retrieve file'))
|
||||
else:
|
||||
s = rfd.read()
|
||||
publickey_pathname = tempfile.mkstemp(str('.publickey'))[1]
|
||||
publickey_pathname = tempfile.mkstemp('.publickey')[1]
|
||||
atomic_write(publickey_pathname, force_bytes(s))
|
||||
|
||||
try:
|
||||
|
@ -619,7 +619,7 @@ class AdminIDPUI(Directory):
|
|||
with open(misc.get_abs_path(self.idp['metadata'])) as fd:
|
||||
metadata = fd.read()
|
||||
try:
|
||||
t = metadata.decode(str('utf8')).encode(get_publisher().site_charset)
|
||||
t = metadata.decode('utf8').encode(get_publisher().site_charset)
|
||||
except Exception:
|
||||
t = metadata
|
||||
r += htmltext(t)
|
||||
|
@ -1109,14 +1109,14 @@ class MethodAdminDirectory(Directory):
|
|||
if not lasso.WSF_SUPPORT:
|
||||
widget = form.get_widget('grab-user-with-wsf')
|
||||
widget.hint = _('Lasso version is too old for this support.')
|
||||
widget.attrs[str('disabled')] = str('disabled')
|
||||
widget.attrs['disabled'] = 'disabled'
|
||||
|
||||
form.add(
|
||||
SingleSelectWidget,
|
||||
'identity-creation',
|
||||
title=_('Identity Creation'),
|
||||
value=identities_cfg.get('identity-creation', 'admin'),
|
||||
options=[(str('admin'), _('Site Administrator')), (str('self'), _('Self-registration'))],
|
||||
options=[('admin', _('Site Administrator')), ('self', _('Self-registration'))],
|
||||
)
|
||||
|
||||
form.add(
|
||||
|
|
|
@ -150,7 +150,7 @@ def check_password(form, widget_name):
|
|||
)
|
||||
|
||||
if set_errors:
|
||||
form.set_error(widget_name, str(' ').join(set_errors))
|
||||
form.set_error(widget_name, ' '.join(set_errors))
|
||||
|
||||
|
||||
class TokenDirectory(Directory):
|
||||
|
@ -249,14 +249,14 @@ class MethodDirectory(Directory):
|
|||
else:
|
||||
register_url = get_publisher().get_root_url() + 'register/'
|
||||
r += TextsDirectory.get_html_text(
|
||||
str('password-account-link-to-register-page'), {'register_url': register_url}
|
||||
'password-account-link-to-register-page', {'register_url': register_url}
|
||||
)
|
||||
r += htmltext('</div>')
|
||||
|
||||
forgotten_url = get_publisher().get_root_url() + 'ident/password/forgotten'
|
||||
r += htmltext('<div id="forgotten">')
|
||||
r += htmltext('<h3>%s</h3>') % _('Lost Password?')
|
||||
r += TextsDirectory.get_html_text(str('password-forgotten-link')) % {'forgotten_url': forgotten_url}
|
||||
r += TextsDirectory.get_html_text('password-forgotten-link') % {'forgotten_url': forgotten_url}
|
||||
r += htmltext('</div>')
|
||||
r += htmltext('</div>') # .ident-content
|
||||
|
||||
|
@ -337,7 +337,7 @@ class MethodDirectory(Directory):
|
|||
template.html_top(_('Forgotten password'))
|
||||
r += htmltext('<div class="ident-content">')
|
||||
|
||||
r += TextsDirectory.get_html_text(str('password-forgotten-enter-username'))
|
||||
r += TextsDirectory.get_html_text('password-forgotten-enter-username')
|
||||
r += form.render()
|
||||
if not include_mode:
|
||||
r += htmltext('</div>')
|
||||
|
@ -383,7 +383,7 @@ class MethodDirectory(Directory):
|
|||
template.html_top(_('Forgotten Password'))
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<div class="ident-content">')
|
||||
r += TextsDirectory.get_html_text(str('password-forgotten-token-sent'))
|
||||
r += TextsDirectory.get_html_text('password-forgotten-token-sent')
|
||||
r += htmltext('</div>')
|
||||
return r.getvalue()
|
||||
|
||||
|
@ -507,7 +507,7 @@ class MethodDirectory(Directory):
|
|||
form = Form(enctype='multipart/form-data', use_tokens=False)
|
||||
|
||||
formdef = None
|
||||
if hasattr(get_publisher().user_class, str('get_formdef')):
|
||||
if hasattr(get_publisher().user_class, 'get_formdef'):
|
||||
formdef = get_publisher().user_class.get_formdef()
|
||||
if formdef:
|
||||
formdef.add_fields_to_form(form)
|
||||
|
@ -823,8 +823,8 @@ class MethodAdminDirectory(Directory):
|
|||
title=_('Identity Creation'),
|
||||
value=identities_cfg.get('creation', 'admin'),
|
||||
options=[
|
||||
(str('admin'), _('Site Administrator')),
|
||||
(str('self'), _('Self-registration')),
|
||||
('admin', _('Site Administrator')),
|
||||
('self', _('Self-registration')),
|
||||
],
|
||||
)
|
||||
form.add(
|
||||
|
|
|
@ -123,7 +123,7 @@ def get_lasso_server():
|
|||
def get_provider_label(provider):
|
||||
if not provider:
|
||||
return None
|
||||
if not hasattr(provider, str('getOrganization')):
|
||||
if not hasattr(provider, 'getOrganization'):
|
||||
return provider.providerId
|
||||
|
||||
organization = provider.getOrganization()
|
||||
|
@ -716,10 +716,10 @@ def get_thumbnail(filepath, content_type=None):
|
|||
# PIL can raise syntax error on broken PNG files
|
||||
# * File "PIL/PngImagePlugin.py", line 119, in read
|
||||
# * raise SyntaxError("broken PNG file (chunk %s)" % repr(cid))
|
||||
raise IOError
|
||||
raise OSError
|
||||
image_thumb_fp = io.BytesIO()
|
||||
image.save(image_thumb_fp, "PNG")
|
||||
except IOError:
|
||||
except OSError:
|
||||
# failed to create thumbnail.
|
||||
raise ThumbnailError()
|
||||
|
||||
|
@ -773,7 +773,7 @@ def validate_luhn(string_value, length=None):
|
|||
|
||||
|
||||
def is_ascii_digit(string_value):
|
||||
return string_value and all((x in '0123456789' for x in string_value))
|
||||
return string_value and all(x in '0123456789' for x in string_value)
|
||||
|
||||
|
||||
def validate_phone_fr(string_value):
|
||||
|
|
|
@ -74,7 +74,7 @@ class MyspaceDirectory(Directory):
|
|||
if user.form_data:
|
||||
r += htmltext('<ul>')
|
||||
for field in formdef.fields:
|
||||
if not hasattr(field, str('get_view_value')):
|
||||
if not hasattr(field, 'get_view_value'):
|
||||
continue
|
||||
value = user.form_data.get(field.id)
|
||||
r += htmltext('<li>')
|
||||
|
@ -183,7 +183,7 @@ class MyspaceDirectory(Directory):
|
|||
if form.is_submitted() and not form.has_errors():
|
||||
user = get_request().user
|
||||
try:
|
||||
account = PasswordAccount.get_on_index(user.id, str('user_id'))
|
||||
account = PasswordAccount.get_on_index(user.id, 'user_id')
|
||||
account.remove_self()
|
||||
except KeyError:
|
||||
pass
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# w.c.s. - web application for online forms
|
||||
# Copyright (C) 2005-2013 Entr'ouvert
|
||||
|
|
|
@ -32,7 +32,6 @@ import os
|
|||
import pickle
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
@ -304,7 +303,7 @@ class QommonPublisher(Publisher):
|
|||
|
||||
try:
|
||||
self.logger.log_internal_error(error_summary, plain_error_msg)
|
||||
except socket.error:
|
||||
except OSError:
|
||||
# wilr happen if there is no mail server available and exceptions
|
||||
# were configured to be mailed.
|
||||
pass
|
||||
|
|
|
@ -86,10 +86,10 @@ class Metadata:
|
|||
'''Return new or earlier version of PEM keys'''
|
||||
_dir = self.publisher.app_dir
|
||||
if not signing_pem_key and self.config.get('publickey'):
|
||||
with open(os.path.join(_dir, 'public-key.pem'), 'r') as fd:
|
||||
with open(os.path.join(_dir, 'public-key.pem')) as fd:
|
||||
signing_pem_key = fd.read()
|
||||
if not encryption_pem_key and self.config.get('encryption_publickey'):
|
||||
with open(os.path.join(_dir, 'encryption-public-key.pem'), 'r') as fd:
|
||||
with open(os.path.join(_dir, 'encryption-public-key.pem')) as fd:
|
||||
encryption_pem_key = fd.read()
|
||||
return (signing_pem_key, encryption_pem_key)
|
||||
|
||||
|
|
|
@ -405,8 +405,7 @@ class StorableObject:
|
|||
|
||||
@classmethod
|
||||
def select_iterator(cls, **kwargs):
|
||||
for obj in cls.select(**kwargs):
|
||||
yield obj
|
||||
yield from cls.select(**kwargs)
|
||||
|
||||
@classmethod
|
||||
def has_key(cls, id):
|
||||
|
@ -419,7 +418,7 @@ class StorableObject:
|
|||
try:
|
||||
with open(os.path.join(objects_dir, '.max_id')) as fd:
|
||||
max_id = int(fd.read())
|
||||
except (IOError, OSError, ValueError):
|
||||
except (OSError, ValueError):
|
||||
max_id = 0
|
||||
keys = cls.keys()
|
||||
if not keys:
|
||||
|
@ -511,7 +510,7 @@ class StorableObject:
|
|||
try:
|
||||
fd = open(force_bytes(filename, 'utf-8'), 'rb') # pylint: disable=consider-using-with
|
||||
o = cls.storage_load(fd, **kwargs)
|
||||
except IOError:
|
||||
except OSError:
|
||||
if ignore_errors:
|
||||
return None
|
||||
raise KeyError()
|
||||
|
@ -536,7 +535,7 @@ class StorableObject:
|
|||
fd.close()
|
||||
if cls._reset_class:
|
||||
o.__class__ = cls
|
||||
if any((isinstance(k, bytes) for k in o.__dict__)):
|
||||
if any(isinstance(k, bytes) for k in o.__dict__):
|
||||
pickle_2to3_conversion(o)
|
||||
if not ignore_migration:
|
||||
o.id = str(o.id) # makes sure 'id' is a string
|
||||
|
|
|
@ -189,7 +189,7 @@ def error_page(error_message, error_title=None, exception=None, continue_to=None
|
|||
if location_hint == 'backoffice':
|
||||
from .backoffice.menu import html_top as error_html_top
|
||||
|
||||
kwargs[str('section')] = None
|
||||
kwargs['section'] = None
|
||||
else:
|
||||
error_html_top = html_top
|
||||
|
||||
|
@ -336,7 +336,7 @@ def get_decorate_vars(body, response, generate_breadcrumb=True, **kwargs):
|
|||
if is_in_backoffice:
|
||||
path += response.breadcrumb[0][0]
|
||||
response.breadcrumb = response.breadcrumb[1:]
|
||||
total_len = sum([len(str(x[1])) for x in response.breadcrumb if x[1] is not None])
|
||||
total_len = sum(len(str(x[1])) for x in response.breadcrumb if x[1] is not None)
|
||||
for component, label in response.breadcrumb:
|
||||
if component.startswith('http:') or component.startswith('https:'):
|
||||
s.append('<a href="%s">%s</a>' % (component, label))
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#
|
||||
# Reduced to only support Django templates.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.template import Context, loader
|
||||
from django.template.base import TextNode
|
||||
|
|
|
@ -49,7 +49,7 @@ def _lock_file_non_blocking(file_):
|
|||
try:
|
||||
fcntl.flock(file_.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
return True
|
||||
except IOError as error:
|
||||
except OSError as error:
|
||||
if error.errno in [errno.EACCES, errno.EAGAIN]:
|
||||
return False
|
||||
else:
|
||||
|
@ -93,7 +93,7 @@ def _acquire_non_blocking(acquire, timeout, retry_period, path):
|
|||
if success:
|
||||
return
|
||||
elif timeout is not None and time.time() - start_time > timeout:
|
||||
raise LockError("Couldn't lock {0}".format(path))
|
||||
raise LockError(f"Couldn't lock {path}")
|
||||
else:
|
||||
time.sleep(retry_period)
|
||||
|
||||
|
|
|
@ -195,10 +195,8 @@ def logged_users_role():
|
|||
|
||||
def get_user_roles():
|
||||
t = sorted(
|
||||
[
|
||||
(misc.simplify(x.name), x.id, x.name, x.id)
|
||||
for x in get_publisher().role_class.select()
|
||||
if not x.is_internal()
|
||||
]
|
||||
(misc.simplify(x.name), x.id, x.name, x.id)
|
||||
for x in get_publisher().role_class.select()
|
||||
if not x.is_internal()
|
||||
)
|
||||
return [x[1:] for x in t]
|
||||
|
|
138
wcs/sql.py
138
wcs/sql.py
|
@ -539,37 +539,35 @@ def do_formdef_tables(formdef, conn=None, cur=None, rebuild_views=False, rebuild
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set(
|
||||
[
|
||||
'id',
|
||||
'user_id',
|
||||
'receipt_time',
|
||||
'status',
|
||||
'workflow_data',
|
||||
'id_display',
|
||||
'fts',
|
||||
'page_no',
|
||||
'anonymised',
|
||||
'workflow_roles',
|
||||
# workflow_roles_array is created from workflow_roles to be used in
|
||||
# get_ids_with_indexed_value
|
||||
'workflow_roles_array',
|
||||
'concerned_roles_array',
|
||||
'tracking_code',
|
||||
'actions_roles_array',
|
||||
'backoffice_submission',
|
||||
'submission_context',
|
||||
'submission_agent_id',
|
||||
'submission_channel',
|
||||
'criticality_level',
|
||||
'last_update_time',
|
||||
'digest',
|
||||
'user_label',
|
||||
'prefilling_data',
|
||||
]
|
||||
)
|
||||
needed_fields = {
|
||||
'id',
|
||||
'user_id',
|
||||
'receipt_time',
|
||||
'status',
|
||||
'workflow_data',
|
||||
'id_display',
|
||||
'fts',
|
||||
'page_no',
|
||||
'anonymised',
|
||||
'workflow_roles',
|
||||
# workflow_roles_array is created from workflow_roles to be used in
|
||||
# get_ids_with_indexed_value
|
||||
'workflow_roles_array',
|
||||
'concerned_roles_array',
|
||||
'tracking_code',
|
||||
'actions_roles_array',
|
||||
'backoffice_submission',
|
||||
'submission_context',
|
||||
'submission_agent_id',
|
||||
'submission_channel',
|
||||
'criticality_level',
|
||||
'last_update_time',
|
||||
'digest',
|
||||
'user_label',
|
||||
'prefilling_data',
|
||||
}
|
||||
|
||||
# migrations
|
||||
if 'fts' not in existing_fields:
|
||||
|
@ -665,7 +663,7 @@ def do_formdef_tables(formdef, conn=None, cur=None, rebuild_views=False, rebuild
|
|||
'''
|
||||
% table_name
|
||||
)
|
||||
evo_existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
evo_existing_fields = {x[0] for x in cur.fetchall()}
|
||||
if 'last_jump_datetime' not in evo_existing_fields:
|
||||
cur.execute('''ALTER TABLE %s_evolutions ADD COLUMN last_jump_datetime timestamp''' % table_name)
|
||||
|
||||
|
@ -703,7 +701,7 @@ def do_formdef_indexes(formdef, created, conn, cur, concurrently=False):
|
|||
AND tablename IN (%s, %s)''',
|
||||
(table_name, evolutions_table_name),
|
||||
)
|
||||
existing_indexes = set([x[0] for x in cur.fetchall()])
|
||||
existing_indexes = {x[0] for x in cur.fetchall()}
|
||||
|
||||
create_index = 'CREATE INDEX'
|
||||
if concurrently:
|
||||
|
@ -757,26 +755,24 @@ def do_user_table():
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set(
|
||||
[
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'roles',
|
||||
'is_admin',
|
||||
'anonymous',
|
||||
'name_identifiers',
|
||||
'verified_fields',
|
||||
'lasso_dump',
|
||||
'last_seen',
|
||||
'fts',
|
||||
'ascii_name',
|
||||
'deleted_timestamp',
|
||||
'is_active',
|
||||
]
|
||||
)
|
||||
needed_fields = {
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'roles',
|
||||
'is_admin',
|
||||
'anonymous',
|
||||
'name_identifiers',
|
||||
'verified_fields',
|
||||
'lasso_dump',
|
||||
'last_seen',
|
||||
'fts',
|
||||
'ascii_name',
|
||||
'deleted_timestamp',
|
||||
'is_active',
|
||||
}
|
||||
|
||||
from wcs.admin.settings import UserFieldsFormDef
|
||||
|
||||
|
@ -868,9 +864,9 @@ def do_role_table(concurrently=False):
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set([x[0] for x in Role._table_static_fields])
|
||||
needed_fields = {x[0] for x in Role._table_static_fields}
|
||||
|
||||
# delete obsolete fields
|
||||
for field in existing_fields - needed_fields:
|
||||
|
@ -911,9 +907,9 @@ def do_tracking_code_table():
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set(['id', 'formdef_id', 'formdata_id'])
|
||||
needed_fields = {'id', 'formdef_id', 'formdata_id'}
|
||||
|
||||
# delete obsolete fields
|
||||
for field in existing_fields - needed_fields:
|
||||
|
@ -948,11 +944,9 @@ def do_session_table():
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set(
|
||||
['id', 'session_data', 'name_identifier', 'visiting_objects_keys', 'last_update_time']
|
||||
)
|
||||
needed_fields = {'id', 'session_data', 'name_identifier', 'visiting_objects_keys', 'last_update_time'}
|
||||
|
||||
# migrations
|
||||
if 'last_update_time' not in existing_fields:
|
||||
|
@ -999,9 +993,9 @@ def do_custom_views_table():
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set([x[0] for x in CustomView._table_static_fields])
|
||||
needed_fields = {x[0] for x in CustomView._table_static_fields}
|
||||
|
||||
# migrations
|
||||
if 'is_default' not in existing_fields:
|
||||
|
@ -1044,9 +1038,9 @@ def do_snapshots_table():
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set([x[0] for x in Snapshot._table_static_fields])
|
||||
needed_fields = {x[0] for x in Snapshot._table_static_fields}
|
||||
|
||||
# delete obsolete fields
|
||||
for field in existing_fields - needed_fields:
|
||||
|
@ -1094,9 +1088,9 @@ def do_loggederrors_table(concurrently=False):
|
|||
AND table_name = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
|
||||
needed_fields = set([x[0] for x in LoggedError._table_static_fields])
|
||||
needed_fields = {x[0] for x in LoggedError._table_static_fields}
|
||||
|
||||
# delete obsolete fields
|
||||
for field in existing_fields - needed_fields:
|
||||
|
@ -1115,7 +1109,7 @@ def do_loggederrors_table(concurrently=False):
|
|||
AND tablename = %s''',
|
||||
(table_name,),
|
||||
)
|
||||
existing_indexes = set([x[0] for x in cur.fetchall()])
|
||||
existing_indexes = {x[0] for x in cur.fetchall()}
|
||||
|
||||
for attr in ('formdef_id', 'workflow_id'):
|
||||
if table_name + '_' + attr + '_idx' not in existing_indexes:
|
||||
|
@ -1903,9 +1897,9 @@ class SqlDataMixin(SqlMixin):
|
|||
@classmethod
|
||||
def _row2evo(cls, row, formdata):
|
||||
o = wcs.formdata.Evolution(formdata)
|
||||
o._sql_id, o.who, o.status, o.time, o.last_jump_datetime, o.comment = [
|
||||
o._sql_id, o.who, o.status, o.time, o.last_jump_datetime, o.comment = (
|
||||
str_encode(x) for x in tuple(row[:6])
|
||||
]
|
||||
)
|
||||
if o.time:
|
||||
o.time = o.time.timetuple()
|
||||
if row[6]:
|
||||
|
@ -1926,7 +1920,7 @@ class SqlDataMixin(SqlMixin):
|
|||
# statistics for example) it is sometimes useful to access .evolution
|
||||
# on a serie of formdata and in that case, it's more efficient to
|
||||
# optimize the process loading all evolutions in a single batch query.
|
||||
object_dict = dict([(x.id, x) for x in values if x.id and x._evolution is None])
|
||||
object_dict = {x.id: x for x in values if x.id and x._evolution is None}
|
||||
if not object_dict:
|
||||
return
|
||||
conn, cur = get_connection_and_cursor()
|
||||
|
@ -2466,7 +2460,7 @@ class SqlUser(SqlMixin, wcs.users.User):
|
|||
ascii_name, # XXX what's this ? pylint: disable=unused-variable
|
||||
o.deleted_timestamp,
|
||||
o.is_active,
|
||||
) = [str_encode(x) for x in tuple(row[:13])]
|
||||
) = (str_encode(x) for x in tuple(row[:13]))
|
||||
if o.last_seen:
|
||||
o.last_seen = time.mktime(o.last_seen.timetuple())
|
||||
if o.roles:
|
||||
|
@ -2813,7 +2807,7 @@ class TrackingCode(SqlMixin, wcs.tracking_code.TrackingCode):
|
|||
@classmethod
|
||||
def _row2ob(cls, row, **kwargs):
|
||||
o = cls()
|
||||
(o.id, o.formdef_id, o.formdata_id) = [str_encode(x) for x in tuple(row[:3])]
|
||||
(o.id, o.formdef_id, o.formdata_id) = (str_encode(x) for x in tuple(row[:3]))
|
||||
return o
|
||||
|
||||
@classmethod
|
||||
|
@ -3408,7 +3402,7 @@ def migrate_global_views(conn, cur):
|
|||
AND table_name = %s''',
|
||||
('wcs_all_forms',),
|
||||
)
|
||||
existing_fields = set([x[0] for x in cur.fetchall()])
|
||||
existing_fields = {x[0] for x in cur.fetchall()}
|
||||
if 'formdef_id' not in existing_fields:
|
||||
drop_global_views(conn, cur)
|
||||
do_global_views(conn, cur)
|
||||
|
|
|
@ -36,7 +36,7 @@ class TrackingCode(StorableObject):
|
|||
|
||||
@classmethod
|
||||
def get(cls, id, **kwargs):
|
||||
return super(TrackingCode, cls).get(id.upper(), **kwargs)
|
||||
return super().get(id.upper(), **kwargs)
|
||||
|
||||
@classmethod
|
||||
def get_new_id(cls, create=False):
|
||||
|
|
|
@ -252,8 +252,7 @@ class LazyFormDefObjectsManager:
|
|||
|
||||
def __iter__(self):
|
||||
self._populate_cache()
|
||||
for lazy_formdata in self._cached_resultset:
|
||||
yield lazy_formdata
|
||||
yield from self._cached_resultset
|
||||
|
||||
def __nonzero__(self):
|
||||
return any(self)
|
||||
|
@ -285,8 +284,7 @@ class LazyList:
|
|||
|
||||
def __iter__(self):
|
||||
self._populate_cache()
|
||||
for value in self._cached_resultset:
|
||||
yield value
|
||||
yield from self._cached_resultset
|
||||
|
||||
def __nonzero__(self):
|
||||
return any(self)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue