def test_to_table(self):

        site = USite.objects.create(name="site")
        unit1 = utils.create_unit(site=site)
        usa1 = sl_utils.create_unit_service_area(unit=unit1)
        sl_utils.create_service_event(unit_service_area=usa1)

        unit2 = utils.create_unit()
        usa2 = sl_utils.create_unit_service_area(unit=unit2)
        se = sl_utils.create_service_event(unit_service_area=usa2)
        se2 = sl_utils.create_service_event(unit_service_area=usa2)
        se.service_event_related.add(se2)

        sl_utils.create_hours(service_event=se)
        tp = sl_utils.create_third_party()
        sl_utils.create_hours(service_event=se, third_party=tp)
        sl_utils.create_group_linker_instance(service_event=se)
        part = sl_utils.create_part()

        parts_models.PartUsed.objects.create(service_event=se, part=part, quantity=1)

        attachment = Attachment(
            attachment=ContentFile("content", "content.pdf"),
            created_by=se.user_created_by,
            serviceevent=se,
        )
        attachment.save()

        rep = sl.ServiceEventPersonnelSummaryReport()
        rep.report_format = "xlsx"
        context = rep.get_context()
        rep.to_table(context)
Example #2
0
    def test_third_party_and_hours(self):

        se = sl_models.ServiceEvent.objects.first()
        tp = sl_utils.create_third_party()

        h_01 = sl_utils.create_hours(service_event=se,
                                     third_party=tp,
                                     user=None)

        with self.assertRaises(IntegrityError):
            sl_models.Hours.objects.create(service_event=se,
                                           third_party=tp,
                                           user=None,
                                           time=timezone.timedelta(hours=1))

        u_02 = create_user(is_superuser=False, uname='user_02')
        h_02 = sl_utils.create_hours(service_event=se, user=u_02)

        # Test user_or_third_party
        self.assertEqual((tp.__class__, tp.id),
                         (h_01.user_or_thirdparty().__class__,
                          h_01.user_or_thirdparty().id))
        self.assertEqual((u_02.__class__, u_02.id),
                         (h_02.user_or_thirdparty().__class__,
                          h_02.user_or_thirdparty().id))
Example #3
0
    def test_delete_thirdparty_variables(self):

        # vendor > Protect

        tp = sl_utils.create_third_party()
        v = tp.vendor

        with self.assertRaises(ProtectedError):
            v.delete()
Example #4
0
    def test_unique_together(self):

        v_01 = qa_utils.create_vendor()
        tp_01 = sl_utils.create_third_party(vendor=v_01)
        tp_01_first_name = tp_01.first_name
        tp_01_last_name = tp_01.last_name

        with self.assertRaises(IntegrityError):
            sl_models.ThirdParty.objects.create(vendor=v_01,
                                                first_name=tp_01_first_name,
                                                last_name=tp_01_last_name)
Example #5
0
    def test_delete_hours_variables(self):

        # service_event > Cascade
        # third_party   > Protect
        # user          > Protect

        tp = sl_utils.create_third_party()
        h = sl_utils.create_hours(third_party=tp)
        se = h.service_event
        h_id = h.id

        with self.assertRaises(ProtectedError):
            tp.delete()

        se.delete()
        self.assertFalse(sl_models.Hours.objects.filter(id=h_id).exists())

        u = create_user()
        h = sl_utils.create_hours(user=u)

        with self.assertRaises(ProtectedError):
            u.delete()
Example #6
0
 def test_get_full_name(self):
     tp = sl_utils.create_third_party()
     self.assertTrue(tp.first_name in tp.get_full_name()
                     and tp.last_name in tp.get_full_name())
     self.assertTrue(tp.vendor.name in tp.get_full_name())
