Пример #1
0
    def save_model(self, request, test_info, form, change):
        """create new reference when user updates value"""

        if form.instance.test.type != models.MULTIPLE_CHOICE:

            if form.instance.test.type == models.BOOLEAN:
                ref_type = models.BOOLEAN
            else:
                ref_type = models.NUMERICAL
            val = form["reference_value"].value()
            if val not in ("", None):
                if not (test_info.reference
                        and test_info.reference.value == float(val)):
                    try:
                        ref = models.Reference.objects.filter(value=val,
                                                              type=ref_type)[0]
                    except IndexError:
                        ref = models.Reference(
                            value=val,
                            type=ref_type,
                            created_by=request.user,
                            modified_by=request.user,
                            name="%s %s" %
                            (test_info.unit.name, test_info.test.name)[:255])
                        ref.save()
                    test_info.reference = ref
            else:
                test_info.reference = None

        super(UnitTestInfoAdmin, self).save_model(request, test_info, form,
                                                  change)
Пример #2
0
    def setUp(self):

        self.tests = []

        self.ref = models.Reference(type=models.NUMERICAL, value=100.)
        self.tol = models.Tolerance(type=models.PERCENT,
                                    act_low=-3,
                                    tol_low=-2,
                                    tol_high=2,
                                    act_high=3)
        self.values = [None, None, 96, 97, 100, 100]

        self.statuses = [
            utils.create_status(name="status%d" % x, slug="status%d" % x)
            for x in range(len(self.values))
        ]

        self.test_list = utils.create_test_list()
        for i in range(6):
            test = utils.create_test(name="name%d" % i)
            self.tests.append(test)
            utils.create_test_list_membership(self.test_list, test)

        self.unit_test_collection = utils.create_unit_test_collection(
            test_collection=self.test_list)

        self.test_list_instance = self.create_test_list_instance()

        self.group = models.Group.objects.get(pk=1)
        user = models.User.objects.get(pk=1)
        user.groups.add(self.group)
        user.email = "*****@*****.**"
        user.save()
Пример #3
0
    def test_absolute(self):
        r = models.Reference(value=1)
        tol = models.Tolerance(
            type=models.ABSOLUTE,
            act_low=-2, tol_low=-1, tol_high=1, act_high=2,
        )

        self.assertIn("Between 0 & 2", qa_tags.tolerance_for_reference(tol, r))
Пример #4
0
 def test_absolute(self):
     t = models.Test(type=models.NUMERICAL)
     r = models.Reference(value=1)
     tol = models.Tolerance(
         type=models.ABSOLUTE,
         act_low=-2, tol_low=-1, tol_high=1, act_high=2,
     )
     result = qa_tags.reference_tolerance_span(t, r, tol)
     self.assertIn("%s L" % (settings.TEST_STATUS_DISPLAY_SHORT['action']), result)
Пример #5
0
def create_reference(name="ref", ref_type=models.NUMERICAL, value=1, created_by=None):
    if created_by is None:
        created_by = create_user()

    r = models.Reference(
        name=name, type=ref_type, value=value,
        created_by=created_by, modified_by=created_by
    )
    r.save()
    return r
Пример #6
0
    def setUp(self):

        self.tests = []

        self.ref = models.Reference(type=models.NUMERICAL, value=100.)
        self.tol = models.Tolerance(type=models.PERCENT,
                                    act_low=-3,
                                    tol_low=-2,
                                    tol_high=2,
                                    act_high=3)
        self.ref.created_by = utils.create_user()
        self.tol.created_by = utils.create_user()
        self.ref.modified_by = utils.create_user()
        self.tol.modified_by = utils.create_user()
        self.values = [None, None, 96, 97, 100, 100]

        self.statuses = [
            utils.create_status(name="status%d" % x, slug="status%d" % x)
            for x in range(len(self.values))
        ]

        self.test_list = utils.create_test_list()
        for i in range(6):
            test = utils.create_test(name="name%d" % i)
            self.tests.append(test)
            utils.create_test_list_membership(self.test_list, test)

        self.testlist_group = TestListGroup.objects.create(name="test group")
        self.testlist_group.test_lists.add(self.test_list)

        self.unit_test_collection = utils.create_unit_test_collection(
            test_collection=self.test_list)

        self.unit_group = UnitGroup.objects.create(name="test group")
        self.unit_group.units.add(self.unit_test_collection.unit)

        self.test_list_instance = self.create_test_list_instance()

        self.group = models.Group.objects.latest('pk')
        user = models.User.objects.latest('pk')
        user.groups.add(self.group)
        user.email = "*****@*****.**"
        user.save()

        self.recipients = RecipientGroup.objects.create(name="test group")
        self.recipients.groups.add(self.group)

        self.inactive_user = models.User.objects.create_user(
            'inactive', '*****@*****.**', 'password')
        self.inactive_user.groups.add(self.group)
        self.inactive_user.is_active = False
        self.inactive_user.save()

        # delete defaults schedules to make counting easier
        Schedule.objects.all().delete()
