1601 lines
66 KiB
Python
1601 lines
66 KiB
Python
import copy
|
|
import datetime
|
|
import json
|
|
|
|
import pytest
|
|
from webtest import Upload
|
|
|
|
from chrono.agendas.models import Agenda
|
|
from chrono.pricing.models import AgendaPricing, Criteria, CriteriaCategory, Pricing, PricingCriteriaCategory
|
|
from tests.utils import login
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
@pytest.fixture
|
|
def agenda_with_restrictions(manager_user):
|
|
agenda = Agenda(label='Foo Bar')
|
|
agenda.view_role = manager_user.groups.all()[0]
|
|
agenda.save()
|
|
return agenda
|
|
|
|
|
|
def test_list_pricings_as_manager(app, manager_user, agenda_with_restrictions):
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/', status=403)
|
|
|
|
resp = app.get('/manage/')
|
|
assert 'Pricing' not in resp.text
|
|
|
|
|
|
def test_add_pricing(settings, app, admin_user):
|
|
app = login(app)
|
|
resp = app.get('/manage/')
|
|
resp = resp.click('Pricing')
|
|
resp = resp.click('New pricing model')
|
|
resp.form['label'] = 'Pricing model for lunch'
|
|
resp = resp.form.submit()
|
|
pricing = Pricing.objects.latest('pk')
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
assert pricing.label == 'Pricing model for lunch'
|
|
assert pricing.slug == 'pricing-model-for-lunch'
|
|
|
|
settings.CHRONO_ENABLE_PRICING = False
|
|
resp = app.get('/manage/')
|
|
assert 'Pricing' not in resp.text
|
|
|
|
|
|
def test_add_pricing_as_manager(app, manager_user):
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/add/', status=403)
|
|
|
|
|
|
def test_detail_pricing(app, admin_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/')
|
|
resp = resp.click(href='/manage/pricing/%s/' % pricing.pk)
|
|
assert '/manage/pricing/%s/edit/' % pricing.pk in resp
|
|
assert '/manage/pricing/%s/delete/' % pricing.pk in resp
|
|
|
|
|
|
def test_detail_pricing_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/' % pricing.pk, status=403)
|
|
|
|
|
|
def test_edit_pricing(app, admin_user):
|
|
pricing = Pricing.objects.create(label='Model 1')
|
|
pricing2 = Pricing.objects.create(label='Model 2')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.click(href='/manage/pricing/%s/edit/' % pricing.pk)
|
|
resp.form['label'] = 'Model Foo'
|
|
resp.form['slug'] = pricing2.slug
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['slug'] == ['Pricing with this Identifier already exists.']
|
|
|
|
resp.form['slug'] = 'foo-bar'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
pricing.refresh_from_db()
|
|
assert pricing.label == 'Model Foo'
|
|
assert pricing.slug == 'foo-bar'
|
|
|
|
|
|
def test_edit_pricing_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/edit/' % pricing.pk, status=403)
|
|
|
|
|
|
def test_delete_pricing(app, admin_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.click(href='/manage/pricing/%s/delete/' % pricing.pk)
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/')
|
|
assert Pricing.objects.exists() is False
|
|
|
|
|
|
def test_delete_pricing_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/delete/' % pricing.pk, status=403)
|
|
|
|
|
|
@pytest.mark.freeze_time('2021-07-08')
|
|
def test_import_pricing(app, admin_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/export/' % pricing.id)
|
|
assert resp.headers['content-type'] == 'application/json'
|
|
assert resp.headers['content-disposition'] == 'attachment; filename="export_pricing_model_20210708.json"'
|
|
pricing_export = resp.text
|
|
|
|
# existing pricing
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload('export.json', pricing_export.encode('utf-8'), 'application/json')
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.follow()
|
|
assert 'No pricing model created. A pricing model has been updated.' not in resp.text
|
|
assert Pricing.objects.count() == 1
|
|
|
|
# new pricing
|
|
Pricing.objects.all().delete()
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload('export.json', pricing_export.encode('utf-8'), 'application/json')
|
|
resp = resp.form.submit()
|
|
pricing = Pricing.objects.latest('pk')
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.follow()
|
|
assert 'A pricing model has been created. No pricing model updated.' not in resp.text
|
|
assert Pricing.objects.count() == 1
|
|
|
|
# multiple pricing
|
|
pricings = json.loads(pricing_export)
|
|
pricings['pricing_models'].append(copy.copy(pricings['pricing_models'][0]))
|
|
pricings['pricing_models'].append(copy.copy(pricings['pricing_models'][0]))
|
|
pricings['pricing_models'][1]['label'] = 'Foo bar 2'
|
|
pricings['pricing_models'][1]['slug'] = 'foo-bar-2'
|
|
pricings['pricing_models'][2]['label'] = 'Foo bar 3'
|
|
pricings['pricing_models'][2]['slug'] = 'foo-bar-3'
|
|
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload(
|
|
'export.json', json.dumps(pricings).encode('utf-8'), 'application/json'
|
|
)
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/')
|
|
resp = resp.follow()
|
|
assert '2 pricing models have been created. A pricing model has been updated.' in resp.text
|
|
assert Pricing.objects.count() == 3
|
|
|
|
Pricing.objects.all().delete()
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload(
|
|
'export.json', json.dumps(pricings).encode('utf-8'), 'application/json'
|
|
)
|
|
resp = resp.form.submit().follow()
|
|
assert '3 pricing models have been created. No pricing model updated.' in resp.text
|
|
assert Pricing.objects.count() == 3
|
|
|
|
|
|
def test_pricing_edit_extra_variables(app, admin_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
assert pricing.extra_variables == {}
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/' % pricing.id)
|
|
assert '<label>Extra variables:</label>' not in resp.text
|
|
resp = resp.click(href='/manage/pricing/%s/variable/' % pricing.id)
|
|
resp.form['form-0-key'] = 'foo'
|
|
resp.form['form-0-value'] = 'bar'
|
|
resp = resp.form.submit().follow()
|
|
pricing.refresh_from_db()
|
|
assert pricing.extra_variables == {'foo': 'bar'}
|
|
assert '<label>Extra variables:</label>' in resp.text
|
|
assert '<i>foo</i>' in resp
|
|
|
|
resp = resp.click(href='/manage/pricing/%s/variable/' % pricing.id)
|
|
assert resp.form['form-TOTAL_FORMS'].value == '2'
|
|
assert resp.form['form-0-key'].value == 'foo'
|
|
assert resp.form['form-0-value'].value == 'bar'
|
|
assert resp.form['form-1-key'].value == ''
|
|
assert resp.form['form-1-value'].value == ''
|
|
resp.form['form-0-value'] = 'bar-bis'
|
|
resp.form['form-1-key'] = 'blah'
|
|
resp.form['form-1-value'] = 'baz'
|
|
resp = resp.form.submit().follow()
|
|
pricing.refresh_from_db()
|
|
assert pricing.extra_variables == {
|
|
'foo': 'bar-bis',
|
|
'blah': 'baz',
|
|
}
|
|
assert '<i>blah</i>, <i>foo</i>' in resp
|
|
|
|
resp = resp.click(href='/manage/pricing/%s/variable/' % pricing.id)
|
|
assert resp.form['form-TOTAL_FORMS'].value == '3'
|
|
assert resp.form['form-0-key'].value == 'blah'
|
|
assert resp.form['form-0-value'].value == 'baz'
|
|
assert resp.form['form-1-key'].value == 'foo'
|
|
assert resp.form['form-1-value'].value == 'bar-bis'
|
|
assert resp.form['form-2-key'].value == ''
|
|
assert resp.form['form-2-value'].value == ''
|
|
resp.form['form-1-key'] = 'foo'
|
|
resp.form['form-1-value'] = 'bar'
|
|
resp.form['form-0-key'] = ''
|
|
resp = resp.form.submit().follow()
|
|
pricing.refresh_from_db()
|
|
assert pricing.extra_variables == {
|
|
'foo': 'bar',
|
|
}
|
|
assert '<i>foo</i>' in resp
|
|
|
|
|
|
def test_pricing_edit_extra_variables_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/variable/' % pricing.pk, status=403)
|
|
|
|
|
|
def test_pricing_add_category(app, admin_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
category4 = CriteriaCategory.objects.create(label='Cat 4')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.click(href='/manage/pricing/%s/category/add/' % pricing.pk)
|
|
assert list(resp.context['form'].fields['category'].queryset) == [
|
|
category1,
|
|
category2,
|
|
category3,
|
|
category4,
|
|
]
|
|
resp.form['category'] = category1.pk
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.follow()
|
|
assert '/manage/pricing/%s/category/add/' % pricing.pk in resp
|
|
assert list(
|
|
PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('category', flat=True)
|
|
) == [category1.pk]
|
|
assert list(PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('order', flat=True)) == [
|
|
1
|
|
]
|
|
|
|
resp = app.get('/manage/pricing/%s/category/add/' % pricing.pk)
|
|
assert list(resp.context['form'].fields['category'].queryset) == [category2, category3, category4]
|
|
resp.form['category'] = category4.pk
|
|
resp = resp.form.submit().follow()
|
|
assert list(
|
|
PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('category', flat=True)
|
|
) == [category1.pk, category4.pk]
|
|
assert list(PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('order', flat=True)) == [
|
|
1,
|
|
2,
|
|
]
|
|
|
|
resp = app.get('/manage/pricing/%s/category/add/' % pricing.pk)
|
|
assert list(resp.context['form'].fields['category'].queryset) == [category2, category3]
|
|
resp.form['category'] = category2.pk
|
|
resp = resp.form.submit().follow()
|
|
assert '/manage/pricing/%s/category/add/' % pricing.pk not in resp
|
|
assert list(
|
|
PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('category', flat=True)
|
|
) == [category1.pk, category4.pk, category2.pk]
|
|
assert list(PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('order', flat=True)) == [
|
|
1,
|
|
2,
|
|
3,
|
|
]
|
|
|
|
app.get('/manage/pricing/%s/category/add/' % pricing.pk, status=404)
|
|
|
|
|
|
def test_pricing_add_category_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/category/add/' % pricing.pk, status=403)
|
|
|
|
|
|
def test_pricing_edit_category(app, admin_user):
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
criteria1 = Criteria.objects.create(label='Crit 1', category=category1)
|
|
criteria2 = Criteria.objects.create(label='Crit 2', category=category1)
|
|
criteria3 = Criteria.objects.create(label='Crit 3', category=category1)
|
|
criteria4 = Criteria.objects.create(label='Crit 4', category=category1)
|
|
category2 = CriteriaCategory.objects.create(label='cat 2')
|
|
criteria5 = Criteria.objects.create(label='Crit 5', category=category2)
|
|
pricing = Pricing.objects.create(label='Model')
|
|
pricing.categories.add(category1, through_defaults={'order': 1})
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.click(href='/manage/pricing/%s/category/%s/edit/' % (pricing.pk, category1.pk))
|
|
assert list(resp.context['form'].fields['criterias'].queryset) == [
|
|
criteria1,
|
|
criteria2,
|
|
criteria3,
|
|
criteria4,
|
|
]
|
|
assert list(resp.context['form'].initial['criterias']) == []
|
|
resp.form['criterias'] = [criteria1.pk, criteria3.pk]
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.follow()
|
|
assert list(pricing.criterias.order_by('pk')) == [criteria1, criteria3]
|
|
|
|
resp = app.get('/manage/pricing/%s/category/%s/edit/' % (pricing.pk, category1.pk))
|
|
assert list(resp.context['form'].initial['criterias']) == [criteria1, criteria3]
|
|
resp.form['criterias'] = [criteria1.pk, criteria4.pk]
|
|
resp = resp.form.submit().follow()
|
|
assert list(pricing.criterias.order_by('pk')) == [criteria1, criteria4]
|
|
|
|
resp = app.get('/manage/pricing/%s/category/%s/edit/' % (pricing.pk, category2.pk))
|
|
assert list(resp.context['form'].fields['criterias'].queryset) == [criteria5]
|
|
assert list(resp.context['form'].initial['criterias']) == []
|
|
resp.form['criterias'] = [criteria5.pk]
|
|
resp = resp.form.submit().follow()
|
|
assert list(pricing.criterias.order_by('pk')) == [criteria1, criteria4, criteria5]
|
|
|
|
|
|
def test_pricing_edit_category_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
category = CriteriaCategory.objects.create(label='Cat')
|
|
pricing.categories.add(category, through_defaults={'order': 1})
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/category/%s/edit/' % (pricing.pk, category.pk), status=403)
|
|
|
|
|
|
def test_pricing_delete_category(app, admin_user):
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
criteria1 = Criteria.objects.create(label='Crit 1', category=category1)
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
criteria2 = Criteria.objects.create(label='Crit 2', category=category2)
|
|
pricing = Pricing.objects.create(label='Model')
|
|
pricing.categories.add(category1, through_defaults={'order': 1})
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
pricing.criterias.add(criteria1, criteria2)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.click(href='/manage/pricing/%s/category/%s/delete/' % (pricing.pk, category1.pk))
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/%s/' % pricing.pk)
|
|
resp = resp.follow()
|
|
assert list(pricing.categories.all()) == [category2]
|
|
assert list(pricing.criterias.all()) == [criteria2]
|
|
|
|
# not linked
|
|
app.get('/manage/pricing/%s/category/%s/delete/' % (pricing.pk, category1.pk), status=404)
|
|
# unknown
|
|
app.get('/manage/pricing/%s/category/%s/delete/' % (pricing.pk, 0), status=404)
|
|
|
|
|
|
def test_pricing_delete_category_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
category = CriteriaCategory.objects.create(label='Cat')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/category/%s/delete/' % (pricing.pk, category.pk), status=403)
|
|
|
|
|
|
def test_pricing_reorder_categories(app, admin_user):
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
category4 = CriteriaCategory.objects.create(label='Cat 4')
|
|
pricing = Pricing.objects.create(label='Model')
|
|
pricing.categories.add(category1, through_defaults={'order': 1})
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
assert list(
|
|
PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('category', flat=True)
|
|
) == [category1.pk, category2.pk, category3.pk]
|
|
assert list(PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('order', flat=True)) == [
|
|
1,
|
|
2,
|
|
3,
|
|
]
|
|
|
|
app = login(app)
|
|
# missing get params
|
|
app.get('/manage/pricing/%s/order/' % (pricing.pk), status=400)
|
|
|
|
# bad new-order param
|
|
bad_params = [
|
|
# missing category3 in order
|
|
','.join(str(x) for x in [category1.pk, category2.pk]),
|
|
# category1 mentionned twice
|
|
','.join(str(x) for x in [category1.pk, category2.pk, category3.pk, category1.pk]),
|
|
# category4 not in pricing categories
|
|
','.join(str(x) for x in [category1.pk, category2.pk, category3.pk, category4.pk]),
|
|
# not an id
|
|
'foo,1,2,3',
|
|
' 1 ,2,3',
|
|
]
|
|
for bad_param in bad_params:
|
|
app.get(
|
|
'/manage/pricing/%s/order/' % (pricing.pk),
|
|
params={'new-order': bad_param},
|
|
status=400,
|
|
)
|
|
# not changed
|
|
assert list(
|
|
PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('category', flat=True)
|
|
) == [category1.pk, category2.pk, category3.pk]
|
|
assert list(PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('order', flat=True)) == [
|
|
1,
|
|
2,
|
|
3,
|
|
]
|
|
|
|
# change order
|
|
app.get(
|
|
'/manage/pricing/%s/order/' % (pricing.pk),
|
|
params={'new-order': ','.join(str(x) for x in [category3.pk, category1.pk, category2.pk])},
|
|
)
|
|
assert list(
|
|
PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('category', flat=True)
|
|
) == [category3.pk, category1.pk, category2.pk]
|
|
assert list(PricingCriteriaCategory.objects.filter(pricing=pricing).values_list('order', flat=True)) == [
|
|
1,
|
|
2,
|
|
3,
|
|
]
|
|
|
|
|
|
def test_pricing_reorder_categories_as_manager(app, manager_user):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/%s/order/' % (pricing.pk), status=403)
|
|
|
|
|
|
def test_list_criterias_as_manager(app, manager_user):
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criterias/', status=403)
|
|
|
|
|
|
def test_add_category(settings, app, admin_user):
|
|
app = login(app)
|
|
resp = app.get('/manage/')
|
|
resp = resp.click('Pricing')
|
|
resp = resp.click('Criterias')
|
|
resp = resp.click('New criteria category')
|
|
resp.form['label'] = 'QF'
|
|
resp = resp.form.submit()
|
|
category = CriteriaCategory.objects.latest('pk')
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
assert category.label == 'QF'
|
|
assert category.slug == 'qf'
|
|
|
|
|
|
def test_add_category_as_manager(app, manager_user):
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/add/', status=403)
|
|
|
|
|
|
def test_edit_category(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
category2 = CriteriaCategory.objects.create(label='Domicile')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/criterias/')
|
|
resp = resp.click(href='/manage/pricing/criteria/category/%s/edit/' % category.pk)
|
|
resp.form['label'] = 'QF Foo'
|
|
resp.form['slug'] = category2.slug
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['slug'] == ['Criteria category with this Identifier already exists.']
|
|
|
|
resp.form['slug'] = 'baz2'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
category.refresh_from_db()
|
|
assert category.label == 'QF Foo'
|
|
assert category.slug == 'baz2'
|
|
|
|
|
|
def test_edit_category_as_manager(app, manager_user):
|
|
category = CriteriaCategory.objects.create(label='Foo bar')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/%s/edit/' % category.pk, status=403)
|
|
|
|
|
|
def test_delete_category(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
Criteria.objects.create(label='QF 1', category=category)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/criterias/')
|
|
resp = resp.click(href='/manage/pricing/criteria/category/%s/delete/' % category.pk)
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
assert CriteriaCategory.objects.exists() is False
|
|
assert Criteria.objects.exists() is False
|
|
|
|
|
|
def test_delete_category_as_manager(app, manager_user):
|
|
category = CriteriaCategory.objects.create(label='Foo bar')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/%s/delete/' % category.pk, status=403)
|
|
|
|
|
|
def test_add_criteria(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/criterias/')
|
|
resp = resp.click('Add a criteria')
|
|
resp.form['label'] = 'QF < 1'
|
|
resp.form['condition'] = 'qf < 1 #'
|
|
assert 'slug' not in resp.context['form'].fields
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['condition'] == ['Invalid syntax.']
|
|
resp.form['condition'] = 'qf < 1'
|
|
resp = resp.form.submit()
|
|
criteria = Criteria.objects.latest('pk')
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
assert criteria.label == 'QF < 1'
|
|
assert criteria.category == category
|
|
assert criteria.slug == 'qf-1'
|
|
assert criteria.condition == 'qf < 1'
|
|
assert criteria.order == 1
|
|
|
|
resp = app.get('/manage/pricing/criteria/category/%s/add/' % category.pk)
|
|
resp.form['label'] = 'QF < 1'
|
|
resp.form['condition'] = 'qf < 1'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
criteria = Criteria.objects.latest('pk')
|
|
assert criteria.label == 'QF < 1'
|
|
assert criteria.category == category
|
|
assert criteria.slug == 'qf-1-1'
|
|
assert criteria.condition == 'qf < 1'
|
|
assert criteria.order == 2
|
|
|
|
|
|
def test_add_criteria_as_manager(app, manager_user):
|
|
category = CriteriaCategory.objects.create(label='Foo bar')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/%s/add/' % category.pk, status=403)
|
|
|
|
|
|
def test_edit_criteria(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
criteria = Criteria.objects.create(label='QF 1', category=category)
|
|
criteria2 = Criteria.objects.create(label='QF 2', category=category)
|
|
category2 = CriteriaCategory.objects.create(label='Foo')
|
|
criteria3 = Criteria.objects.create(label='foo-bar', category=category2)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/criterias/')
|
|
resp = resp.click(href='/manage/pricing/criteria/category/%s/%s/edit/' % (category.pk, criteria.pk))
|
|
resp.form['label'] = 'QF 1 bis'
|
|
resp.form['slug'] = criteria2.slug
|
|
resp.form['condition'] = 'qf <= 1 #'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['slug'] == ['Another criteria exists with the same identifier.']
|
|
assert resp.context['form'].errors['condition'] == ['Invalid syntax.']
|
|
|
|
resp.form['condition'] = 'qf <= 1'
|
|
resp.form['slug'] = criteria3.slug
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
criteria.refresh_from_db()
|
|
assert criteria.label == 'QF 1 bis'
|
|
assert criteria.slug == 'foo-bar'
|
|
assert criteria.condition == 'qf <= 1'
|
|
|
|
|
|
def test_edit_criteria_as_manager(app, manager_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
criteria = Criteria.objects.create(label='QF 1', category=category)
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/%s/%s/edit/' % (category.pk, criteria.pk), status=403)
|
|
|
|
|
|
def test_delete_criteria(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
criteria = Criteria.objects.create(label='QF 1', category=category)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/criterias/')
|
|
resp = resp.click(href='/manage/pricing/criteria/category/%s/%s/delete/' % (category.pk, criteria.pk))
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
assert CriteriaCategory.objects.exists() is True
|
|
assert Criteria.objects.exists() is False
|
|
|
|
|
|
def test_delete_criteria_as_manager(app, manager_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
criteria = Criteria.objects.create(label='QF 1', category=category)
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/%s/%s/delete/' % (category.pk, criteria.pk), status=403)
|
|
|
|
|
|
def test_reorder_criterias(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
criteria1 = Criteria.objects.create(label='QF 1', category=category)
|
|
criteria2 = Criteria.objects.create(label='QF 2', category=category)
|
|
criteria3 = Criteria.objects.create(label='QF 3', category=category)
|
|
criteria4 = Criteria.objects.create(label='QF 4', category=category)
|
|
assert list(category.criterias.values_list('pk', flat=True).order_by('order')) == [
|
|
criteria1.pk,
|
|
criteria2.pk,
|
|
criteria3.pk,
|
|
criteria4.pk,
|
|
]
|
|
assert list(category.criterias.values_list('order', flat=True).order_by('order')) == [1, 2, 3, 4]
|
|
|
|
app = login(app)
|
|
# missing get params
|
|
app.get('/manage/pricing/criteria/category/%s/order/' % (category.pk), status=400)
|
|
|
|
# bad new-order param
|
|
bad_params = [
|
|
# missing criteria3 in order
|
|
','.join(str(x) for x in [criteria1.pk, criteria2.pk, criteria4.pk]),
|
|
# criteria1 mentionned twice
|
|
','.join(str(x) for x in [criteria1.pk, criteria2.pk, criteria3.pk, criteria4.pk, criteria1.pk]),
|
|
# not an id
|
|
'foo,1,2,3,4',
|
|
' 1 ,2,3,4',
|
|
]
|
|
for bad_param in bad_params:
|
|
app.get(
|
|
'/manage/pricing/criteria/category/%s/order/' % (category.pk),
|
|
params={'new-order': bad_param},
|
|
status=400,
|
|
)
|
|
# not changed
|
|
assert list(category.criterias.values_list('pk', flat=True).order_by('order')) == [
|
|
criteria1.pk,
|
|
criteria2.pk,
|
|
criteria3.pk,
|
|
criteria4.pk,
|
|
]
|
|
assert list(category.criterias.values_list('order', flat=True).order_by('order')) == [1, 2, 3, 4]
|
|
|
|
# change order
|
|
app.get(
|
|
'/manage/pricing/criteria/category/%s/order/' % (category.pk),
|
|
params={
|
|
'new-order': ','.join(str(x) for x in [criteria3.pk, criteria1.pk, criteria4.pk, criteria2.pk])
|
|
},
|
|
)
|
|
assert list(category.criterias.values_list('pk', flat=True).order_by('order')) == [
|
|
criteria3.pk,
|
|
criteria1.pk,
|
|
criteria4.pk,
|
|
criteria2.pk,
|
|
]
|
|
assert list(category.criterias.values_list('order', flat=True).order_by('order')) == [1, 2, 3, 4]
|
|
|
|
|
|
def test_reorder_criterias_as_manager(app, manager_user):
|
|
category = CriteriaCategory.objects.create(label='QF')
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/criteria/category/%s/order/' % (category.pk), status=403)
|
|
|
|
|
|
@pytest.mark.freeze_time('2021-07-08')
|
|
def test_import_criteria_category(app, admin_user):
|
|
category = CriteriaCategory.objects.create(label='Foo bar')
|
|
Criteria.objects.create(label='Foo', category=category)
|
|
Criteria.objects.create(label='Baz', category=category)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/criteria/category/%s/export/' % category.id)
|
|
assert resp.headers['content-type'] == 'application/json'
|
|
assert (
|
|
resp.headers['content-disposition']
|
|
== 'attachment; filename="export_pricing_category_foo-bar_20210708.json"'
|
|
)
|
|
category_export = resp.text
|
|
|
|
# existing category
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload('export.json', category_export.encode('utf-8'), 'application/json')
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
resp = resp.follow()
|
|
assert (
|
|
'No pricing criteria category created. A pricing criteria category has been updated.' not in resp.text
|
|
)
|
|
assert CriteriaCategory.objects.count() == 1
|
|
assert Criteria.objects.count() == 2
|
|
|
|
# new category
|
|
CriteriaCategory.objects.all().delete()
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload('export.json', category_export.encode('utf-8'), 'application/json')
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/criterias/')
|
|
resp = resp.follow()
|
|
assert (
|
|
'A pricing criteria category has been created. No pricing criteria category updated.' not in resp.text
|
|
)
|
|
assert CriteriaCategory.objects.count() == 1
|
|
assert Criteria.objects.count() == 2
|
|
|
|
# multiple categories
|
|
categories = json.loads(category_export)
|
|
categories['pricing_categories'].append(copy.copy(categories['pricing_categories'][0]))
|
|
categories['pricing_categories'].append(copy.copy(categories['pricing_categories'][0]))
|
|
categories['pricing_categories'][1]['label'] = 'Foo bar 2'
|
|
categories['pricing_categories'][1]['slug'] = 'foo-bar-2'
|
|
categories['pricing_categories'][2]['label'] = 'Foo bar 3'
|
|
categories['pricing_categories'][2]['slug'] = 'foo-bar-3'
|
|
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload(
|
|
'export.json', json.dumps(categories).encode('utf-8'), 'application/json'
|
|
)
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/')
|
|
resp = resp.follow()
|
|
assert (
|
|
'2 pricing criteria categories have been created. A pricing criteria category has been updated.'
|
|
in resp.text
|
|
)
|
|
assert CriteriaCategory.objects.count() == 3
|
|
assert Criteria.objects.count() == 6
|
|
|
|
CriteriaCategory.objects.all().delete()
|
|
resp = app.get('/manage/', status=200)
|
|
resp = resp.click('Import')
|
|
resp.form['agendas_json'] = Upload(
|
|
'export.json', json.dumps(categories).encode('utf-8'), 'application/json'
|
|
)
|
|
resp = resp.form.submit().follow()
|
|
assert (
|
|
'3 pricing criteria categories have been created. No pricing criteria category updated.' in resp.text
|
|
)
|
|
assert CriteriaCategory.objects.count() == 3
|
|
assert Criteria.objects.count() == 6
|
|
|
|
|
|
def test_add_agenda_pricing(settings, app, admin_user):
|
|
agenda = Agenda.objects.create(label='Foo Bar')
|
|
pricing = Pricing.objects.create(label='Model')
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/agendas/%s/settings' % agenda.pk)
|
|
resp = resp.click('New pricing')
|
|
resp.form['pricing'] = pricing.pk
|
|
resp.form['date_start'] = '2021-09-01'
|
|
resp.form['date_end'] = '2021-09-01'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['date_end'] == ['End date must be greater than start date.']
|
|
resp.form['date_end'] = '2022-09-01'
|
|
resp = resp.form.submit()
|
|
agenda_pricing = AgendaPricing.objects.latest('pk')
|
|
assert resp.location.endswith('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
assert agenda_pricing.pricing == pricing
|
|
assert agenda_pricing.agenda == agenda
|
|
assert agenda_pricing.date_start == datetime.date(2021, 9, 1)
|
|
assert agenda_pricing.date_end == datetime.date(2022, 9, 1)
|
|
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/add/' % agenda.pk)
|
|
resp.form['pricing'] = pricing.pk
|
|
resp.form['date_start'] = '2021-11-01'
|
|
resp.form['date_end'] = '2022-11-01'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['__all__'] == ['Pricing overlaps existing pricings.']
|
|
resp.form['date_start'] = '2022-09-01'
|
|
resp.form['date_end'] = '2023-09-01'
|
|
resp = resp.form.submit()
|
|
agenda_pricing = AgendaPricing.objects.latest('pk')
|
|
assert agenda_pricing.pricing == pricing
|
|
assert agenda_pricing.agenda == agenda
|
|
assert agenda_pricing.date_start == datetime.date(2022, 9, 1)
|
|
assert agenda_pricing.date_end == datetime.date(2023, 9, 1)
|
|
|
|
settings.CHRONO_ENABLE_PRICING = False
|
|
resp = app.get('/manage/')
|
|
resp = app.get('/manage/agendas/%s/settings' % agenda.pk)
|
|
assert 'New pricing' not in resp
|
|
|
|
|
|
def test_add_agenda_pricing_as_manager(app, manager_user, agenda_with_restrictions):
|
|
app = login(app, username='manager', password='manager')
|
|
app.get('/manage/pricing/agenda/%s/pricing/add/' % agenda_with_restrictions.pk, status=403)
|
|
|
|
|
|
def test_edit_agenda_pricing(app, admin_user):
|
|
agenda = Agenda.objects.create(label='Foo Bar')
|
|
pricing = Pricing.objects.create(label='Model')
|
|
pricing2 = Pricing.objects.create(label='Model 2')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
agenda2 = Agenda.objects.create(label='Foo Bar')
|
|
agenda_pricing2 = AgendaPricing.objects.create(
|
|
agenda=agenda2,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2022, month=9, day=1),
|
|
date_end=datetime.date(year=2023, month=9, day=1),
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
resp = resp.click(href='/manage/pricing/agenda/%s/pricing/%s/edit/' % (agenda.pk, agenda_pricing.pk))
|
|
resp.form['pricing'] = pricing2.pk
|
|
resp.form['date_start'] = '2021-09-01'
|
|
resp.form['date_end'] = '2021-09-01'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['date_end'] == ['End date must be greater than start date.']
|
|
resp.form['date_start'] = '2021-11-01'
|
|
resp.form['date_end'] = '2022-11-01'
|
|
resp = resp.form.submit()
|
|
assert resp.context['form'].errors['__all__'] == ['Pricing overlaps existing pricings.']
|
|
resp.form['date_start'] = '2021-08-01'
|
|
resp.form['date_end'] = '2022-09-01'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
agenda_pricing.refresh_from_db()
|
|
assert agenda_pricing.pricing == pricing2
|
|
assert agenda_pricing.agenda == agenda
|
|
assert agenda_pricing.date_start == datetime.date(2021, 8, 1)
|
|
assert agenda_pricing.date_end == datetime.date(2022, 9, 1)
|
|
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/edit/' % (agenda.pk, agenda_pricing2.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/edit/' % (0, agenda_pricing.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/edit/' % (agenda.pk, 0), status=404)
|
|
# wrong kind
|
|
for kind in ['meetings', 'virtual']:
|
|
agenda.kind = kind
|
|
agenda.save()
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/edit/' % (agenda.pk, agenda_pricing.pk), status=404)
|
|
|
|
|
|
def test_edit_agenda_pricing_as_manager(app, manager_user, agenda_with_restrictions):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda_with_restrictions,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
)
|
|
app = login(app, username='manager', password='manager')
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/edit/' % (agenda_with_restrictions.pk, agenda_pricing.pk),
|
|
status=403,
|
|
)
|
|
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda_with_restrictions.pk, agenda_pricing.pk))
|
|
assert (
|
|
'/manage/pricing/agenda/%s/pricing/%s/edit/' % (agenda_with_restrictions.pk, agenda_pricing.pk)
|
|
not in resp
|
|
)
|
|
|
|
|
|
def test_delete_agenda_pricing_as_manager(app, manager_user, agenda_with_restrictions):
|
|
pricing = Pricing.objects.create(label='Model')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda_with_restrictions,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
)
|
|
app = login(app, username='manager', password='manager')
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/delete/' % (agenda_with_restrictions.pk, agenda_pricing.pk),
|
|
status=403,
|
|
)
|
|
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda_with_restrictions.pk, agenda_pricing.pk))
|
|
assert (
|
|
'/manage/pricing/agenda/%s/pricing/%s/delete/' % (agenda_with_restrictions.pk, agenda_pricing.pk)
|
|
not in resp
|
|
)
|
|
|
|
|
|
def test_delete_agenda_pricing(app, admin_user):
|
|
agenda = Agenda.objects.create(label='Foo Bar')
|
|
pricing = Pricing.objects.create(label='Model')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
agenda2 = Agenda.objects.create(label='Foo Bar')
|
|
agenda_pricing2 = AgendaPricing.objects.create(
|
|
agenda=agenda2,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
|
|
app = login(app)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/delete/' % (agenda.pk, agenda_pricing2.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/delete/' % (0, agenda_pricing.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/delete/' % (agenda.pk, 0), status=404)
|
|
# wrong kind
|
|
for kind in ['meetings', 'virtual']:
|
|
agenda.kind = kind
|
|
agenda.save()
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/delete/' % (agenda.pk, agenda_pricing.pk), status=404)
|
|
|
|
agenda.kind = 'events'
|
|
agenda.save()
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
resp = resp.click(href='/manage/pricing/agenda/%s/pricing/%s/delete/' % (agenda.pk, agenda_pricing.pk))
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/agendas/%s/settings' % agenda.pk)
|
|
assert AgendaPricing.objects.filter(pk=agenda_pricing.pk).exists() is False
|
|
|
|
|
|
def test_detail_agenda_pricing(app, admin_user):
|
|
agenda = Agenda.objects.create(label='Foo Bar')
|
|
pricing = Pricing.objects.create(label='Model')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
)
|
|
agenda2 = Agenda.objects.create(label='Foo Bar')
|
|
agenda_pricing2 = AgendaPricing.objects.create(
|
|
agenda=agenda2,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/agendas/%s/settings' % agenda.pk)
|
|
resp = resp.click(href='/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing2.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/' % (0, agenda_pricing.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, 0), status=404)
|
|
# wrong kind
|
|
for kind in ['meetings', 'virtual']:
|
|
agenda.kind = kind
|
|
agenda.save()
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk), status=404)
|
|
|
|
|
|
def test_detail_agenda_pricing_3_categories(app, admin_user):
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
Criteria.objects.create(label='Crit 1-1', slug='crit-1-1', category=category1, order=1)
|
|
Criteria.objects.create(label='Crit 1-2', slug='crit-1-2', category=category1, order=2)
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
Criteria.objects.create(label='Crit 2-1', slug='crit-2-1', category=category2, order=1)
|
|
Criteria.objects.create(label='Crit 2-2', slug='crit-2-2', category=category2, order=2)
|
|
Criteria.objects.create(label='Crit 2-3', slug='crit-2-3', category=category2, order=3)
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
|
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
|
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
|
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
pricing.categories.add(category1, through_defaults={'order': 1})
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
pricing_data={
|
|
'cat-1:crit-1-1': {
|
|
'cat-2:crit-2-1': {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-3': 'not-a-decimal',
|
|
'cat-3:crit-3-4': 114,
|
|
},
|
|
'cat-2:crit-2-3': {
|
|
'cat-3:crit-3-2': 132,
|
|
},
|
|
},
|
|
'cat-1:crit-1-2': {
|
|
'cat-2:crit-2-2': {
|
|
'cat-3:crit-3-3': 223,
|
|
},
|
|
},
|
|
},
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
assert '<h3>Crit 1-1</h3>' in resp
|
|
ths = resp.pyquery.find('table.pricing-matrix-crit-1-1 thead th')
|
|
assert len(ths) == 4
|
|
assert ths[0].text is None
|
|
assert ths[1].text == 'Crit 2-1'
|
|
assert ths[2].text == 'Crit 2-2'
|
|
assert ths[3].text == 'Crit 2-3'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1')[
|
|
0
|
|
].text
|
|
== '111.00'
|
|
)
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-1')[
|
|
0
|
|
].text
|
|
is None
|
|
) # not defined
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-1')[
|
|
0
|
|
].text
|
|
is None
|
|
) # wrong value
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1')[
|
|
0
|
|
].text
|
|
== '114.00'
|
|
)
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-1 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[
|
|
0
|
|
].text
|
|
== '132.00'
|
|
)
|
|
assert '<h3>Crit 1-2</h3>' in resp
|
|
ths = resp.pyquery.find('table.pricing-matrix-crit-1-2 thead th')
|
|
assert len(ths) == 4
|
|
assert ths[0].text is None
|
|
assert ths[1].text == 'Crit 2-1'
|
|
assert ths[2].text == 'Crit 2-2'
|
|
assert ths[3].text == 'Crit 2-3'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
|
assert resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-2')[
|
|
0
|
|
].text
|
|
is None
|
|
) # not defined
|
|
assert (
|
|
resp.pyquery.find('table.pricing-matrix-crit-1-2 tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-2')[
|
|
0
|
|
].text
|
|
== '223.00'
|
|
)
|
|
|
|
|
|
def test_detail_agenda_pricing_2_categories(app, admin_user):
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
Criteria.objects.create(label='Crit 2-1', slug='crit-2-1', category=category2, order=1)
|
|
Criteria.objects.create(label='Crit 2-2', slug='crit-2-2', category=category2, order=2)
|
|
Criteria.objects.create(label='Crit 2-3', slug='crit-2-3', category=category2, order=3)
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
|
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
|
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
|
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
pricing_data={
|
|
'cat-2:crit-2-1': {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-3': 'not-a-decimal',
|
|
'cat-3:crit-3-4': 114,
|
|
},
|
|
'cat-2:crit-2-3': {
|
|
'cat-3:crit-3-2': 132,
|
|
},
|
|
},
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
assert '<h3>' not in resp
|
|
ths = resp.pyquery.find('table thead th')
|
|
assert len(ths) == 4
|
|
assert ths[0].text is None
|
|
assert ths[1].text == 'Crit 2-1'
|
|
assert ths[2].text == 'Crit 2-2'
|
|
assert ths[3].text == 'Crit 2-3'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 td.pricing-cell-crit-2-1')[0].text == '111.00'
|
|
assert (
|
|
resp.pyquery.find('table tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-1')[0].text is None
|
|
) # not defined
|
|
assert (
|
|
resp.pyquery.find('table tr.pricing-row-crit-3-3 td.pricing-cell-crit-2-1')[0].text is None
|
|
) # wrong value
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 td.pricing-cell-crit-2-1')[0].text == '114.00'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 td.pricing-cell-crit-2-3')[0].text == '132.00'
|
|
|
|
|
|
def test_detail_agenda_pricing_1_category(app, admin_user):
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
|
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
|
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
|
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
pricing_data={
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-3': 'not-a-decimal',
|
|
'cat-3:crit-3-4': 114,
|
|
},
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
assert '<h3>' not in resp
|
|
ths = resp.pyquery.find('table thead')
|
|
assert len(ths) == 0
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 th')[0].text == 'Crit 3-1'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 th')[0].text == 'Crit 3-2'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-3 th')[0].text == 'Crit 3-3'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 th')[0].text == 'Crit 3-4'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-1 td')[0].text == '111.00'
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-2 td')[0].text is None # not defined
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-3 td')[0].text is None # wrong value
|
|
assert resp.pyquery.find('table tr.pricing-row-crit-3-4 td')[0].text == '114.00'
|
|
|
|
|
|
def test_edit_agenda_pricing_matrix_3_categories(app, admin_user):
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
criteria11 = Criteria.objects.create(label='Crit 1-1', slug='crit-1-1', category=category1, order=1)
|
|
criteria12 = Criteria.objects.create(label='Crit 1-2', slug='crit-1-2', category=category1, order=2)
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
criteria21 = Criteria.objects.create(label='Crit 2-1', slug='crit-2-1', category=category2, order=1)
|
|
Criteria.objects.create(label='Crit 2-2', slug='crit-2-2', category=category2, order=2)
|
|
Criteria.objects.create(label='Crit 2-3', slug='crit-2-3', category=category2, order=3)
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
criteria31 = Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
|
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
|
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
|
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
pricing.categories.add(category1, through_defaults={'order': 1})
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
pricing_data={
|
|
'cat-1:crit-1-1': {
|
|
'cat-2:crit-2-1': {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-3': 'not-a-decimal',
|
|
'cat-3:crit-3-4': 114,
|
|
},
|
|
'cat-2:crit-2-3': {
|
|
'cat-3:crit-3-2': 132,
|
|
},
|
|
},
|
|
'cat-1:crit-1-2': {
|
|
'cat-2:crit-2-2': {
|
|
'cat-3:crit-3-3': 223,
|
|
},
|
|
},
|
|
},
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
resp = resp.click(
|
|
href='/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria11.slug)
|
|
)
|
|
assert resp.form['form-0-crit_0'].value == '111'
|
|
assert resp.form['form-0-crit_1'].value == ''
|
|
assert resp.form['form-0-crit_2'].value == ''
|
|
assert resp.form['form-1-crit_0'].value == ''
|
|
assert resp.form['form-1-crit_1'].value == ''
|
|
assert resp.form['form-1-crit_2'].value == '132'
|
|
assert resp.form['form-2-crit_0'].value == ''
|
|
assert resp.form['form-2-crit_1'].value == ''
|
|
assert resp.form['form-2-crit_2'].value == ''
|
|
assert resp.form['form-3-crit_0'].value == '114'
|
|
assert resp.form['form-3-crit_1'].value == ''
|
|
assert resp.form['form-3-crit_2'].value == ''
|
|
resp.form['form-0-crit_1'] = '121'
|
|
resp.form['form-0-crit_2'] = '131'
|
|
resp.form['form-1-crit_0'] = '112'
|
|
resp.form['form-1-crit_1'] = '122'
|
|
resp.form['form-1-crit_2'] = '132.5'
|
|
resp.form['form-2-crit_0'] = '113'
|
|
resp.form['form-2-crit_1'] = '123'
|
|
resp.form['form-2-crit_2'] = '133'
|
|
resp.form['form-3-crit_0'] = '914'
|
|
resp.form['form-3-crit_1'] = '124'
|
|
resp.form['form-3-crit_2'] = '134'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
agenda_pricing.refresh_from_db()
|
|
assert agenda_pricing.pricing_data == {
|
|
'cat-1:crit-1-1': {
|
|
'cat-2:crit-2-1': {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-2': 112,
|
|
'cat-3:crit-3-3': 113,
|
|
'cat-3:crit-3-4': 914,
|
|
},
|
|
'cat-2:crit-2-2': {
|
|
'cat-3:crit-3-1': 121,
|
|
'cat-3:crit-3-2': 122,
|
|
'cat-3:crit-3-3': 123,
|
|
'cat-3:crit-3-4': 124,
|
|
},
|
|
'cat-2:crit-2-3': {
|
|
'cat-3:crit-3-1': 131,
|
|
'cat-3:crit-3-2': 132.5,
|
|
'cat-3:crit-3-3': 133,
|
|
'cat-3:crit-3-4': 134,
|
|
},
|
|
},
|
|
'cat-1:crit-1-2': {
|
|
'cat-2:crit-2-2': {
|
|
'cat-3:crit-3-3': 223,
|
|
},
|
|
},
|
|
}
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria12.slug),
|
|
status=200,
|
|
)
|
|
|
|
agenda2 = Agenda.objects.create(label='Foo Bar')
|
|
agenda_pricing2 = AgendaPricing.objects.create(
|
|
agenda=agenda2,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing2.pk, criteria11.slug),
|
|
status=404,
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/' % (0, agenda_pricing.pk, criteria11.slug),
|
|
status=404,
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/' % (agenda.pk, 0, criteria11.slug), status=404
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/' % (agenda.pk, agenda_pricing.pk, 'unknown'),
|
|
status=404,
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria21.slug),
|
|
status=404,
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria31.slug),
|
|
status=404,
|
|
)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing.pk), status=404)
|
|
# wrong kind
|
|
for kind in ['meetings', 'virtual']:
|
|
agenda.kind = kind
|
|
agenda.save()
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria11.slug),
|
|
status=404,
|
|
)
|
|
|
|
|
|
def test_edit_agenda_pricing_matrix_2_categories(app, admin_user):
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
criteria21 = Criteria.objects.create(label='Crit 2-1', slug='crit-2-1', category=category2, order=1)
|
|
Criteria.objects.create(label='Crit 2-2', slug='crit-2-2', category=category2, order=2)
|
|
Criteria.objects.create(label='Crit 2-3', slug='crit-2-3', category=category2, order=3)
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
criteria31 = Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
|
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
|
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
|
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
pricing_data={
|
|
'cat-2:crit-2-1': {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-3': 'not-a-decimal',
|
|
'cat-3:crit-3-4': 114,
|
|
},
|
|
'cat-2:crit-2-3': {
|
|
'cat-3:crit-3-2': 132,
|
|
},
|
|
},
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
resp = resp.click(
|
|
href='/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing.pk)
|
|
)
|
|
assert resp.form['form-0-crit_0'].value == '111'
|
|
assert resp.form['form-0-crit_1'].value == ''
|
|
assert resp.form['form-0-crit_2'].value == ''
|
|
assert resp.form['form-1-crit_0'].value == ''
|
|
assert resp.form['form-1-crit_1'].value == ''
|
|
assert resp.form['form-1-crit_2'].value == '132'
|
|
assert resp.form['form-2-crit_0'].value == ''
|
|
assert resp.form['form-2-crit_1'].value == ''
|
|
assert resp.form['form-2-crit_2'].value == ''
|
|
assert resp.form['form-3-crit_0'].value == '114'
|
|
assert resp.form['form-3-crit_1'].value == ''
|
|
assert resp.form['form-3-crit_2'].value == ''
|
|
resp.form['form-0-crit_1'] = '121'
|
|
resp.form['form-0-crit_2'] = '131'
|
|
resp.form['form-1-crit_0'] = '112'
|
|
resp.form['form-1-crit_1'] = '122'
|
|
resp.form['form-1-crit_2'] = '132.5'
|
|
resp.form['form-2-crit_0'] = '113'
|
|
resp.form['form-2-crit_1'] = '123'
|
|
resp.form['form-2-crit_2'] = '133'
|
|
resp.form['form-3-crit_0'] = '914'
|
|
resp.form['form-3-crit_1'] = '124'
|
|
resp.form['form-3-crit_2'] = '134'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
agenda_pricing.refresh_from_db()
|
|
assert agenda_pricing.pricing_data == {
|
|
'cat-2:crit-2-1': {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-2': 112,
|
|
'cat-3:crit-3-3': 113,
|
|
'cat-3:crit-3-4': 914,
|
|
},
|
|
'cat-2:crit-2-2': {
|
|
'cat-3:crit-3-1': 121,
|
|
'cat-3:crit-3-2': 122,
|
|
'cat-3:crit-3-3': 123,
|
|
'cat-3:crit-3-4': 124,
|
|
},
|
|
'cat-2:crit-2-3': {
|
|
'cat-3:crit-3-1': 131,
|
|
'cat-3:crit-3-2': 132.5,
|
|
'cat-3:crit-3-3': 133,
|
|
'cat-3:crit-3-4': 134,
|
|
},
|
|
}
|
|
|
|
agenda2 = Agenda.objects.create(label='Foo Bar')
|
|
agenda_pricing2 = AgendaPricing.objects.create(
|
|
agenda=agenda2,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing2.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (0, agenda_pricing.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, 0), status=404)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria21.slug),
|
|
status=404,
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria31.slug),
|
|
status=404,
|
|
)
|
|
# wrong kind
|
|
for kind in ['meetings', 'virtual']:
|
|
agenda.kind = kind
|
|
agenda.save()
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing.pk), status=404
|
|
)
|
|
|
|
|
|
def test_edit_agenda_pricing_matrix_1_category(app, admin_user):
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
criteria31 = Criteria.objects.create(label='Crit 3-1', slug='crit-3-1', category=category3, order=1)
|
|
Criteria.objects.create(label='Crit 3-3', slug='crit-3-3', category=category3, order=3)
|
|
Criteria.objects.create(label='Crit 3-4', slug='crit-3-4', category=category3, order=4)
|
|
Criteria.objects.create(label='Crit 3-2', slug='crit-3-2', category=category3, order=2)
|
|
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
pricing_data={
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-3': 'not-a-decimal',
|
|
'cat-3:crit-3-4': 114,
|
|
},
|
|
)
|
|
|
|
app = login(app)
|
|
resp = app.get('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
resp = resp.click(
|
|
href='/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing.pk)
|
|
)
|
|
assert resp.form['form-0-crit_0'].value == '111'
|
|
assert resp.form['form-1-crit_0'].value == ''
|
|
assert resp.form['form-2-crit_0'].value == ''
|
|
assert resp.form['form-3-crit_0'].value == '114'
|
|
resp.form['form-1-crit_0'] = '112.5'
|
|
resp.form['form-2-crit_0'] = '113'
|
|
resp.form['form-3-crit_0'] = '914'
|
|
resp = resp.form.submit()
|
|
assert resp.location.endswith('/manage/pricing/agenda/%s/pricing/%s/' % (agenda.pk, agenda_pricing.pk))
|
|
agenda_pricing.refresh_from_db()
|
|
assert agenda_pricing.pricing_data == {
|
|
'cat-3:crit-3-1': 111,
|
|
'cat-3:crit-3-2': 112.5,
|
|
'cat-3:crit-3-3': 113,
|
|
'cat-3:crit-3-4': 914,
|
|
}
|
|
|
|
agenda2 = Agenda.objects.create(label='Foo Bar')
|
|
agenda_pricing2 = AgendaPricing.objects.create(
|
|
agenda=agenda2,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2022, month=9, day=1),
|
|
)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing2.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (0, agenda_pricing.pk), status=404)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, 0), status=404)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda.pk, agenda_pricing.pk, criteria31.slug),
|
|
status=404,
|
|
)
|
|
# wrong kind
|
|
for kind in ['meetings', 'virtual']:
|
|
agenda.kind = kind
|
|
agenda.save()
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing.pk), status=404
|
|
)
|
|
|
|
|
|
def test_edit_agenda_pricing_matrix_empty(app, admin_user):
|
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
pricing = Pricing.objects.create(label='Foo bar')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
)
|
|
|
|
app = login(app)
|
|
app.get('/manage/pricing/agenda/%s/pricing/%s/matrix/edit/' % (agenda.pk, agenda_pricing.pk), status=404)
|
|
|
|
|
|
def test_edit_agenda_pricing_matrix_as_manager(app, manager_user, agenda_with_restrictions):
|
|
category1 = CriteriaCategory.objects.create(label='Cat 1')
|
|
Criteria.objects.create(label='Crit 1-1', slug='crit-1-1', category=category1, order=1)
|
|
Criteria.objects.create(label='Crit 1-2', slug='crit-1-2', category=category1, order=2)
|
|
category2 = CriteriaCategory.objects.create(label='Cat 2')
|
|
category3 = CriteriaCategory.objects.create(label='Cat 3')
|
|
pricing = Pricing.objects.create(label='Model')
|
|
agenda_pricing = AgendaPricing.objects.create(
|
|
agenda=agenda_with_restrictions,
|
|
pricing=pricing,
|
|
date_start=datetime.date(year=2021, month=9, day=1),
|
|
date_end=datetime.date(year=2021, month=10, day=1),
|
|
)
|
|
pricing.categories.add(category1, through_defaults={'order': 1})
|
|
pricing.criterias.set(Criteria.objects.all())
|
|
|
|
def check():
|
|
resp = app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/' % (agenda_with_restrictions.pk, agenda_pricing.pk)
|
|
)
|
|
assert (
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/edit/'
|
|
% (agenda_with_restrictions.pk, agenda_pricing.pk)
|
|
not in resp
|
|
)
|
|
for slug in ['crit-1-1', 'crit-1-2']:
|
|
assert (
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/%s/edit/'
|
|
% (agenda_with_restrictions.pk, agenda_pricing.pk, slug)
|
|
not in resp
|
|
)
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/edit/'
|
|
% (agenda_with_restrictions.pk, agenda_pricing.pk),
|
|
status=403,
|
|
)
|
|
check()
|
|
|
|
pricing.categories.add(category2, through_defaults={'order': 2})
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/edit/'
|
|
% (agenda_with_restrictions.pk, agenda_pricing.pk),
|
|
status=403,
|
|
)
|
|
check()
|
|
|
|
pricing.categories.add(category3, through_defaults={'order': 3})
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/crit-1-1/edit/'
|
|
% (agenda_with_restrictions.pk, agenda_pricing.pk),
|
|
status=403,
|
|
)
|
|
app.get(
|
|
'/manage/pricing/agenda/%s/pricing/%s/matrix/crit-1-2/edit/'
|
|
% (agenda_with_restrictions.pk, agenda_pricing.pk),
|
|
status=403,
|
|
)
|
|
check()
|