def test_reminder_emails_are_sent(self):
        ResourceType.create_defaults()
        UserRole.create_defaults()

        unit = self.create_organizational_unit()
        self.create_default_teacher(unit=unit)
        product = self.create_product(unit=unit)
        visit = self.create_visit(
            product,
            start=datetime.now() + timedelta(days=5),
            end=datetime.now() + timedelta(days=10),
        )
        template_type = EmailTemplateType.objects.create(
            key=EmailTemplateType.NOTIFY_GUEST_REMINDER,
            name_da="gæst notifikation",
            send_to_unit_teachers=True)
        self.create_emailtemplate(type=template_type,
                                  subject="Mail til lærer",
                                  body="Mail til lærer")

        self.create_autosend(visit, template_type, enabled=True, days=5)
        job = ReminderJob()
        job.run()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, "Mail til lærer")
        self.assertEqual(mail.outbox[0].body, "\n\n\nMail til lærer\n")
 def setUpClass(cls):
     super(TestBooking, cls).setUpClass()
     EmailTemplateType.set_defaults()
     School.create_defaults()
     GrundskoleLevel.create_defaults()
     UserRole.create_defaults()
     ResourceType.create_defaults()
     Subject.create_defaults()
     (cls.unittype,
      c) = OrganizationalUnitType.objects.get_or_create(name="Fakultet")
     (cls.unit,
      c) = OrganizationalUnit.objects.get_or_create(name="testunit",
                                                    type=cls.unittype)
     cls.admin.userprofile.organizationalunit = cls.unit
     cls.admin.userprofile.save()
     Locality.create_defaults()
     (cls.locality,
      c) = Locality.objects.get_or_create(name='TestPlace',
                                          description="Place for testing",
                                          address_line="SomeRoad 2",
                                          zip_city="1234 SomeCity",
                                          organizationalunit=cls.unit)
     (cls.roomresponsible, c) = RoomResponsible.objects.get_or_create(
         name='TestResponsible',
         email='*****@*****.**',
         phone='12345678',
         organizationalunit=cls.unit)
Ejemplo n.º 3
0
    def setUpClass(cls):
        super(TestResources, cls).setUpClass()
        UserRole.create_defaults()
        ResourceType.create_defaults()
        cls.unittype = OrganizationalUnitType.objects.create(name="Fakultet")
        cls.unit = OrganizationalUnit.objects.create(name=u"testunit",
                                                     type=cls.unittype)
        cls.admin.userprofile.organizationalunit = cls.unit
        cls.admin.userprofile.save()

        cls.field_definitions = {}
Ejemplo n.º 4
0
 def setUpClass(cls):
     super(TestUser, cls).setUpClass()
     UserRole.create_defaults()
     ResourceType.create_defaults()
     (cls.unittype,
      c) = OrganizationalUnitType.objects.get_or_create(name="Fakultet")
     (cls.unit,
      c) = OrganizationalUnit.objects.get_or_create(name="testunit",
                                                    type=cls.unittype)
     cls.admin.userprofile.organizationalunit = cls.unit
     cls.admin.userprofile.save()
