0005-misc-fix-unused-variable-pylint-error-56288.patch
combo/apps/assets/api_views.py | ||
---|---|---|
52 | 52 |
return Response(response, status.HTTP_400_BAD_REQUEST) |
53 | 53 |
data = serializer.validated_data |
54 | 54 | |
55 |
asset, created = Asset.objects.get_or_create(key=key)
|
|
55 |
asset, dummy = Asset.objects.get_or_create(key=key)
|
|
56 | 56 |
asset.asset = File(BytesIO(data['asset']['content']), name=data['asset'].get('filename')) |
57 | 57 |
asset.save() |
58 | 58 |
response = {'err': 0} |
combo/apps/assets/models.py | ||
---|---|---|
53 | 53 |
@classmethod |
54 | 54 |
def load_serialized_object(cls, json_asset): |
55 | 55 |
json_asset['model'] = 'assets.asset' |
56 |
asset, created = Asset.objects.get_or_create(key=json_asset['fields']['key'])
|
|
56 |
asset, dummy = Asset.objects.get_or_create(key=json_asset['fields']['key'])
|
|
57 | 57 |
json_asset['pk'] = asset.id |
58 | 58 |
asset = next(serializers.deserialize('json', json.dumps([json_asset]), ignorenonexistent=True)) |
59 | 59 |
asset.save() |
combo/apps/assets/utils.py | ||
---|---|---|
26 | 26 | |
27 | 27 |
def clean_assets_files(): |
28 | 28 |
media_prefix = default_storage.path('') |
29 |
for basedir, dirnames, filenames in os.walk(media_prefix):
|
|
29 |
for basedir, dummy, filenames in os.walk(media_prefix):
|
|
30 | 30 |
for filename in filenames: |
31 | 31 |
os.remove('%s/%s' % (basedir, filename)) |
32 | 32 | |
... | ... | |
58 | 58 | |
59 | 59 |
def tar_assets_files(tar): |
60 | 60 |
media_prefix = default_storage.path('') |
61 |
for basedir, dirnames, filenames in os.walk(media_prefix):
|
|
61 |
for basedir, dummy, filenames in os.walk(media_prefix):
|
|
62 | 62 |
for filename in filenames: |
63 | 63 |
tar.add(os.path.join(basedir, filename), os.path.join(basedir, filename)[len(media_prefix) :]) |
64 | 64 |
export = {'assets': Asset.export_all_for_json()} |
combo/apps/assets/views.py | ||
---|---|---|
394 | 394 |
context = super().get_context_data(**kwargs) |
395 | 395 |
media_prefix = default_storage.path('') |
396 | 396 |
computed_size = 0 |
397 |
for basedir, dirnames, filenames in os.walk(media_prefix):
|
|
397 |
for basedir, dummy, filenames in os.walk(media_prefix):
|
|
398 | 398 |
for filename in filenames: |
399 | 399 |
computed_size += os.stat(os.path.join(basedir, filename)).st_size |
400 | 400 |
context['size'] = computed_size |
combo/apps/calendar/utils.py | ||
---|---|---|
67 | 67 | |
68 | 68 | |
69 | 69 |
def get_chrono_events(agenda_reference, synchronous): |
70 |
chrono_key, chrono_slug = agenda_reference.split(':')
|
|
70 |
dummy, chrono_slug = agenda_reference.split(':')
|
|
71 | 71 |
chrono = get_chrono_service() |
72 | 72 |
response = requests.get( |
73 | 73 |
'api/agenda/%s/datetimes/' % chrono_slug, |
combo/apps/dashboard/views.py | ||
---|---|---|
154 | 154 | |
155 | 155 | |
156 | 156 |
def dashboard_reorder_tiles(request, *args, **kwargs): |
157 |
dashboard = DashboardCell.objects.filter(page__snapshot__isnull=True)[0] |
|
158 | 157 |
new_order = request.GET['order'].split(',') |
159 | 158 |
tiles = {str(x.id): x for x in Tile.objects.filter(id__in=new_order)} |
160 | 159 |
for i, tile_id in enumerate(new_order): |
combo/apps/dataviz/forms.py | ||
---|---|---|
35 | 35 |
def __init__(self, *args, **kwargs): |
36 | 36 |
super().__init__(*args, **kwargs) |
37 | 37 |
available_charts = [] |
38 |
for site_key, site_dict in settings.KNOWN_SERVICES.get('bijoe').items():
|
|
38 |
for site_dict in settings.KNOWN_SERVICES.get('bijoe').values():
|
|
39 | 39 |
result = requests.get( |
40 | 40 |
'/visualization/json/', |
41 | 41 |
remote_service=site_dict, |
combo/apps/dataviz/utils.py | ||
---|---|---|
1 | 1 |
import django |
2 | 2 |
from django.conf import settings |
3 |
from django.utils import timezone |
|
4 | 3 | |
5 | 4 |
from combo.utils import requests |
6 | 5 | |
... | ... | |
12 | 11 |
return |
13 | 12 | |
14 | 13 |
results = [] |
15 |
start_update = timezone.now() |
|
16 | 14 |
for provider in settings.STATISTICS_PROVIDERS: |
17 | 15 |
if isinstance(provider, dict): |
18 | 16 |
url = provider['url'] |
combo/apps/dataviz/views.py | ||
---|---|---|
44 | 44 |
width=int(request.GET['width']) if request.GET.get('width') else None, |
45 | 45 |
height=int(request.GET['height']) if request.GET.get('height') else int(cell.height), |
46 | 46 |
) |
47 |
except UnsupportedDataSet as e:
|
|
47 |
except UnsupportedDataSet: |
|
48 | 48 |
error_text = _('Unsupported dataset.') |
49 | 49 |
except HTTPError as e: |
50 | 50 |
if e.response.status_code == 404: |
combo/apps/lingo/models.py | ||
---|---|---|
887 | 887 | |
888 | 888 |
def create_paid_invoice_basket_item(self, item_id, remote_item): |
889 | 889 |
subject = _('Invoice #%s') % remote_item.display_id |
890 |
basket_item, created = BasketItem.objects.get_or_create(
|
|
890 |
basket_item, dummy = BasketItem.objects.get_or_create(
|
|
891 | 891 |
remote_item_id=item_id, |
892 | 892 |
defaults=dict( |
893 | 893 |
user=self.user, |
combo/apps/maps/models.py | ||
---|---|---|
190 | 190 |
@classmethod |
191 | 191 |
def load_serialized_object(cls, json_layer): |
192 | 192 |
json_layer['model'] = 'maps.maplayer' |
193 |
layer, created = MapLayer.objects.get_or_create(slug=json_layer['fields']['slug'])
|
|
193 |
layer, dummy = MapLayer.objects.get_or_create(slug=json_layer['fields']['slug'])
|
|
194 | 194 |
json_layer['pk'] = layer.id |
195 | 195 |
layer = next(serializers.deserialize('json', json.dumps([json_layer]), ignorenonexistent=True)) |
196 | 196 |
layer.save() |
combo/apps/notifications/models.py | ||
---|---|---|
151 | 151 |
raise ValueError('id must be convertible to unicode', e) |
152 | 152 |
if not re.match(cls.ID_RE, id): |
153 | 153 |
raise ValueError('id must match regular expression %s' % cls.ID_RE) |
154 |
notification, created = Notification.objects.update_or_create(
|
|
154 |
notification, dummy = Notification.objects.update_or_create(
|
|
155 | 155 |
user=user, external_id=id, defaults=defaults |
156 | 156 |
) |
157 | 157 |
else: |
combo/apps/pwa/models.py | ||
---|---|---|
173 | 173 |
json_entry['model'] = 'pwa.pwanavigationentry' |
174 | 174 |
# deserialize once to get link_page by natural key |
175 | 175 |
fake_entry = next(serializers.deserialize('json', json.dumps([json_entry]), ignorenonexistent=True)) |
176 |
entry, created = cls.objects.get_or_create(
|
|
176 |
entry, dummy = cls.objects.get_or_create(
|
|
177 | 177 |
label=json_entry['fields']['label'], |
178 | 178 |
url=json_entry['fields']['url'], |
179 | 179 |
link_page=fake_entry.object.link_page, |
combo/apps/pwa/views.py | ||
---|---|---|
99 | 99 |
if subscription_data is None: |
100 | 100 |
PushSubscription.objects.filter(user=request.user).delete() |
101 | 101 |
else: |
102 |
subscription, created = PushSubscription.objects.get_or_create(
|
|
102 |
subscription, dummy = PushSubscription.objects.get_or_create(
|
|
103 | 103 |
user=request.user, subscription_info=subscription_data |
104 | 104 |
) |
105 | 105 |
subscription.save() |
combo/apps/search/manager_views.py | ||
---|---|---|
150 | 150 |
return HttpResponse(status=204) |
151 | 151 | |
152 | 152 |
engines = [] |
153 |
for i, engine_slug in enumerate(cell._search_services['data']):
|
|
153 |
for engine_slug in cell._search_services['data']:
|
|
154 | 154 |
try: |
155 | 155 |
new_order = int(request.GET.get('pos_' + str(engine_slug))) |
156 | 156 |
except TypeError: |
combo/data/models.py | ||
---|---|---|
114 | 114 | |
115 | 115 | |
116 | 116 |
def compile_sub_slug(sub_slug): |
117 |
sub_slug, mapping = format_sub_slug(sub_slug)
|
|
117 |
sub_slug = format_sub_slug(sub_slug)[0]
|
|
118 | 118 |
# will raise re.error if wrong regexp |
119 | 119 |
re.compile(sub_slug) |
120 | 120 |
combo/manager/views.py | ||
---|---|---|
341 | 341 | |
342 | 342 |
cells = CellBase.get_cells(page=self.object, prefetch_validity_info=True) |
343 | 343 |
self.object.prefetched_cells = cells |
344 |
template = self.object.template_name |
|
345 | 344 |
placeholders = [] |
346 | 345 |
optional_placeholders = [] |
347 |
combo_template = settings.COMBO_PUBLIC_TEMPLATES.get(template) |
|
348 | 346 | |
349 | 347 |
for placeholder in self.object.get_placeholders(request=self.request, traverse_cells=True): |
350 | 348 |
placeholder_dict = { |
... | ... | |
748 | 746 |
slug = 'portal' |
749 | 747 |
if getattr(settings, 'KNOWN_SERVICES') and 'combo' in settings.KNOWN_SERVICES: |
750 | 748 |
# switch to custom slug if the site is the portal agent. |
751 |
for service_slug, service in settings.KNOWN_SERVICES['combo'].items():
|
|
749 |
for service in settings.KNOWN_SERVICES['combo'].values():
|
|
752 | 750 |
if service.get('is-portal-agent') and not service.get('secret'): |
753 | 751 |
slug = 'portal-agent' |
754 | 752 |
break |
combo/profile/__init__.py | ||
---|---|---|
64 | 64 |
user_page_base_url = user_page.get_online_url() |
65 | 65 | |
66 | 66 |
# return entry using first(&only) authentic (if it exists) |
67 |
for key, service in settings.KNOWN_SERVICES.get('authentic', {}).items():
|
|
67 |
for service in settings.KNOWN_SERVICES.get('authentic', {}).values():
|
|
68 | 68 |
return { |
69 | 69 |
'users': { |
70 | 70 |
'url': service['url'] + 'api/users/?q=%(q)s', |
combo/public/templatetags/combo.py | ||
---|---|---|
166 | 166 |
@register.tag |
167 | 167 |
def skeleton_extra_placeholder(parser, token): |
168 | 168 |
try: |
169 |
tag_name, placeholder_name = token.split_contents()
|
|
169 |
dummy, placeholder_name = token.split_contents()
|
|
170 | 170 |
except ValueError: |
171 | 171 |
raise template.TemplateSyntaxError("%r tag requires exactly one argument" % token.contents.split()[0]) |
172 | 172 |
combo/public/views.py | ||
---|---|---|
232 | 232 |
if cell.slug not in cell_by_slugs: |
233 | 233 |
cell_by_slugs[cell.slug] = [] |
234 | 234 |
cell_by_slugs[cell.slug].append(cell) |
235 |
for slug, slug_cells in cell_by_slugs.items():
|
|
235 |
for slug_cells in cell_by_slugs.values():
|
|
236 | 236 |
for cell in slug_cells: |
237 | 237 |
cell.use_slug_as_id = bool(len(slug_cells) == 1) |
238 | 238 | |
... | ... | |
343 | 343 |
if cell.slug not in cell_by_slugs: |
344 | 344 |
cell_by_slugs[cell.slug] = [] |
345 | 345 |
cell_by_slugs[cell.slug].append(cell) |
346 |
for slug, slug_cells in cell_by_slugs.items():
|
|
346 |
for slug_cells in cell_by_slugs.values():
|
|
347 | 347 |
for cell in slug_cells: |
348 | 348 |
cell.use_slug_as_id = bool(len(slug_cells) == 1) |
349 | 349 | |
... | ... | |
376 | 376 |
self.page = Page(public=False, title=_('Style Demo')) |
377 | 377 |
self.page.template_name = self.template_name |
378 | 378 |
self.page.save() |
379 |
combo_template = settings.COMBO_PUBLIC_TEMPLATES[self.page.template_name] |
|
380 | 379 |
for i, placeholder in enumerate(self.page.get_placeholders(request=self.request)): |
381 | 380 |
cell = TextCell(page=self.page, placeholder=placeholder.key, order=0) |
382 | 381 |
if placeholder.key == 'footer': |
... | ... | |
466 | 465 |
and settings.COMBO_INITIAL_LOGIN_PAGE_PATH |
467 | 466 |
and (request.user and not request.user.is_anonymous) |
468 | 467 |
): |
469 |
profile, created = Profile.objects.get_or_create(user=request.user)
|
|
468 |
profile, dummy = Profile.objects.get_or_create(user=request.user)
|
|
470 | 469 |
if not profile.initial_login_view_timestamp: |
471 | 470 |
# first connection of user, record that and redirect to welcome URL |
472 | 471 |
profile.initial_login_view_timestamp = timezone.now() |
combo/utils/requests_wrapper.py | ||
---|---|---|
64 | 64 |
for services in settings.KNOWN_SERVICES.values(): |
65 | 65 |
for service in services.values(): |
66 | 66 |
remote_url = service.get('url') |
67 |
remote_scheme, remote_netloc, r_path, r_params, r_query, r_fragment = urlparse.urlparse( |
|
68 |
remote_url |
|
69 |
) |
|
67 |
remote_scheme, remote_netloc, dummy, dummy, dummy, dummy = urlparse.urlparse(remote_url) |
|
70 | 68 |
if remote_scheme == scheme and remote_netloc == netloc: |
71 | 69 |
remote_service = service |
72 | 70 |
break |
... | ... | |
105 | 103 |
query_params['orig'] = remote_service.get('orig') |
106 | 104 | |
107 | 105 |
remote_service_base_url = remote_service.get('url') |
108 |
scheme, netloc, old_path, params, old_query, fragment = urlparse.urlparse(remote_service_base_url)
|
|
106 |
scheme, netloc, dummy, params, old_query, fragment = urlparse.urlparse(remote_service_base_url)
|
|
109 | 107 | |
110 | 108 |
query = urlencode(query_params) |
111 | 109 |
if '?' in url: |
tests/test_assets.py | ||
---|---|---|
30 | 30 |
def count_asset_files(): |
31 | 31 |
nb_assets = 0 |
32 | 32 |
media_prefix = default_storage.path('') |
33 |
for basedir, dirnames, filenames in os.walk(media_prefix):
|
|
33 |
for dummy, dummy, filenames in os.walk(media_prefix):
|
|
34 | 34 |
nb_assets += len(filenames) |
35 | 35 |
return nb_assets |
36 | 36 |
tests/test_cells.py | ||
---|---|---|
822 | 822 |
'combo-public-ajax-page-cell', |
823 | 823 |
kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()}, |
824 | 824 |
) |
825 |
resp = app.get(url)
|
|
825 |
app.get(url) |
|
826 | 826 |
assert requests_get.call_count == 1 |
827 | 827 |
assert requests_get.call_args[0][0] == 'http://foo?var=plop' |
828 | 828 |
assert requests_get.call_args[-1]['log_errors'] == False |
... | ... | |
1280 | 1280 |
page = Page(title='example page', slug='example-page') |
1281 | 1281 |
page.save() |
1282 | 1282 | |
1283 |
request = RequestFactory().get('/') |
|
1284 | ||
1285 | 1283 |
with override_settings(JSON_CELL_TYPES={'foobar': {'name': 'Foobar', 'url': 'http://test/'}}): |
1286 | 1284 |
cell = ConfigJsonCell() |
1287 | 1285 |
cell.key = 'foobar' |
tests/test_dashboard.py | ||
---|---|---|
66 | 66 |
def test_add_to_dashboard_order(app, site): |
67 | 67 |
test_add_to_dashboard(app, site) |
68 | 68 |
cell = TextCell.objects.get(order=101) |
69 |
resp = app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
|
69 |
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()})) |
|
70 | 70 |
assert Tile.objects.count() == 2 |
71 | 71 |
assert Tile.objects.all()[0].cell.text == 'hello world (100)' |
72 | 72 |
assert Tile.objects.all()[1].cell.text == 'hello world (101)' |
73 | 73 | |
74 | 74 |
cell = TextCell.objects.get(order=102) |
75 |
resp = app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
|
75 |
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()})) |
|
76 | 76 |
assert Tile.objects.count() == 3 |
77 | 77 |
assert Tile.objects.all()[0].cell.text == 'hello world (100)' |
78 | 78 |
assert Tile.objects.all()[1].cell.text == 'hello world (101)' |
... | ... | |
80 | 80 | |
81 | 81 |
with override_settings(COMBO_DASHBOARD_NEW_TILE_POSITION='first'): |
82 | 82 |
cell = TextCell.objects.get(order=103) |
83 |
resp = app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
|
|
83 |
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()})) |
|
84 | 84 |
assert Tile.objects.count() == 4 |
85 | 85 |
assert Tile.objects.all()[0].cell.text == 'hello world (103)' |
86 | 86 |
assert Tile.objects.all()[1].cell.text == 'hello world (100)' |
... | ... | |
112 | 112 |
app.reset() # logout |
113 | 113 |
tile = Tile.objects.all()[0] |
114 | 114 |
page = Page.objects.get(slug='two') |
115 |
resp = app.get(
|
|
115 |
app.get( |
|
116 | 116 |
reverse( |
117 | 117 |
'combo-public-ajax-page-cell', |
118 | 118 |
kwargs={'page_pk': page.id, 'cell_reference': tile.cell.get_reference()}, |
... | ... | |
121 | 121 |
) |
122 | 122 | |
123 | 123 |
app = login(app) |
124 |
resp = app.get(
|
|
124 |
app.get( |
|
125 | 125 |
reverse( |
126 | 126 |
'combo-public-ajax-page-cell', |
127 | 127 |
kwargs={'page_pk': page.id, 'cell_reference': tile.cell.get_reference()}, |
... | ... | |
129 | 129 |
status=200, |
130 | 130 |
) |
131 | 131 | |
132 |
user = User.objects.create_user('plop', email=None, password='plop')
|
|
132 |
User.objects.create_user('plop', email=None, password='plop') |
|
133 | 133 |
app = login(app, username='plop', password='plop') |
134 |
resp = app.get(
|
|
134 |
app.get( |
|
135 | 135 |
reverse( |
136 | 136 |
'combo-public-ajax-page-cell', |
137 | 137 |
kwargs={'page_pk': page.id, 'cell_reference': tile.cell.get_reference()}, |
... | ... | |
144 | 144 |
test_add_to_dashboard(app, site) |
145 | 145 |
app.reset() # logout |
146 | 146 |
tile = Tile.objects.all()[0] |
147 |
resp = app.get(
|
|
147 |
app.get( |
|
148 | 148 |
reverse('combo-dashboard-remove-tile', kwargs={'cell_reference': tile.cell.get_reference()}), |
149 | 149 |
status=403, |
150 | 150 |
) |
151 | 151 | |
152 | 152 |
app = login(app) |
153 |
resp = app.get(
|
|
153 |
app.get( |
|
154 | 154 |
reverse('combo-dashboard-remove-tile', kwargs={'cell_reference': tile.cell.get_reference()}), |
155 | 155 |
status=302, |
156 | 156 |
) |
... | ... | |
180 | 180 |
# add cells to dashboard |
181 | 181 |
app = login(app) |
182 | 182 |
for i in range(103, 108): |
183 |
resp = app.get(
|
|
183 |
app.get( |
|
184 | 184 |
reverse( |
185 | 185 |
'combo-dashboard-add-tile', |
186 | 186 |
kwargs={'cell_reference': TextCell.objects.get(order=i).get_reference()}, |
... | ... | |
192 | 192 |
app.reset() # logout |
193 | 193 |
tiles = Tile.objects.filter(user=user).order_by('?') |
194 | 194 |
new_order = ','.join([str(x.id) for x in tiles]) |
195 |
resp = app.get(
|
|
195 |
app.get( |
|
196 | 196 |
reverse('combo-dashboard-reorder-tiles', kwargs={'dashboard_id': dashboard.id}), |
197 | 197 |
params={'order': new_order}, |
198 | 198 |
status=403, |
199 | 199 |
) |
200 | 200 | |
201 | 201 |
app = login(app) |
202 |
resp = app.get(
|
|
202 |
app.get( |
|
203 | 203 |
reverse('combo-dashboard-reorder-tiles', kwargs={'dashboard_id': dashboard.id}), |
204 | 204 |
params={'order': new_order}, |
205 | 205 |
) |
tests/test_dataviz.py | ||
---|---|---|
1377 | 1377 |
cell.statistic = Statistic.objects.get(slug='one-serie') |
1378 | 1378 |
cell.save() |
1379 | 1379 | |
1380 |
chart = cell.get_chart()
|
|
1380 |
cell.get_chart() |
|
1381 | 1381 |
request = new_api_mock.call['requests'][0] |
1382 | 1382 |
assert 'time_interval=' not in request.url |
1383 | 1383 |
assert 'ou=' not in request.url |
1384 | 1384 | |
1385 | 1385 |
cell.filter_params = {'time_interval': 'month', 'ou': 'default'} |
1386 | 1386 |
cell.save() |
1387 |
chart = cell.get_chart()
|
|
1387 |
cell.get_chart() |
|
1388 | 1388 |
request = new_api_mock.call['requests'][1] |
1389 | 1389 |
assert 'time_interval=month' in request.url |
1390 | 1390 |
assert 'ou=default' in request.url |
... | ... | |
1392 | 1392 |
freezer.move_to(date) |
1393 | 1393 |
cell.time_range = 'previous-year' |
1394 | 1394 |
cell.save() |
1395 |
chart = cell.get_chart()
|
|
1395 |
cell.get_chart() |
|
1396 | 1396 |
request = new_api_mock.call['requests'][2] |
1397 | 1397 |
assert 'time_interval=month' in request.url |
1398 | 1398 |
assert 'ou=default' in request.url |
... | ... | |
1400 | 1400 | |
1401 | 1401 |
cell.time_range = 'current-week' |
1402 | 1402 |
cell.save() |
1403 |
chart = cell.get_chart()
|
|
1403 |
cell.get_chart() |
|
1404 | 1404 |
request = new_api_mock.call['requests'][-1] |
1405 | 1405 |
assert 'start=2020-03-02' in request.url and 'end=2020-03-09' in request.url |
1406 | 1406 | |
1407 | 1407 |
cell.time_range = 'previous-week' |
1408 | 1408 |
cell.save() |
1409 |
chart = cell.get_chart()
|
|
1409 |
cell.get_chart() |
|
1410 | 1410 |
request = new_api_mock.call['requests'][-1] |
1411 | 1411 |
assert 'start=2020-02-24' in request.url and 'end=2020-03-02' in request.url |
1412 | 1412 | |
1413 | 1413 |
cell.time_range = 'next-week' |
1414 | 1414 |
cell.save() |
1415 |
chart = cell.get_chart()
|
|
1415 |
cell.get_chart() |
|
1416 | 1416 |
request = new_api_mock.call['requests'][-1] |
1417 | 1417 |
assert 'start=2020-03-09' in request.url and 'end=2020-03-16' in request.url |
1418 | 1418 | |
1419 | 1419 |
cell.time_range = 'range' |
1420 | 1420 |
cell.save() |
1421 |
chart = cell.get_chart()
|
|
1421 |
cell.get_chart() |
|
1422 | 1422 |
request = new_api_mock.call['requests'][-1] |
1423 | 1423 |
assert 'start' not in urllib.parse.parse_qs(urllib.parse.urlparse(request.url).query) |
1424 | 1424 |
assert 'end' not in urllib.parse.parse_qs(urllib.parse.urlparse(request.url).query) |
1425 | 1425 | |
1426 | 1426 |
cell.time_range_start = '2020-10-01' |
1427 | 1427 |
cell.save() |
1428 |
chart = cell.get_chart()
|
|
1428 |
cell.get_chart() |
|
1429 | 1429 |
request = new_api_mock.call['requests'][-1] |
1430 | 1430 |
assert 'start=2020-10-01' in request.url |
1431 | 1431 | |
1432 | 1432 |
cell.time_range_end = '2020-11-03' |
1433 | 1433 |
cell.save() |
1434 |
chart = cell.get_chart()
|
|
1434 |
cell.get_chart() |
|
1435 | 1435 |
request = new_api_mock.call['requests'][-1] |
1436 | 1436 |
assert 'start=2020-10-01' in request.url and 'end=2020-11-03' in request.url |
1437 | 1437 | |
... | ... | |
1448 | 1448 |
cell.save() |
1449 | 1449 | |
1450 | 1450 |
freezer.move_to('2021-01-02') |
1451 |
chart = cell.get_chart()
|
|
1451 |
cell.get_chart() |
|
1452 | 1452 |
request = new_api_mock.call['requests'][0] |
1453 | 1453 |
assert 'start=2021-01-01' in request.url and 'end=2021-02-01' in request.url |
1454 | 1454 | |
1455 | 1455 |
cell.time_range = 'previous-month' |
1456 | 1456 |
cell.save() |
1457 |
chart = cell.get_chart()
|
|
1457 |
cell.get_chart() |
|
1458 | 1458 |
request = new_api_mock.call['requests'][1] |
1459 | 1459 |
assert 'start=2020-12-01' in request.url and 'end=2021-01-01' in request.url |
1460 | 1460 | |
1461 | 1461 |
freezer.move_to('2021-11-02') |
1462 | 1462 |
cell.time_range = 'next-month' |
1463 | 1463 |
cell.save() |
1464 |
chart = cell.get_chart()
|
|
1464 |
cell.get_chart() |
|
1465 | 1465 |
request = new_api_mock.call['requests'][2] |
1466 | 1466 |
assert 'start=2021-12-01' in request.url and 'end=2022-01-01' in request.url |
1467 | 1467 |
tests/test_lingo_cells.py | ||
---|---|---|
201 | 201 |
page.save() |
202 | 202 |
cell = LingoBasketLinkCell(page=page, placeholder='content', order=0) |
203 | 203 |
cell.save() |
204 |
resp = app.get('/__skeleton__/?source=%s' % quote('http://example.net/foo/bar'))
|
|
204 |
app.get('/__skeleton__/?source=%s' % quote('http://example.net/foo/bar')) |
|
205 | 205 | |
206 | 206 | |
207 | 207 |
def test_tipi_cell(): |
tests/test_lingo_payment.py | ||
---|---|---|
242 | 242 |
'/lingo/return-payment-backend/%s/' % regie.payment_backend.id |
243 | 243 |
) |
244 | 244 |
# simulate successful call to callback URL |
245 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
|
|
245 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request'): |
|
246 | 246 |
resp = app.get(get_url(with_payment_backend, 'lingo-callback', regie), params=args) |
247 | 247 |
assert resp.status_code == 200 |
248 | 248 |
# simulate successful return URL |
... | ... | |
343 | 343 |
url = '%s?NameId=%s&orig=wcs' % (reverse('api-add-basket-item'), user_name_id) |
344 | 344 |
url = sign_url(url, settings.LINGO_API_SIGN_KEY) |
345 | 345 |
resp = app.post_json(url, params=data) |
346 |
item = BasketItem.objects.get(amount=Decimal('22.23')) |
|
347 | 346 |
assert resp.status_code == 200 |
348 | 347 |
response = json.loads(resp.text) |
349 | 348 |
assert response['result'] == 'success' |
... | ... | |
810 | 809 |
def test_payment_callback(app, basket_page, regie, user, with_payment_backend): |
811 | 810 |
page = Page(title='xxx', slug='index', template_name='standard') |
812 | 811 |
page.save() |
813 |
item = BasketItem.objects.create(
|
|
812 |
BasketItem.objects.create( |
|
814 | 813 |
user=user, regie=regie, subject='test_item', amount='10.5', source_url='http://example.org/testitem/' |
815 | 814 |
) |
816 | 815 |
resp = login(app).get(basket_page.get_online_url()) |
... | ... | |
832 | 831 |
assert get_resp.status_code == 200 |
833 | 832 |
assert Transaction.objects.get(order_id=transaction_id).status == 3 |
834 | 833 | |
835 |
item = BasketItem.objects.create(
|
|
834 |
BasketItem.objects.create( |
|
836 | 835 |
user=user, regie=regie, subject='test_item', amount='11.5', source_url='http://example.org/testitem/' |
837 | 836 |
) |
838 | 837 |
resp = login(app).get(basket_page.get_online_url()) |
... | ... | |
861 | 860 | |
862 | 861 |
@pytest.mark.parametrize('with_payment_backend', [False, True]) |
863 | 862 |
def test_payment_callback_no_regie(app, basket_page, regie, user, with_payment_backend): |
864 |
item = BasketItem.objects.create(
|
|
863 |
BasketItem.objects.create( |
|
865 | 864 |
user=user, regie=regie, subject='test_item', amount='10.5', source_url='http://example.org/testitem/' |
866 | 865 |
) |
867 | 866 |
resp = login(app).get(basket_page.get_online_url()) |
... | ... | |
883 | 882 |
assert get_resp.status_code == 200 |
884 | 883 |
assert Transaction.objects.get(order_id=transaction_id).status == 3 |
885 | 884 | |
886 |
item = BasketItem.objects.create(
|
|
885 |
BasketItem.objects.create( |
|
887 | 886 |
user=user, regie=regie, subject='test_item', amount='11.5', source_url='http://example.org/testitem/' |
888 | 887 |
) |
889 | 888 |
resp = login(app).get(basket_page.get_online_url()) |
... | ... | |
901 | 900 |
def test_payment_return_without_query_string(app, basket_page, regie, user, with_payment_backend): |
902 | 901 |
page = Page(title='xxx', slug='index', template_name='standard') |
903 | 902 |
page.save() |
904 |
item = BasketItem.objects.create(
|
|
903 |
BasketItem.objects.create( |
|
905 | 904 |
user=user, regie=regie, subject='test_item', amount='10.5', source_url='http://example.org/testitem/' |
906 | 905 |
) |
907 | 906 |
resp = login(app).get(basket_page.get_online_url()) |
... | ... | |
916 | 915 | |
917 | 916 |
# payment status is obtained through callback |
918 | 917 |
callback_url = get_url(with_payment_backend, 'lingo-callback', regie) |
919 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as request:
|
|
918 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request'): |
|
920 | 919 |
get_resp = app.get(callback_url, params=data) |
921 | 920 |
transaction = Transaction.objects.get(order_id=transaction_id) |
922 | 921 |
assert transaction.status == 3 |
... | ... | |
988 | 987 | |
989 | 988 |
@pytest.mark.parametrize('with_payment_backend', [False, True]) |
990 | 989 |
def test_payment_no_callback_just_return(caplog, app, basket_page, regie, user, with_payment_backend): |
991 |
item = BasketItem.objects.create(
|
|
990 |
BasketItem.objects.create( |
|
992 | 991 |
user=user, regie=regie, subject='test_item', amount='10.5', source_url='http://example.org/testitem/' |
993 | 992 |
) |
994 | 993 |
resp = login(app).get(basket_page.get_online_url()) |
... | ... | |
1615 | 1614 | |
1616 | 1615 | |
1617 | 1616 |
def test_request_payment_exception(app, basket_page, regie, user): |
1618 |
item = BasketItem.objects.create(
|
|
1617 |
BasketItem.objects.create( |
|
1619 | 1618 |
user=user, regie=regie, subject='test_item', amount='10.5', source_url='http://example.org/testitem/' |
1620 | 1619 |
) |
1621 | 1620 |
tests/test_lingo_remote_regie.py | ||
---|---|---|
156 | 156 |
# check if regie webservice has been correctly called |
157 | 157 |
assert mock_send.call_args[0][0].method == 'GET' |
158 | 158 |
url = mock_send.call_args[0][0].url |
159 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
159 |
scheme, netloc, path, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
160 | 160 |
assert scheme == 'http' |
161 | 161 |
assert netloc == 'example.org' |
162 | 162 |
assert path == '/regie/invoices/' |
... | ... | |
285 | 285 |
# check if regie webservice has been correctly called |
286 | 286 |
assert mock_send.call_args[0][0].method == 'GET' |
287 | 287 |
url = mock_send.call_args[0][0].url |
288 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
288 |
scheme, netloc, path, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
289 | 289 |
assert scheme == 'http' |
290 | 290 |
assert netloc == 'example.org' |
291 | 291 |
assert path == '/regie/invoices/history/' |
... | ... | |
530 | 530 |
mock_json = mock.Mock() |
531 | 531 |
mock_json.json.return_value = {'err': 0, 'data': INVOICES[0]} |
532 | 532 |
mock_get.return_value = mock_json |
533 |
resp = app.get('/lingo/item/%s/%s/' % (remote_regie.id, 'zrzer854sfaear45e6rzerzerzef'), status=404)
|
|
533 |
app.get('/lingo/item/%s/%s/' % (remote_regie.id, 'zrzer854sfaear45e6rzerzerzef'), status=404) |
|
534 | 534 | |
535 | 535 | |
536 | 536 |
@mock.patch('combo.apps.lingo.models.requests.get') |
tests/test_manager.py | ||
---|---|---|
1403 | 1403 | |
1404 | 1404 |
params = [] |
1405 | 1405 |
new_order = [2, 3, 1, 4, 5] |
1406 |
for i, (cell, new_pos) in enumerate(zip(cells, new_order)):
|
|
1406 |
for i, (cell, dummy) in enumerate(zip(cells, new_order)):
|
|
1407 | 1407 |
params.append(('ph_data_textcell-%s' % cell.id, 'content')) # no placeholder change |
1408 | 1408 |
params.append(('pos_data_textcell-%s' % cell.id, str(new_order[i]))) |
1409 | 1409 | |
... | ... | |
1659 | 1659 |
resp = app.get('/manage/assets/') |
1660 | 1660 |
assert 'have any asset yet.' in resp.text |
1661 | 1661 | |
1662 |
for i in range(25):
|
|
1662 |
for dummy in range(25):
|
|
1663 | 1663 |
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'cc.png') |
1664 | 1664 |
pix = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVQI12NoAAAAggCB3UNq9AAAAABJRU5ErkJggg==' |
1665 | 1665 |
default_storage.save(filepath, BytesIO(base64.decodebytes(pix))) |
... | ... | |
1751 | 1751 |
assert 'CKEditorFuncNum=0' in resp.request.url |
1752 | 1752 |
assert resp.text.count('<tr class="asset') == 2 |
1753 | 1753 | |
1754 |
for i in range(25):
|
|
1754 |
for dummy in range(25):
|
|
1755 | 1755 |
filepath = os.path.join(settings.CKEDITOR_UPLOAD_PATH, 'cc.png') |
1756 | 1756 |
pix = b'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVQI12NoAAAAggCB3UNq9AAAAABJRU5ErkJggg==' |
1757 | 1757 |
default_storage.save(filepath, BytesIO(base64.decodebytes(pix))) |
... | ... | |
2161 | 2161 | |
2162 | 2162 |
app = login(app) |
2163 | 2163 | |
2164 |
with mock.patch('combo.utils.requests.get') as requests_get: |
|
2165 |
data = {'data': [{'url': 'xxx', 'text': 'xxx'}]} |
|
2164 |
with mock.patch('combo.utils.requests.get'): |
|
2166 | 2165 |
with pytest.raises(TemplateSyntaxError): |
2167 | 2166 |
cell.render({}) |
2168 | 2167 | |
... | ... | |
2473 | 2472 | |
2474 | 2473 |
params = [] |
2475 | 2474 |
new_order = [2, 3, 1, 4, 5] |
2476 |
for i, (item, new_pos) in enumerate(zip(items, new_order)):
|
|
2475 |
for item, new_pos in zip(items, new_order):
|
|
2477 | 2476 |
params.append(('pos_%s' % item.pk, str(new_pos))) |
2478 | 2477 | |
2479 | 2478 |
app = login(app) |
tests/test_notification.py | ||
---|---|---|
289 | 289 |
@mock.patch('combo.utils.requests_wrapper.RequestsSession.request') |
290 | 290 |
def test_notify_remote_items(mock_get, app, john_doe, jane_doe, regie, monkeypatch, freezer): |
291 | 291 |
freezer.move_to('2016-01-02') |
292 |
datetime_format = '%Y-%m-%dT%H:%M:%S' |
|
293 | 292 |
invoice_now = now() |
294 | 293 |
invoice_now = freezer() |
295 | 294 |
FAKE_PENDING_INVOICES = { |
tests/test_pages.py | ||
---|---|---|
462 | 462 |
page.parent_id = parent_id |
463 | 463 |
page.save() |
464 | 464 |
add_pages.num += 1 |
465 |
for m in range(0, depth + 1):
|
|
465 |
for dummy in range(0, depth + 1):
|
|
466 | 466 |
add_pages(depth + 1, page.id) |
467 | 467 | |
468 | 468 |
add_pages.num = 1 |
tests/test_public.py | ||
---|---|---|
282 | 282 |
page = Page(title='Home', slug='index', template_name='standard', public=False) |
283 | 283 |
page.save() |
284 | 284 |
app = login(app) |
285 |
resp = app.get('/', status=200)
|
|
285 |
app.get('/', status=200) |
|
286 | 286 | |
287 | 287 | |
288 | 288 |
def test_page_skeleton(app): |
tests/test_pwa.py | ||
---|---|---|
79 | 79 |
pwa_settings.push_notifications = False |
80 | 80 |
pwa_settings.save() |
81 | 81 |
with mock.patch('pywebpush.webpush') as webpush: |
82 |
notification = Notification.notify(john_doe, 'test', body='hello world')
|
|
82 |
Notification.notify(john_doe, 'test', body='hello world') |
|
83 | 83 |
assert webpush.call_count == 0 |
84 | 84 | |
85 | 85 |
pwa_settings.push_notifications = True |
86 | 86 |
pwa_settings.save() |
87 | 87 |
with mock.patch('pywebpush.webpush') as webpush: |
88 |
notification = Notification.notify(john_doe, 'test', body='hello world')
|
|
88 |
Notification.notify(john_doe, 'test', body='hello world') |
|
89 | 89 |
assert webpush.call_count == 1 |
90 | 90 |
assert webpush.call_args[1]['subscription_info'] == {'sample': 'content'} |
91 | 91 | |
... | ... | |
96 | 96 |
PWA_VAPID_CLAIMS={'sub': 'mailto:admin@entrouvert.com'}, |
97 | 97 |
): |
98 | 98 |
with mock.patch('pywebpush.webpush') as webpush: |
99 |
notification = Notification.notify(john_doe, 'test', body='hello world')
|
|
99 |
Notification.notify(john_doe, 'test', body='hello world') |
|
100 | 100 |
assert webpush.call_count == 1 |
101 | 101 |
assert webpush.call_args[1]['subscription_info'] == {'sample': 'content'} |
102 | 102 |
assert webpush.call_args[1]['vapid_private_key'] == settings.PWA_VAPID_PRIVATE_KEY |
... | ... | |
271 | 271 |
assert len(resp.json['icons']) == 5 |
272 | 272 | |
273 | 273 |
# make sure largest icon is referenced in service worker |
274 |
resp2 = app.get('/service-worker.js', status=200)
|
|
274 |
app.get('/service-worker.js', status=200) |
|
275 | 275 |
assert resp.json['icons'][-1]['src'].split('/')[-1] in resp.text |
276 | 276 | |
277 | 277 |
tests/test_requests.py | ||
---|---|---|
32 | 32 |
requests.get('/foo/bar/', remote_service=remote_service) |
33 | 33 |
url = send.call_args[0][0].url |
34 | 34 |
assert url.startswith('http://example.org/foo/bar/?') |
35 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
35 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
36 | 36 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
37 | 37 |
assert query['orig'][0] == 'myself' |
38 | 38 |
assert query['email'][0] == '' |
... | ... | |
42 | 42 |
requests.get('/foo/bar/', remote_service=remote_service, without_user=True) |
43 | 43 |
url = send.call_args[0][0].url |
44 | 44 |
assert url.startswith('http://example.org/foo/bar/?') |
45 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
45 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
46 | 46 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
47 | 47 |
assert query['orig'][0] == 'myself' |
48 | 48 |
assert 'email' not in query |
... | ... | |
55 | 55 |
requests.get('http://example.org/foo/bar/', remote_service='auto') |
56 | 56 |
url = send.call_args[0][0].url |
57 | 57 |
assert url.startswith('http://example.org/foo/bar/?') |
58 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
58 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
59 | 59 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
60 | 60 |
assert query['orig'][0] == 'combo' |
61 | 61 |
assert check_query(querystring, 'combo') == True |
... | ... | |
73 | 73 |
requests.get('/foo/bar/', remote_service=remote_service, user=user) |
74 | 74 |
url = send.call_args[0][0].url |
75 | 75 |
assert url.startswith('http://example.org/foo/bar/?') |
76 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
76 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
77 | 77 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
78 | 78 |
assert query['NameID'][0] == 'r2d2' |
79 | 79 |
assert 'email' not in query |
... | ... | |
83 | 83 |
requests.get('/foo/bar/', remote_service=remote_service, user=user, federation_key='email') |
84 | 84 |
url = send.call_args[0][0].url |
85 | 85 |
assert url.startswith('http://example.org/foo/bar/?') |
86 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
86 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
87 | 87 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
88 | 88 |
assert query['email'][0] == 'foo@example.net' |
89 | 89 |
assert 'NameID' not in query |
... | ... | |
95 | 95 |
requests.get('/foo/bar/', remote_service=remote_service, user=user) |
96 | 96 |
url = send.call_args[0][0].url |
97 | 97 |
assert url.startswith('http://example.org/foo/bar/?') |
98 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
98 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
99 | 99 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
100 | 100 |
assert 'NameID' not in query |
101 | 101 |
assert query['email'][0] == 'foo@example.net' |
... | ... | |
112 | 112 |
requests.get('/foo/bar/', remote_service=remote_service, user=user) |
113 | 113 |
url = send.call_args[0][0].url |
114 | 114 |
assert url.startswith('http://example.org/foo/bar/?') |
115 |
scheme, netloc, path, params, querystring, fragment = urlparse.urlparse(url)
|
|
115 |
dummy, dummy, dummy, dummy, querystring, dummy = urlparse.urlparse(url)
|
|
116 | 116 |
query = urlparse.parse_qs(querystring, keep_blank_values=True) |
117 | 117 |
assert query['NameID'][0] == '' |
118 | 118 |
assert query['email'][0] == '' |
tests/test_search.py | ||
---|---|---|
243 | 243 |
with mock.patch('combo.utils.requests.get') as requests_get: |
244 | 244 |
data = {'data': []} |
245 | 245 |
requests_get.return_value = mock.Mock(json=lambda: data, status_code=200) |
246 |
resp = app.get(url)
|
|
246 |
app.get(url) |
|
247 | 247 |
assert requests_get.call_args[0][0] == 'http://www.example.net/search/foo/' |
248 | 248 | |
249 | 249 | |
... | ... | |
800 | 800 | |
801 | 801 |
params = [] |
802 | 802 |
new_order = [2, 3, 1] |
803 |
for i, (service_slug, new_pos) in enumerate(zip(cell._search_services['data'], new_order)):
|
|
803 |
for service_slug, new_pos in zip(cell._search_services['data'], new_order):
|
|
804 | 804 |
params.append(('pos_%s' % service_slug, str(new_pos))) |
805 | 805 | |
806 | 806 |
app = login(app) |
807 |
- |