def test_pre_reserve_script_variables(self):

        class MockContext(object):
            def getPhysicalPath(self):
                return ['', 'foo', 'bar']

        start, end = datetime.now(), datetime.now()
        data = utils.mock_data_dictionary({
            'is_test': True,
            'description': 'This is the description'
        })

        settings.set('pre_reservation_script', u'exit()')

        locals_ = {}
        run_pre_reserve_script(MockContext(), start, end, data, locals_)

        self.assertEqual(locals_['path'], '/foo/bar')
        self.assertFalse(locals_['is_group_reservation'])
        self.assertEqual(locals_['start'], start)
        self.assertEqual(locals_['end'], end)
        self.assertEqual(locals_['date'], date)
        self.assertEqual(locals_['datetime'], datetime)
        self.assertEqual(locals_['timedelta'], timedelta)
        self.assertTrue(locals_['formset_available']('mock'))
Example #2
0
def upgrade_1025_to_1026(context):

    registry = getUtility(IRegistry)
    registry.registerInterface(settings.ISeantisReservationSettings)

    settings.set('available_threshold', 75)
    settings.set('partly_available_threshold', 1)

    # ensure that the records exist now
    settings.get('available_threshold')
    settings.get('partly_available_threshold')
Example #3
0
def upgrade_1025_to_1026(context):

    registry = getUtility(IRegistry)
    registry.registerInterface(settings.ISeantisReservationSettings)

    settings.set('available_threshold', 75)
    settings.set('partly_available_threshold', 1)

    # ensure that the records exist now
    settings.get('available_threshold')
    settings.get('partly_available_threshold')
    def test_event_class(self):
        self.assertEqual(utils.event_class(100), 'event-available')
        self.assertEqual(utils.event_class(75), 'event-available')
        self.assertEqual(utils.event_class(1), 'event-partly-available')
        self.assertEqual(utils.event_class(0), 'event-unavailable')

        settings.set('available_threshold', 100)
        settings.set('partly_available_threshold', 1)

        self.assertEqual(utils.event_class(100), 'event-available')
        self.assertEqual(utils.event_class(99), 'event-partly-available')
        self.assertEqual(utils.event_class(1), 'event-partly-available')
        self.assertEqual(utils.event_class(0), 'event-unavailable')
Example #5
0
    def test_event_class(self):
        self.assertEqual(utils.event_class(100), 'event-available')
        self.assertEqual(utils.event_class(75), 'event-available')
        self.assertEqual(utils.event_class(1), 'event-partly-available')
        self.assertEqual(utils.event_class(0), 'event-unavailable')

        settings.set('available_threshold', 100)
        settings.set('partly_available_threshold', 1)

        self.assertEqual(utils.event_class(100), 'event-available')
        self.assertEqual(utils.event_class(99), 'event-partly-available')
        self.assertEqual(utils.event_class(1), 'event-partly-available')
        self.assertEqual(utils.event_class(0), 'event-unavailable')
Example #6
0
    def test_manager_discovery(self):
        self.login_manager()

        resource = self.create_resource()

        # nobody's defined in the hierarchy, in which case anybody with the
        # reservation role get's the email
        self.set_test_user_roles(['Manager', 'Reservation-Manager'])
        self.assertEqual(get_managers_by_context(resource), [TEST_USER_ID])

        # if we assign two separate managers to the resource we should
        # only get those
        self.assign_reservation_manager('*****@*****.**', resource)
        self.assign_reservation_manager('*****@*****.**', resource)

        self.assertEqual(sorted(get_managers_by_context(resource)),
                         sorted(['ted', 'brad']))

        settings.set('send_email_to_managers', 'by_path')
        self.assertEqual(sorted(get_manager_emails(resource)),
                         ['*****@*****.**', '*****@*****.**'])

        settings.set('manager_email', u'*****@*****.**')
        settings.set('send_email_to_managers', 'by_address')

        self.assertEqual(get_manager_emails(resource), ['*****@*****.**'])

        settings.set('send_email_to_managers', 'never')
        self.assertEqual(get_manager_emails(resource), [])
Example #7
0
def upgrade_1020_to_1021(context):

    send_email_to_managers = settings.get('send_email_to_managers')

    registry = getUtility(IRegistry)
    registry.registerInterface(settings.ISeantisReservationSettings)

    if send_email_to_managers is True:
        settings.set('send_email_to_managers', 'by_path')
    elif send_email_to_managers is False:
        settings.set('send_email_to_managers', 'never')

    # ensure that the records exist now
    settings.get('manager_email')
    settings.get('send_email_to_managers')
Example #8
0
def upgrade_1020_to_1021(context):

    send_email_to_managers = settings.get('send_email_to_managers')

    registry = getUtility(IRegistry)
    registry.registerInterface(settings.ISeantisReservationSettings)

    if send_email_to_managers is True:
        settings.set('send_email_to_managers', 'by_path')
    elif send_email_to_managers is False:
        settings.set('send_email_to_managers', 'never')

    # ensure that the records exist now
    settings.get('manager_email')
    settings.get('send_email_to_managers')
    def test_pre_reserve_script_example(self):

        class MockContext(object):
            def getPhysicalPath(self):
                return ['', 'foo', 'bar']

        script = u"""
        if is_group_reservation:
            exit()

        if not formset_available('personalien'):
            exit()

        if personalien.zipcode != '1337':
            error('People with uncool zipcodes are not welcome.')
        """

        settings.set('pre_reservation_script', dedent(script))

        start, end = None, None
        data = utils.mock_data_dictionary({})

        run = lambda: run_pre_reserve_script(MockContext(), start, end, data)

        run()  # exits early because it's a group reservation

        start, end = datetime.now(), datetime.now()

        run()  # exits early because the formset is not available

        data = utils.mock_data_dictionary({
            'zipcode': '1234'
        }, 'personalien')

        self.assertRaises(CustomReservationError, run)  # uncool zipcode

        data = utils.mock_data_dictionary({
            'zipcode': '1337'
        }, 'personalien')

        run()  # ok
Example #10
0
    def test_manager_discovery(self):
        self.login_manager()

        resource = self.create_resource()

        # nobody's defined in the hierarchy, in which case anybody with the
        # reservation role get's the email
        self.set_test_user_roles(['Manager', 'Reservation-Manager'])
        self.assertEqual(get_managers_by_context(resource), [TEST_USER_ID])

        # if we assign two separate managers to the resource we should
        # only get those
        self.assign_reservation_manager('*****@*****.**', resource)
        self.assign_reservation_manager('*****@*****.**', resource)

        self.assertEqual(
            sorted(get_managers_by_context(resource)),
            sorted(['ted', 'brad'])
        )

        settings.set('send_email_to_managers', 'by_path')
        self.assertEqual(
            sorted(get_manager_emails(resource)),
            ['*****@*****.**', '*****@*****.**']
        )

        settings.set('manager_email', u'*****@*****.**')
        settings.set('send_email_to_managers', 'by_address')

        self.assertEqual(
            get_manager_emails(resource),
            ['*****@*****.**']
        )

        settings.set('send_email_to_managers', 'never')
        self.assertEqual(
            get_manager_emails(resource),
            []
        )