Example #7
0
    def setUp(self):

        self.factory = RequestFactory()
        self.view = views.UpdateServiceEvent.as_view()

        self.default_ses = sl_utils.create_service_event_status(
            is_default=True)
        self.approved_ses = sl_utils.create_service_event_status(
            is_review_required=False, rts_qa_must_be_reviewed=True)
        sl_utils.create_service_event_status()
        qa_utils.create_status(is_default=True)

        now = timezone.now()

        self.u_1 = qa_utils.create_unit(name='u_1')
        self.sa_1 = sl_utils.create_service_area(name='sa_1')
        self.usa_1 = sl_utils.create_unit_service_area(unit=self.u_1,
                                                       service_area=self.sa_1)
        self.tl_1 = qa_utils.create_test_list(name='tl_1')
        self.tli_1_1 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_1, test_collection=self.tl_1),
            test_list=self.tl_1,
            work_completed=now - timezone.timedelta(hours=1))
        self.tli_1_2 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_1, test_collection=self.tl_1),
            test_list=self.tl_1,
            work_completed=now)
        self.se_1 = sl_utils.create_service_event(unit_service_area=self.usa_1)

        self.u_2 = qa_utils.create_unit(name='u_2')
        self.sa_2 = sl_utils.create_service_area(name='sa_2')
        self.usa_2 = sl_utils.create_unit_service_area(unit=self.u_2,
                                                       service_area=self.sa_2)
        self.tl_2 = qa_utils.create_test_list(name='tl_2')
        self.tli_2_1 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_2, test_collection=self.tl_2),
            test_list=self.tl_2,
            work_completed=now - timezone.timedelta(hours=1))
        self.tli_2_2 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_2, test_collection=self.tl_2),
            test_list=self.tl_2,
            work_completed=now)
        self.se_2 = sl_utils.create_service_event(unit_service_area=self.usa_2)

        self.url = reverse('sl_new')
        self.user = create_user(is_superuser=True)

        self.client.login(username='******', password='******')

        perm = Permission.objects.get(codename='can_have_hours')
        user_can_hours = User.objects.get(username='******')
        user_can_hours.user_permissions.add(perm)
        user_group_has_hours = create_user(uname='in_group_with_hours')
        group_has_hours = create_group(name='can_have_hours')
        group_has_hours.permissions.add(perm)
        user_group_has_hours.groups.add(group_has_hours)

        sl_utils.create_third_party()

        group_linked = create_group(name='linked')
        user_group_linked = create_user(uname='user_in_group_linked')
        user_group_linked.groups.add(group_linked)
        self.gl_1 = sl_utils.create_group_linker(group=group_linked)
        self.part = sl_utils.create_part(add_storage=True)

        self.st = sl_utils.create_service_type()

        self.se = sl_utils.create_service_event(
            unit_service_area=self.usa_1,
            service_status=self.default_ses,
            service_type=self.st)

        self.url = reverse('sl_edit', kwargs={"pk": self.se.pk})

        self.data = {
            'datetime_service': format_datetime(timezone.now()),
            'service_status': self.default_ses.id,
            'service_type': self.st.id,
            'is_review_required': 0,
            'safety_precautions': 'safety_precautions',
            'problem_description': 'problem_description',
            'service_area_field': self.se.unit_service_area.service_area.id,
            'unit_field': self.se.unit_service_area.unit.id,
            'unit_field_fake': self.se.unit_service_area.unit.id,
            'qafollowup_notes': 'qafollowup_notes',
            'test_list_instance_initiated_by': self.tli_1_1.id,
            'duration_lost_time': '0100',
            'duration_service_time': '0100',
            'hours-INITIAL_FORMS': 0,
            'hours-MAX_NUM_FORMS': 1000,
            'hours-TOTAL_FORMS': 0,
            'hours-MIN_NUM_FORMS': 0,
            'parts-INITIAL_FORMS': 0,
            'parts-MAX_NUM_FORMS': 1000,
            'parts-TOTAL_FORMS': 0,
            'parts-MIN_NUM_FORMS': 0,
            'rtsqa-INITIAL_FORMS': 0,
            'rtsqa-MAX_NUM_FORMS': 1000,
            'rtsqa-TOTAL_FORMS': 0,
            'rtsqa-MIN_NUM_FORMS': 0,
        }
Example #8
0
    def setUp(self):

        self.factory = RequestFactory()
        self.view = views.CreateServiceEvent.as_view()

        self.default_ses = sl_utils.create_service_event_status(
            is_default=True)
        sl_utils.create_service_event_status()
        qa_utils.create_status(is_default=True)

        now = timezone.now()

        self.u_1 = qa_utils.create_unit(name='u_1')
        self.sa_1 = sl_utils.create_service_area(name='sa_1')
        self.usa_1 = sl_utils.create_unit_service_area(unit=self.u_1,
                                                       service_area=self.sa_1)
        self.tl_1 = qa_utils.create_test_list(name='tl_1')
        self.tli_1_1 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_1, test_collection=self.tl_1),
            test_list=self.tl_1,
            work_completed=now - timezone.timedelta(hours=1))
        self.tli_1_2 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_1, test_collection=self.tl_1),
            test_list=self.tl_1,
            work_completed=now)
        self.se_1 = sl_utils.create_service_event(unit_service_area=self.usa_1)

        self.u_2 = qa_utils.create_unit(name='u_2')
        self.sa_2 = sl_utils.create_service_area(name='sa_2')
        self.usa_2 = sl_utils.create_unit_service_area(unit=self.u_2,
                                                       service_area=self.sa_2)
        self.tl_2 = qa_utils.create_test_list(name='tl_2')
        self.tli_2_1 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_2, test_collection=self.tl_2),
            test_list=self.tl_2,
            work_completed=now - timezone.timedelta(hours=1))
        self.tli_2_2 = qa_utils.create_test_list_instance(
            unit_test_collection=qa_utils.create_unit_test_collection(
                unit=self.u_2, test_collection=self.tl_2),
            test_list=self.tl_2,
            work_completed=now)
        self.se_2 = sl_utils.create_service_event(unit_service_area=self.usa_2)

        self.url = reverse('sl_new')
        self.url_delete = reverse('se_delete')
        self.user = create_user(is_superuser=True)

        self.client.login(username='******', password='******')

        perm = Permission.objects.get(codename='can_have_hours')
        user_can_hours = User.objects.get(username='******')
        user_can_hours.user_permissions.add(perm)
        user_group_has_hours = create_user(uname='in_group_with_hours')
        group_has_hours = create_group(name='can_have_hours')
        group_has_hours.permissions.add(perm)
        user_group_has_hours.groups.add(group_has_hours)

        sl_utils.create_third_party()

        group_linked = create_group(name='linked')
        user_group_linked = create_user(uname='user_in_group_linked')
        user_group_linked.groups.add(group_linked)
        self.gl_1 = sl_utils.create_group_linker(group=group_linked)
        self.part = sl_utils.create_part(add_storage=True)

        self.st = sl_utils.create_service_type()

        self.sto = sl_utils.create_storage(quantity=2)