Пример #7
0
 def test_absolute(self):
     t = models.Test(type=models.NUMERICAL)
     r = models.Reference(value=1)
     tol = models.Tolerance(
         type=models.ABSOLUTE,
         act_low=-2,
         tol_low=-1,
         tol_high=1,
         act_high=2,
     )
     result = qa_tags.reference_tolerance_span(t, r, tol)
     self.assertIn("ACT L", result)
Пример #8
0
 def test_percent(self):
     t = models.Test(type=models.NUMERICAL)
     r = models.Reference(value=1)
     tol = models.Tolerance(
         type=models.PERCENT,
         act_low=-2,
         tol_low=-1,
         tol_high=1,
         act_high=2,
     )
     result = qa_tags.reference_tolerance_span(t, r, tol)
     self.assertIn("(-2.00%", result)
Пример #9
0
    def form_valid(self, request, queryset, form):

        if form.is_valid():
            reference = form.cleaned_data['reference']
            tolerance = form.cleaned_data['tolerance']

            # Save the uti with the new references and tolerance
            # TODO: Combine with save method: save_model ?
            for uti in queryset:
                if uti.test.type != models.MULTIPLE_CHOICE:
                    if uti.test.type == models.BOOLEAN:
                        ref_type = models.BOOLEAN
                        if reference == 'True' or reference == 1:
                            reference = 1
                        else:
                            reference = 0
                    else:
                        ref_type = models.NUMERICAL
                    if reference not in ("", None):
                        if not (uti.reference
                                and uti.reference.value == float(reference)):
                            try:
                                ref = models.Reference.objects.get(
                                    value=reference, type=ref_type)
                            except models.Reference.DoesNotExist:
                                ref = models.Reference(
                                    value=reference,
                                    type=ref_type,
                                    created_by=request.user,
                                    modified_by=request.user,
                                    name="%s %s" %
                                    (uti.unit.name, uti.test.name)[:255])
                                ref.save()
                            uti.reference = ref
                    else:
                        uti.reference = None
                uti.tolerance = tolerance
                uti.save()

            messages.success(
                request,
                "%s tolerances and references have been saved successfully." %
                queryset.count())
            return HttpResponseRedirect(request.get_full_path())
Пример #10
0
 def test_no_tol(self):
     t = models.Test(type=models.NUMERICAL)
     r = models.Reference(value=1)
     result = qa_tags.reference_tolerance_span(t, r, None)
     self.assertIn("No Tolerance", result)
Пример #11
0
 def test_bool(self):
     t = models.Test(type=models.BOOLEAN)
     r = models.Reference(value=1)
     self.assertIn("Passing value",
                   qa_tags.reference_tolerance_span(t, r, None))
Пример #12
0
 def test_no_tol(self):
     r = models.Reference(value=1)
     self.assertIn("N/A", qa_tags.tolerance_for_reference(None, r))
Пример #13
0
 def test_bool(self):
     r = models.Reference(value=1, type=models.BOOLEAN)
     self.assertIn("Pass: Yes", qa_tags.tolerance_for_reference(None, r))
Пример #14
0
 def test_bool(self):
     r = models.Reference(value=1, type=models.BOOLEAN)
     self.assertIn("%s: Yes" % (settings.TEST_STATUS_DISPLAY['ok']), qa_tags.tolerance_for_reference(None, r))