Пример #1
0
 def test_save_pack(self):
     pack = testpack.create_testpack(self.tlqs, self.tlcqs)
     fp = io.StringIO()
     testpack.save_testpack(pack, fp)
     fp.seek(0)
     # check the accented character in test list 1 name was written
     assert "\\u00e9" in fp.read()
Пример #2
0
    def form_valid(self, form):
        tls = form.cleaned_data['testlists']
        cycles = form.cleaned_data['testlistcycles']
        extra_tests = form.cleaned_data['tests']
        desc = form.cleaned_data['description']
        user = self.request.user
        name = form.cleaned_data['name']
        try:
            tp = create_testpack(
                test_lists=tls,
                cycles=cycles,
                extra_tests=extra_tests,
                description=desc,
                user=user,
                name=name,
                timeout=settings.TESTPACK_TIMEOUT,
            )
        except RuntimeError as e:
            form.add_error(None, ValidationError(str(e), code="timeout"))
            return self.form_invalid(form)

        response = HttpResponse(json.dumps(tp),
                                content_type='application/json')
        response['Content-Disposition'] = 'attachment; filename=%s' % (name +
                                                                       ".tpk")
        return response
Пример #3
0
 def test_extra_tests(self):
     extra = utils.create_test("extra test")
     extra_qs = models.Test.objects.filter(pk=extra.pk)
     pack = testpack.create_testpack(self.tlqs,
                                     self.tlcqs,
                                     extra_tests=extra_qs)
     fp = io.StringIO()
     testpack.save_testpack(pack, fp)
     fp.seek(0)
     assert "extra test" in fp.read()
Пример #4
0
 def test_non_destructive_load(self):
     ntl = models.TestList.objects.count()
     nt = models.Test.objects.count()
     pack = testpack.create_testpack(self.tlqs, self.tlcqs, self.extra)
     fp = io.StringIO()
     testpack.save_testpack(pack, fp)
     fp.seek(0)
     testpack.load_testpack(fp)
     assert models.TestList.objects.count() == 2 * ntl
     assert models.Test.objects.count() == 2 * nt
Пример #5
0
    def test_existing_created_user_not_overwritten(self):
        user2 = utils.create_user(uname="user2")
        pack = testpack.create_testpack(self.tlqs, self.tlcqs)

        fp = io.StringIO()
        testpack.save_testpack(pack, fp)
        fp.seek(0)
        testpack.load_testpack(fp, user2)

        assert models.TestList.objects.get(
            slug=self.tl1.slug).created_by != user2
Пример #6
0
 def test_extra_tests_loaded(self):
     extra = utils.create_test("extra test")
     extra_qs = models.Test.objects.filter(pk=extra.pk)
     pack = testpack.create_testpack(self.tlqs,
                                     self.tlcqs,
                                     extra_tests=extra_qs)
     fp = io.StringIO()
     testpack.save_testpack(pack, fp)
     fp.seek(0)
     models.Test.objects.all().delete()
     testpack.load_testpack(fp,
                            test_keys=[extra.natural_key()],
                            test_list_keys=[],
                            cycle_keys=[])
     assert models.Test.objects.filter(name=extra.name).exists()
Пример #7
0
    def test_load(self):
        pack = testpack.create_testpack(self.tlqs, self.tlcqs)
        models.TestList.objects.all().delete()
        models.Test.objects.all().delete()
        models.TestListCycle.objects.all().delete()

        fp = io.StringIO()
        testpack.save_testpack(pack, fp)
        fp.seek(0)
        testpack.load_testpack(fp)

        assert models.TestList.objects.filter(name=self.tl1.name).exists()
        assert models.Test.objects.filter(name=self.t1.name).exists()
        assert models.TestListCycle.objects.filter(name=self.tlc.name).exists()
        assert self.tl1.name in models.TestListCycle.objects.values_list(
            "test_lists__name", flat=True)
