'Basic event management with auto confirmation'

@mute_logger('odoo.addons.base.ir.ir_model', 'odoo.models')
def test_00_basic_event_auto_confirm(self):

    event_config = self.env['event.config.settings'].sudo(self.user_eventmanager).create({'auto_confirmation': 1})
    event_config.execute()
    test_event = self.Event.sudo(self.user_eventmanager).create({'name': 'TestEvent', 'date_begin': (datetime.datetime.now() + relativedelta(days=(-1))), 'date_end': (datetime.datetime.now() + relativedelta(days=1)), 'seats_max': 2, 'seats_availability': 'limited'})
    self.assertEqual(test_event.state, 'confirm', 'Event:    auto_confirmation    of    event    failed')
    test_reg1 = self.Registration.sudo(self.user_eventuser).create({'name': 'TestReg1', 'event_id': test_event.id})
    self.assertEqual(test_reg1.state, 'open', 'Event:    auto_confirmation    of    registration    failed')
    self.assertEqual(test_event.seats_reserved, 1, 'Event:    wrong    number    of    reserved    seats    after    confirmed    registration')
    test_reg2 = self.Registration.sudo(self.user_eventuser).create({'name': 'TestReg2', 'event_id': test_event.id})
    self.assertEqual(test_reg2.state, 'open', 'Event:    auto_confirmation    of    registration    failed')
    self.assertEqual(test_event.seats_reserved, 2, 'Event:    wrong    number    of    reserved    seats    after    confirmed    registration')
    with self.assertRaises(ValidationError):
        self.Registration.sudo(self.user_eventuser).create({'name': 'TestReg3', 'event_id': test_event.id})
    test_reg1.button_reg_close()
    self.assertEqual(test_reg1.state, 'done', 'Event:    wrong    state    of    attended    registration')
    self.assertEqual(test_event.seats_used, 1, 'Event:    incorrect    number    of    attendees    after    closing    registration')
    test_reg2.button_reg_close()
    self.assertEqual(test_reg1.state, 'done', 'Event:    wrong    state    of    attended    registration')
    self.assertEqual(test_event.seats_used, 2, 'Event:    incorrect    number    of    attendees    after    closing    registration')
    test_event.button_done()
    with self.assertRaises(UserError):
        test_event.button_cancel()