Ejemplo n.º 5
0
 def setUpClass(cls):
     super(TestEmail, cls).setUpClass()
     EmailTemplateType.set_defaults()
     UserRole.create_defaults()
     ResourceType.create_defaults()
     GrundskoleLevel.create_defaults()
     cls.unittype = OrganizationalUnitType.objects.create(name="Fakultet")
     cls.unit = OrganizationalUnit.objects.create(name="testunit",
                                                  type=cls.unittype)
     cls.admin.userprofile.organizationalunit = cls.unit
     cls.admin.userprofile.save()
     """
    def test_idle_host_role_notifications_are_sent(self):
        ResourceType.create_defaults()
        UserRole.create_defaults()
        unit = self.create_organizational_unit()

        guest = self.create_guest()
        host = self.create_default_host(unit=unit)

        product = self.create_product(unit=unit, potential_hosts=[host])
        product.needed_hosts = 1
        product.save()
        visit = self.create_visit(
            product,
            start=datetime.now() + timedelta(days=5),
            end=datetime.now() + timedelta(days=10),
        )
        booking = self.create_booking(visit, guest)
        statistics = ObjectStatistics.objects.create()
        booking.statistics = statistics
        booking.save()
        template_type = EmailTemplateType.objects.create(
            key=EmailTemplateType.NOTIFY_HOST__HOSTROLE_IDLE,
            name_da="notificer vært",
            send_to_potential_hosts=True,
        )
        email_template = self.create_emailtemplate(
            key=EmailTemplateType.NOTIFY_HOST__HOSTROLE_IDLE,
            type=template_type,
            unit=unit,
            subject="Mail til vært",
            body="Mail til vært")
        self.create_autosend(visit, template_type, enabled=True, days=0)

        job = IdleHostroleJob()
        job.run()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject, "Mail til vært")
        self.assertEqual(mail.outbox[0].body, "\n\n\nMail til vært\n")
    def test_potential_host(self):
        UserRole.create_defaults()
        ResourceType.create_defaults()
        user = self.create_default_host(unit=self.unit)
        product = self.create_product(unit=self.unit,
                                      potential_hosts=[user],
                                      time_mode=Product.TIME_MODE_SPECIFIC)
        self.assertTrue(
            user.id in [u.id for u in product.potential_hosts.all()])
        self._test_is_present_on_profile(user, product)
        product.delete()

        product = self.create_product(
            unit=self.unit, time_mode=Product.TIME_MODE_RESOURCE_CONTROLLED)
        self.assertFalse(
            user.id in [u.id for u in product.potential_hosts.all()])
        pool = self.create_resourcepool(ResourceType.RESOURCE_TYPE_HOST,
                                        self.unit, 'test_pool',
                                        user.userprofile.get_resource())
        self.create_resourcerequirement(product, pool, 1)
        self.assertTrue(
            user.id in [u.id for u in product.potential_hosts.all()])
        self._test_is_present_on_profile(user, product)
    def test_email_recipients(self):
        # setup products with users in different roles
        # test that get_recipients returns the correct users
        EmailTemplateType.set_defaults()
        ResourceType.create_defaults()
        UserRole.create_defaults()
        teacher = self.create_default_teacher(unit=self.unit)
        host = self.create_default_host(unit=self.unit)
        coordinator = self.create_default_coordinator(unit=self.unit)
        roomguy = self.create_default_roomresponsible(unit=self.unit)
        teacher_pool = self.create_resourcepool(
            ResourceType.RESOURCE_TYPE_TEACHER, self.unit, 'test_teacher_pool',
            teacher.userprofile.get_resource())
        host_pool = self.create_resourcepool(
            ResourceType.RESOURCE_TYPE_HOST, self.unit, 'test_host_pool',
            teacher.userprofile.get_resource())

        products = []

        for product_type, label in Product.resource_type_choices:
            for time_mode in [
                    Product.TIME_MODE_NONE, Product.TIME_MODE_SPECIFIC,
                    Product.TIME_MODE_GUEST_SUGGESTED,
                    Product.TIME_MODE_NO_BOOKING
            ]:
                product = self.create_product(self.unit,
                                              time_mode=time_mode,
                                              potential_teachers=[teacher],
                                              potential_hosts=[host],
                                              state=Product.CREATED,
                                              product_type=product_type)
                product.tilbudsansvarlig = coordinator
                product.roomresponsible.add(roomguy)
                product.save()
                products.append(product)

        for time_mode in [
                Product.TIME_MODE_RESOURCE_CONTROLLED,
                Product.TIME_MODE_RESOURCE_CONTROLLED_AUTOASSIGN
        ]:
            product = self.create_product(self.unit,
                                          time_mode=time_mode,
                                          state=Product.CREATED,
                                          product_type=product_type)
            product.tilbudsansvarlig = coordinator
            product.roomresponsible.add(roomguy)
            self.create_resourcerequirement(product, teacher_pool, 1)
            self.create_resourcerequirement(product, host_pool, 1)
            product.save()
            #  products.append(product)

        expected = {
            EmailTemplateType.NOTIFY_EDITORS__BOOKING_CREATED:
            [(KUEmailRecipient.TYPE_PRODUCT_RESPONSIBLE, coordinator)],
            EmailTemplateType.NOTIFY_HOST__REQ_TEACHER_VOLUNTEER:
            [(KUEmailRecipient.TYPE_TEACHER, teacher)],
            EmailTemplateType.NOTIFY_HOST__REQ_HOST_VOLUNTEER:
            [(KUEmailRecipient.TYPE_HOST, host)],
            EmailTemplateType.NOTIFY_HOST__REQ_ROOM:
            [(KUEmailRecipient.TYPE_ROOM_RESPONSIBLE, roomguy)],
            EmailTemplateType.NOTIFY_ALL__BOOKING_COMPLETE: [
                (KUEmailRecipient.TYPE_PRODUCT_RESPONSIBLE, coordinator),
                (KUEmailRecipient.TYPE_ROOM_RESPONSIBLE, roomguy)
            ],
            EmailTemplateType.NOTIFY_ALL__BOOKING_CANCELED: [
                (KUEmailRecipient.TYPE_PRODUCT_RESPONSIBLE, coordinator),
                (KUEmailRecipient.TYPE_ROOM_RESPONSIBLE, roomguy)
            ],
            EmailTemplateType.NOTITY_ALL__BOOKING_REMINDER: [
                (KUEmailRecipient.TYPE_PRODUCT_RESPONSIBLE, coordinator),
                (KUEmailRecipient.TYPE_ROOM_RESPONSIBLE, roomguy)
            ],
            EmailTemplateType.NOTIFY_HOST__HOSTROLE_IDLE: [
                (KUEmailRecipient.TYPE_EDITOR, coordinator)
            ],
            EmailTemplateType.NOTIFY_EDITORS__SPOT_REJECTED: [
                (KUEmailRecipient.TYPE_PRODUCT_RESPONSIBLE, coordinator),
            ],
        }
        expected.update({
            template_type.key: []
            for template_type in EmailTemplateType.objects.all()
            if template_type.key not in expected.keys()
        })

        def unpack(item):
            if isinstance(item, User):
                return (item.get_full_name(), item.email)
            if isinstance(item, RoomResponsible):
                return (item.name, item.email)

        for product in products:
            for template_type_key, expected_recipients in expected.items():
                actual_recipients = product.get_recipients(
                    EmailTemplateType.get(template_type_key))
                self.assertEquals(
                    len(expected_recipients), len(actual_recipients),
                    "Expected number of recipients not "
                    "matching for template type %d" % template_type_key)
                expected_recipients = [(t, unpack(r))
                                       for (t, r) in expected_recipients]
                for r in actual_recipients:
                    self.assertTrue(
                        (r.type, (r.name, r.email)) in expected_recipients,
                        "did not expect (%d, (%s, %s)) "
                        "for template type %d, expected %s" %
                        (r.type, r.name, r.email, template_type_key,
                         str(expected_recipients)))
    def test_visit_ui(self):
        # create product, visit and bookings
        # test that visit view html looks ok, including
        # number of attendees
        # time
        # status data
        # booker list
        # waiting list
        # activity log
        # emails
        # Post log form, check that new log entry is created
        # Post comment form, check that new log entry is created
        # test that bookings can be moved to/from waiting list
        # test that bookings can be deleted

        ResourceType.create_defaults()
        UserRole.create_defaults()
        School.create_defaults()
        teacher = self.create_default_teacher(unit=self.unit)
        host = self.create_default_host(unit=self.unit)
        coordinator = self.create_default_coordinator(unit=self.unit)
        roomguy = self.create_default_roomresponsible(unit=self.unit)
        self.create_resourcepool(
            ResourceType.RESOURCE_TYPE_TEACHER,
            self.unit,
            'test_teacher_pool',
            teacher.userprofile.get_resource()
        )
        self.create_resourcepool(
            ResourceType.RESOURCE_TYPE_HOST,
            self.unit,
            'test_host_pool',
            teacher.userprofile.get_resource()
        )

        product = self.create_product(
            self.unit,
            time_mode=Product.TIME_MODE_SPECIFIC
        )
        product.roomresponsible.add(roomguy)
        product.tilbudsansvarlig = coordinator
        product.do_create_waiting_list = True
        product.waiting_list_length = 10
        product.maximum_number_of_visitors = 10
        product.save()
        start = datetime.utcnow() + timedelta(days=10)
        visit = self.create_visit(product, start, start + timedelta(hours=1))
        visit.teachers.add(teacher)
        visit.hosts.add(host)
        visit.save()

        guest1 = self.create_guest("Tester1")
        guest1.attendee_count = 10
        guest1.school = School.objects.get(id=1)
        guest1.save()
        self.create_booking(visit, guest1)
        guest2 = self.create_guest("Tester2")
        guest2.attendee_count = 10
        guest2.school = School.objects.get(id=2)
        guest2.save()
        booking2 = self.create_booking(visit, guest2)
        booking2.waitinglist_spot = 1
        booking2.save()

        url = "/visit/%d/" % visit.id
        self.login(url, self.admin)
        response = self.client.get(url)
        query = PyQuery(response.content)
        self.assertEquals(
            "10 har tilmeldt sig testproduct",
            query("#attendees").text()
        )

        overview = ParsedNode(query("#status-overview"))
        data = {}
        for row in overview.find("div.row"):
            key = None
            values = []
            for c in row.children:
                if c.tag == 'strong':
                    key = c.text
                elif c.tag == 'div':
                    values.append(c.text)
            data[key] = values
        self.assertDictEqual(
            {
                u'Enhed': [u'testunit'],
                u'Tidspunkt': [
                    product.eventtime_set.first().interval_display, u'Redigér'
                ],
                u'Undervisere': [u'1/0 undervisere fundet', u'Redigér'],
                u'Værter': [u'1/0 værter fundet', u'Redigér'],
                u'Lokaler': [u'Afventer tildeling/bekræftelse', u'Redigér'],
                u'Automatisk e-mail': [u'', u'Redigér'],
                u'Status': [u'Under planlægning', u'Skift status'],
                u'Antal på venteliste': [u'10', u'Se liste'],
                u'Vigtig bemærkning': [u'', u'Redigér']
            },
            data
        )

        attendees_overview = ParsedNode(query(".attendees"))
        self.assertEquals(
            "Tilmeldte\n(10/10)",
            self.strip_inner(attendees_overview.find("h2")[0].text)
        )
        attendees_list = attendees_overview.find(".list-group-item")
        for attendee in attendees_list:
            data = {}
            for d in [x.extract_dl() for x in attendee.find("dl")]:
                data.update(d)
            self.assertDictEqual(
                {
                    u'koordinator:': [{'text': coordinator.get_full_name()}],
                    u'studieretning:': [{'text': None}],
                    u'f*g:': [],
                    u'underviser:': [{'text': teacher.get_full_name()}],
                    u'antal:': [{'text': '10'}],
                    u'email:': [{'text': guest1.email}],
                    u'vært:': [{'text': host.get_full_name()}],
                    u'niveau:': [{'text': 'Afsluttet gymnasieuddannelse'}],
                    u'navn:': [{'text': guest1.get_full_name()}],
                    u'skole:': [
                        {
                            'text': 'Aabenraa Statsskole, 6200 Aabenraa',
                            'children': [
                                {'text': 'Aabenraa Statsskole, 6200 Aabenraa'}
                            ]
                        }
                    ]
                },
                data
            )