Пример #8
0
    def test_round_trip(self):
        pack = json.dumps(
            testpack.create_testpack(
                test_lists=self.tlqs,
                cycles=self.tlcqs,
                extra_tests=self.extra,
            ))
        models.TestListCycle.objects.all().delete()
        models.TestList.objects.all().delete()
        models.Test.objects.all().delete()
        models.Category.objects.all().delete()
        testpack.add_testpack(pack)

        assert models.Test.objects.count() == 4
        assert models.TestList.objects.count() == 3
        assert models.TestListMembership.objects.count() == 4
        assert models.TestListCycle.objects.count() == 1
        assert models.TestListCycleMembership.objects.count() == 2
Пример #9
0
 def test_sublist(self):
     tl5 = utils.create_test_list("tl5")
     t5 = utils.create_test("t5")
     utils.create_test_list_membership(tl5, t5, order=0)
     utils.create_sublist(tl5, self.tl1, order=2)
     utils.create_sublist(tl5, self.tl2, order=3)
     pack = json.dumps(
         testpack.create_testpack(test_lists=models.TestList.objects.filter(
             pk=tl5.pk)))
     models.TestList.objects.all().delete()
     models.Test.objects.all().delete()
     assert models.Sublist.objects.count() == 0
     testpack.add_testpack(pack, test_list_keys=[tl5.natural_key()])
     assert models.Sublist.objects.count() == 2
     assert models.TestListMembership.objects.count() == 3
     for sl in models.Sublist.objects.all():
         assert sl.child.testlistmembership_set.count() == 1
     assert models.TestList.objects.count() == 3
     assert models.TestList.objects.get(name="tl5")
Пример #10
0
    def test_existing_objs_not_deleted(self):
        pack = testpack.create_testpack(self.tlqs, self.tlcqs)

        fp = io.StringIO()
        testpack.save_testpack(pack, fp)
        fp.seek(0)
        testpack.load_testpack(
            fp,
            test_keys=[self.t1.natural_key()],
            test_list_keys=[self.tl1.natural_key()],
            cycle_keys=[],
        )

        assert models.TestList.objects.filter(
            name__in=[self.tl2.name, self.tl3.name]).count() == 2
        assert models.Test.objects.filter(
            name__in=[self.t2.name, self.t3.name]).count() == 2
        assert models.TestListCycle.objects.filter(
            name__in=[self.tlc.name]).count() == 1
Пример #11
0
    def test_selective_load(self):
        pack = testpack.create_testpack(models.TestList.objects.all(),
                                        self.tlcqs)
        models.TestList.objects.all().delete()
        models.Test.objects.all().delete()
        models.TestListCycle.objects.all().delete()

        fp = io.StringIO()
        testpack.save_testpack(pack, fp)
        fp.seek(0)
        testpack.load_testpack(
            fp,
            test_keys=[self.t1.natural_key()],
            test_list_keys=[self.tl1.natural_key()],
            cycle_keys=[],
        )

        assert models.TestList.objects.count() == 1
        assert models.Test.objects.count() == 1
        assert models.TestListCycle.objects.count() == 0
Пример #12
0
    def test_create_pack(self):

        pack = testpack.create_testpack(self.tlqs, self.tlcqs)

        assert 'meta' in pack
        assert 'objects' in pack

        test_found = False
        list_found = False
        for tl_dat in pack['objects']['testlists']:
            tl = json.loads(tl_dat)
            if tl['object']['fields']['name'] == self.tl3.name:
                list_found = True

            for o in tl['dependencies']:
                try:
                    if o['fields']['name'] == self.t3.name:
                        test_found = True
                except KeyError:
                    pass

        assert list_found and test_found
