def test_payment_types(session): payment_types = PaymentTypeCollection(session) payment_type = payment_types.add(name='normal', _price_per_quantity=700) assert payment_type.name == 'normal' assert payment_type._price_per_quantity == 700 assert payment_type.price_per_quantity == 7.0
def editbar_links(self): result = [] model = PaymentTypeCollection(self.request.session) if self.request.has_permission(model, EditModel): result.append( Link(text=_("Manage payment types"), url=self.request.link(model), attrs={'class': 'payment-icon'})) return result
def test_municipality_form(session): payment_types = PaymentTypeCollection(session) payment_types.add(name='normal', _price_per_quantity=700) payment_types.add(name='spezial', _price_per_quantity=850) municipalities = MunicipalityCollection(session) municipality = municipalities.add(name="Boppelsen", bfs_number=82, payment_type='normal') # Test choices form = MunicipalityForm() form.request = Request(session) form.on_request() assert form.payment_type.choices == [('normal', 'Normal'), ('spezial', 'Spezial')] # Test apply / update form.apply_model(municipality) assert form.name.data == "Boppelsen" assert form.bfs_number.data == 82 assert form.address_supplement.data is None assert form.gpn_number.data is None assert form.payment_type.data == 'normal' form.name.data = "Adlikon" form.bfs_number.data = 21 form.address_supplement.data = "Zusatz" form.gpn_number.data = 1122 form.payment_type.data = 'spezial' form.update_model(municipality) assert municipality.name == "Adlikon" assert municipality.bfs_number == 21 assert municipality.address_supplement == "Zusatz" assert municipality.gpn_number == 1122 assert municipality.payment_type == 'spezial' # Test validation form = MunicipalityForm() form.request = Request(session) form.on_request() assert not form.validate() form = MunicipalityForm(PostData({ 'bfs_number': '82', })) form.request = Request(session) form.on_request() assert not form.validate() form = MunicipalityForm( PostData({ 'name': "Boppelsen", 'bfs_number': '82', 'payment_type': 'normal' })) form.request = Request(session) form.on_request() assert form.validate()
def test_payments_type_layouts(session): request = DummyRequest() request_admin = DummyRequest(roles=['admin']) model = PaymentTypeCollection(session) layout = PaymentTypesLayout(model, request) assert layout.title == 'Manage payment types' assert layout.editbar_links == [] assert path(layout.breadcrumbs) == 'DummyPrincipal/PaymentTypeCollection' assert layout.cancel_url == 'Invoice/' assert layout.success_url == 'Invoice/' layout = PaymentTypesLayout(model, request_admin) assert layout.editbar_links == []
def test_payments_form(session): model = PaymentTypeCollection(session) request = Request(session) form = PaymentTypesForm.get_form_class(model, request)() assert [field for field in form] == [] model.add(name='normal', _price_per_quantity=700) model.add(name='spezial', _price_per_quantity=850) form = PaymentTypesForm.get_form_class(model, request)() assert [(field.name, field.type) for field in form] == [('normal', 'FloatField'), ('spezial', 'FloatField')] # Test apply / update form.apply_model(model) assert form.normal.data == 7.0 assert form.spezial.data == 8.5 form.normal.data = 8.0 form.spezial.data = 9 form.update_model(model) assert {r.name: r.price_per_quantity for r in model.query()} == { 'normal': 8.0, 'spezial': 9.0 } # Test validation form = PaymentTypesForm.get_form_class(model, request)(PostData({ 'normal': 10.0, 'spezial': 12.6, })) form.request = Request(session) assert form.validate()
def test_permissions(wtfs_app, wtfs_password): session = wtfs_app.session() def permits(user, model, permission): return permits_by_app(wtfs_app, user, model, permission) # Remove existing users and group session.query(User).filter_by(realname='Editor').one().group_id = None session.query(User).filter_by(realname='Member').one().group_id = None session.query(Municipality).delete() # Add new municipality_a_id = uuid4() session.add(Municipality( id=municipality_a_id, name='Municipality A', bfs_number=10, )) session.add(PickupDate( date=date.today(), municipality_id=municipality_a_id, )) session.add(ScanJob( type='normal', municipality_id=municipality_a_id, delivery_number=1, dispatch_date=date(2019, 1, 1)) ) session.add(User( realname='Admin A', username='******', password_hash=wtfs_password, role='admin', group_id=municipality_a_id )) session.add(User( realname='Editor A', username='******', password_hash=wtfs_password, role='editor', group_id=municipality_a_id )) session.add(User( realname='Member A', username='******', password_hash=wtfs_password, role='member', group_id=municipality_a_id )) municipality_b_id = uuid4() session.add(Municipality( id=municipality_b_id, name='Municipality B', bfs_number=20, )) session.add(User( realname='Admin B', username='******', password_hash=wtfs_password, role='admin', group_id=municipality_b_id )) session.add(User( realname='Editor B', username='******', password_hash=wtfs_password, role='editor', group_id=municipality_b_id )) session.add(User( realname='Member B', username='******', password_hash=wtfs_password, role='member', group_id=municipality_b_id )) query = session.query admin = query(User).filter_by(realname='Admin').one() admin_a = query(User).filter_by(realname='Admin A').one() admin_b = query(User).filter_by(realname='Admin B').one() editor = query(User).filter_by(realname='Editor').one() editor_a = query(User).filter_by(realname='Editor A').one() editor_b = query(User).filter_by(realname='Editor B').one() member = query(User).filter_by(realname='Member').one() member_a = query(User).filter_by(realname='Member A').one() member_b = query(User).filter_by(realname='Member B').one() group = UserGroup() group_a = query(UserGroup).filter_by(name='Municipality A').one() group_b = query(UserGroup).filter_by(name='Municipality B').one() municipality = Municipality() municipality_a = query(Municipality).filter_by(name='Municipality A').one() municipality_b = query(Municipality).filter_by(name='Municipality B').one() scan_job = query(ScanJob).one() # General model = object() for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # UserGroupCollection / MunicipalityCollection # MunicipalityCollection for model in ( MunicipalityCollection(session), UserGroupCollection(session) ): for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # UserGroup / Municipality for user in (admin, admin_a, admin_b): for model in (group_a, group_b, municipality_a, municipality_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for model in (group, municipality): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): for model in ( group_a, group_b, group, municipality_a, municipality_b, municipality ): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # UserCollection model = UserCollection(session) for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # User for user in (admin, admin_a, admin_b): for model in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) if user == model: assert not permits(user, model, DeleteModel) else: assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for model in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, ): for model in (admin, admin_a, admin_b, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (editor, ): for model in (editor, ): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (editor_a, ): for model in (admin, admin_a, admin_b, editor, editor_b, member, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for model in (editor_a, ): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for model in (member_a,): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (editor_b, ): for model in (admin, admin_a, admin_b, editor, editor_a, member, member_a): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for model in (editor_b, ): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for model in (member_b,): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (member, member_a, member_b): for model in (admin, admin_a, admin_b, editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # ScanJobCollection model = ScanJobCollection(session) for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor_a, editor_b, member_a, member_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (editor, member): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # ScanJob model = scan_job for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_b, member, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (editor_a, member_a): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # DailyList for model in (DailyList(), DailyListBoxes(session)): for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for user in (member,): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) for model in (DailyListBoxesAndForms(session), ): for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # Report for model in ( Report(session), ReportBoxes(session), ReportBoxesAndForms(session), ReportFormsByMunicipality(session) ): for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # Notification model = Notification() for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # Invoice model = Invoice(session) for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # PaymentType model = PaymentType() for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # PaymentTypeCollection model = PaymentTypeCollection(session) for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert not permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted) # UserManual model = UserManual(wtfs_app) for user in (admin, admin_a, admin_b): assert permits(user, model, Public) assert permits(user, model, AddModel) assert permits(user, model, AddModelUnrestricted) assert permits(user, model, EditModel) assert permits(user, model, EditModelUnrestricted) assert permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert permits(user, model, ViewModelUnrestricted) for user in (editor, editor_a, editor_b, member, member_a, member_b): assert permits(user, model, Public) assert not permits(user, model, AddModel) assert not permits(user, model, AddModelUnrestricted) assert not permits(user, model, EditModel) assert not permits(user, model, EditModelUnrestricted) assert not permits(user, model, DeleteModel) assert permits(user, model, ViewModel) assert not permits(user, model, ViewModelUnrestricted)
def payment_types_url(self): return self.request.link(PaymentTypeCollection(self.request.session))
def get_payment_types(request): return PaymentTypeCollection(request.session)