def create_dqa3(mode, beams):

    params = [
        "Signature",
        "Temperature",
        "Pressure",
        "Dose",
        "Dose Baseline",
        "Dose Diff",
        "AxSym",
        "AxSym Baseline",
        "AxSym Diff",
        "TrSym",
        "TrSym Baseline",
        "TrSym Diff",
        "QAFlat",
        "QAFlat Baseline",
        "QAFlat Diff",
        "Energy",
        "Energy Baseline",
        "Energy Diff",
        "XSize",
        "XSize Baseline",
        "XSize Diff",
        "XShift",
        "XShift Baseline",
        "XShift Diff",
        "YSize",
        "YSize Baseline",
        "YSize Diff",
        "YShift",
        "YShift Baseline",
        "YShift Diff",
        "Data Key",
    ]
    string_tests = ["Signature", "Data Key"]

    try:
        with transaction.atomic():

            cat = "Daily QA3"
            cat, _ = models.Category.objects.get_or_create(
                name=cat,
                defaults={
                    "slug": slugify(cat),
                    "description": cat,
                },
            )

            parent_test_list_name = f"Daily QA3 Results"
            print(f"Creating Test List: {parent_test_list_name}")
            parent_test_list, _ = models.TestList.objects.get_or_create(
                name=parent_test_list_name,
                slug=slugify(parent_test_list_name),
                defaults={
                    "created_by": user,
                    "modified_by": user,
                },
            )

            for beam_num, beam in enumerate(beams):

                test_list_name = f"Daily QA3 Results: {beam}"
                print(f"Creating Test List: {test_list_name}")
                test_list, _ = models.TestList.objects.get_or_create(
                    name=test_list_name,
                    slug=slugify(test_list_name),
                    defaults={
                        "created_by": user,
                        "modified_by": user,
                    },
                )
                for param_idx, param in enumerate(params):

                    unit = ""
                    if param == "Pressure":
                        unit = "kPa"
                    elif param == "Temperature":
                        unit = "°C"
                    elif param not in string_tests:
                        unit = "%" if 'shift' not in param.lower() and 'size' not in param.lower() else "cm"
                    name = f"{beam}: {param} ({unit})" if unit else f"{beam}: {param}"
                    test_name = f"DQA3 Results: {name}"
                    slug = ("%s_%s" % (slugify(param), slugify(beam))).lower().replace("-", "_")
                    print(f"\tCreating Test: {test_name} ({slug})")
                    test, _ = models.Test.objects.get_or_create(
                        name=test_name,
                        display_name=name,
                        slug=slug,
                        type=models.SIMPLE if param not in string_tests else models.STRING,
                        defaults={
                            "created_by": user,
                            "modified_by": user,
                            "formatting": "%.3f" if param not in string_tests else "",
                            "category": cat,
                            "description": "",
                        },
                    )
                    models.TestListMembership.objects.get_or_create(
                        test=test,
                        test_list=test_list,
                        order=param_idx,
                    )
                models.Sublist.objects.create(parent=parent_test_list, child=test_list, outline=True, order=beam_num)

            if mode == "testpack":
                tp = create_testpack(test_lists=[parent_test_list])
                fname = "grouped-dqa3-qcpump-test-list.tpk" % beam.lower()
                json.dump(tp, open(fname, "w"), indent=2)
                print("Wrote '%s' Test Pack to %s" % (parent_test_list.name, fname))
                raise Rollback("Rollback so we don't actually save the tests")
            else:
                domain = Site.objects.get_current().domain
                url = '%s://%s%s' % (settings.HTTP_OR_HTTPS, domain, parent_test_list.get_absolute_url())
                print("Created '%s' Test List (%s)" % (parent_test_list.name, url))

    except IntegrityError:
        print(
            "\tThere was a conflict with an existing Test List slug or "
            "Test name when trying to create this test list."
        )
    except Rollback:
        pass
Пример #14
0
    def test_timeout(self):

        with self.assertRaises(RuntimeError):
            with mock.patch('time.time', mock.Mock(side_effect=time)):
                testpack.create_testpack(self.tlqs, self.tlcqs, timeout=1)