Example #1
0
    def test_remove_ref_with_different_browser(self):
        """
        Test the case where we remove a ref a we want to make sure that the new reference is searched with the same browsert 
        """
        with open("snapshotServer/tests/data/test_Image1.png",
                  'rb') as imgFile:

            img = ImageFile(imgFile)

            # snapshot associated to same version, same test case, but other environment as 'initialRefSnapshot'
            snapshot_other_browser = Snapshot(
                stepResult=self.step_result_other_env,
                refSnapshot=None,
                pixelsDiff=None)
            snapshot_other_browser.save()
            snapshot_other_browser.image.save("img", img)
            snapshot_other_browser.save()

            # reference snapshot associated to same version / test case / environment / browser as 'initialRefSnapshot'
            snapshot_ref_same_env = Snapshot(stepResult=self.sr1,
                                             refSnapshot=None,
                                             pixelsDiff=None)
            snapshot_ref_same_env.save()
            snapshot_ref_same_env.image.save("img", img)
            snapshot_ref_same_env.save()

            # snapshot associated to same version / test case / environment / browser as 'snapshot_ref_same_env'
            snapshot_same_env = Snapshot(stepResult=self.step_result_same_env,
                                         refSnapshot=snapshot_ref_same_env,
                                         pixelsDiff=None)
            snapshot_same_env.save()
            snapshot_same_env.image.save("img", img)
            snapshot_same_env.save()

            response = self.client.get(
                reverse('pictureView',
                        kwargs={
                            'testCaseInSessionId': self.tcs1.id,
                            'testStepId': 1
                        }) + "?makeRef=False&snapshotId=" +
                str(snapshot_ref_same_env.id))

            # check display
            self.assertEqual(response.context['captureList'][0]['reference'],
                             self.initialRefSnapshot,
                             "new reference should be the first snapshot")
            self.assertEqual(
                response.context['captureList'][0]['stepSnapshot'].refSnapshot,
                self.initialRefSnapshot,
                "new reference should be the first snapshot")
            self.assertIsNotNone(
                response.context['captureList'][0]['stepSnapshot'].pixelsDiff)
            DiffComputer.stopThread()

            # check 'snapshot_same_env' ref as been changed and its reference snapshot is 'initialRefSnapshot' becaus it's the same environment / test case / version
            self.assertEqual(
                Snapshot.objects.get(id=snapshot_same_env.id).refSnapshot,
                self.initialRefSnapshot,
                "ref snapshot for 'snapshot_same_env' should have changed to first snapshot, not 'snapshot_other_browser'"
            )
 def test_stop_thread(self):
     """
     Thread should be stopped and instance deleted
     """
     inst = DiffComputer.get_instance()
     DiffComputer.stopThread()
     self.assertIsNone(DiffComputer._instance)
    def test_error_message_reset(self):
        """
        Check that if an error occurs during _compute_diff() method, 'computed' flag is still set to 'True' whatever the result is, and 'computingError' is filled  
        If an other computing is done, and no error occurs, then, 'computingError' is reset to an empty string
        """
        with open("snapshotServer/tests/data/test_Image1.png",
                  'rb') as reference:
            with open("snapshotServer/tests/data/test_Image1Mod.png",
                      'rb') as step:
                img_reference = ImageFile(reference)
                img_step = ImageFile(step)
                ref_snapshot = Snapshot(
                    stepResult=StepResult.objects.get(id=1),
                    refSnapshot=None,
                    pixelsDiff=None)
                ref_snapshot.save()
                ref_snapshot.image.save("img", img_reference)
                ref_snapshot.save()
                step_snapshot = Snapshot(
                    stepResult=StepResult.objects.get(id=2),
                    refSnapshot=None,
                    pixelsDiff=None)
                step_snapshot.save()
                step_snapshot.image.save("img", img_step)
                step_snapshot.save()

                diff_computer = DiffComputer.get_instance()
                diff_computer.mark_diff = MagicMock(
                    side_effect=Exception("error while computing"))
                diff_computer.add_jobs(ref_snapshot,
                                       step_snapshot,
                                       check_test_mode=True)
                time.sleep(1)
                self.assertIsNotNone(DiffComputer._instance,
                                     "thread should still be running")

                # check error has been saved
                self.assertTrue(
                    Snapshot.objects.get(id=step_snapshot.id).computed)
                self.assertEqual(
                    Snapshot.objects.get(id=step_snapshot.id).computingError,
                    "error while computing")

                # check error has been removed as computing is ok
                DiffComputer.stopThread()  # reset DiffComputer instance
                diff_computer_ok = DiffComputer.get_instance()
                diff_computer_ok.add_jobs(ref_snapshot,
                                          step_snapshot,
                                          check_test_mode=True)
                time.sleep(1)
                self.assertTrue(
                    Snapshot.objects.get(id=step_snapshot.id).computed)
                self.assertEqual(
                    Snapshot.objects.get(id=step_snapshot.id).computingError,
                    "")
Example #4
0
    def test_remove_ref(self):
        """
        From a picture which is a reference (snapshot_ref_same_env), remove the reference flag. Next snpashots (snapshot_same_env) should then refere to the last 
        reference available
        """
        with open("snapshotServer/tests/data/test_Image1.png",
                  'rb') as imgFile:

            img = ImageFile(imgFile)

            snapshot_ref_same_env = Snapshot(stepResult=self.sr1,
                                             refSnapshot=None,
                                             pixelsDiff=None)
            snapshot_ref_same_env.save()
            snapshot_ref_same_env.image.save("img", img)
            snapshot_ref_same_env.save()

            snapshot_same_env = Snapshot(stepResult=self.step_result_same_env,
                                         refSnapshot=snapshot_ref_same_env,
                                         pixelsDiff=None)
            snapshot_same_env.save()
            snapshot_same_env.image.save("img", img)
            snapshot_same_env.save()

            response = self.client.get(
                reverse('pictureView',
                        kwargs={
                            'testCaseInSessionId': self.tcs1.id,
                            'testStepId': 1
                        }) + "?makeRef=False&snapshotId=" +
                str(snapshot_ref_same_env.id))

            # check display
            self.assertEqual(response.context['captureList'][0]['reference'],
                             self.initialRefSnapshot,
                             "new reference should be the first snapshot")
            self.assertEqual(
                response.context['captureList'][0]['stepSnapshot'].refSnapshot,
                self.initialRefSnapshot,
                "new reference should be the first snapshot")
            self.assertIsNotNone(
                response.context['captureList'][0]['stepSnapshot'].pixelsDiff)
            self.assertEqual(
                response.context['captureList'][0]['diffPercentage'], 0.0)
            DiffComputer.stopThread()

            # check snapshot_same_env ref as been changed
            self.assertEqual(
                Snapshot.objects.get(id=snapshot_same_env.id).refSnapshot,
                self.initialRefSnapshot,
                "ref snapshot for snapshot_same_env should have changed to first snapshot"
            )
Example #5
0
    def test_remove_very_first_ref(self):
        """
        From a picture which is the first reference for a testCase/testStep couple, try to remove the reference
        It should not be possible
        
        We use
        -   model: snapshotServer.testcaseinsession
            pk: 3
            fields:
                testCase: 3
                session: 4
                testSteps: [1]
        -   model: snapshotServer.stepresult
            pk: 3
            fields: 
                step: 1
                testCase: 3
                result: true
        -   model: snapshotServer.snapshot
            pk: 3
            fields: 
                stepResult: 3
                image: documents/test_Image1.png
        """

        response = self.client.get(
            reverse('pictureView',
                    kwargs={
                        'testCaseInSessionId': 3,
                        'testStepId': 1
                    }) + "?makeRef=False&snapshotId=3")

        # check display
        self.assertIsNone(response.context['captureList'][0]['reference'],
                          "picture is still a reference")
        self.assertIsNone(
            response.context['captureList'][0]['stepSnapshot'].refSnapshot,
            "new reference should be the snapshot itself")
        self.assertIsNone(
            response.context['captureList'][0]['stepSnapshot'].pixelsDiff,
            "no diff as we have a reference")
        DiffComputer.stopThread()
Example #6
0
 def tearDown(self):
     DiffComputer.stopThread()
     logging.error("Stop threads")
     super().tearDown()
Example #7
0
    def test_make_new_ref(self):
        """
        From a picture which is not a reference (snapshot_future_ref_same_env), make it a new ref
        'snapshot_same_env' should then have 'snapshot_future_ref_same_env' as reference because it has a higher id than 'initialRefSnapshot' and same name / browser / environment / version
        """
        with open("snapshotServer/tests/data/test_Image1.png",
                  'rb') as imgFile:

            img = ImageFile(imgFile)

            snapshot_future_ref_same_env = Snapshot(
                stepResult=self.sr1,
                refSnapshot=self.initialRefSnapshot,
                pixelsDiff=None)
            snapshot_future_ref_same_env.save()
            snapshot_future_ref_same_env.image.save("img", img)
            snapshot_future_ref_same_env.save()

            exclusion1 = ExcludeZone(x=0,
                                     y=0,
                                     width=10,
                                     height=10,
                                     snapshot=self.initialRefSnapshot)
            exclusion1.save()
            exclusion2 = ExcludeZone(x=10,
                                     y=10,
                                     width=10,
                                     height=10,
                                     snapshot=self.initialRefSnapshot)
            exclusion2.save()
            self.assertEqual(
                len(
                    ExcludeZone.objects.filter(
                        snapshot=self.initialRefSnapshot)), 2)
            self.assertEqual(
                len(
                    ExcludeZone.objects.filter(
                        snapshot=snapshot_future_ref_same_env)), 0)

            snapshot_same_env = Snapshot(stepResult=self.step_result_same_env,
                                         refSnapshot=self.initialRefSnapshot,
                                         pixelsDiff=None)
            snapshot_same_env.save()
            snapshot_same_env.image.save("img", img)
            snapshot_same_env.save()

            response = self.client.get(
                reverse('pictureView',
                        kwargs={
                            'testCaseInSessionId': self.tcs1.id,
                            'testStepId': 1
                        }) + "?makeRef=True&snapshotId=" +
                str(snapshot_future_ref_same_env.id))

            # check display
            self.assertIsNone(response.context['captureList'][0]['reference'],
                              "new reference should be the snapshot itself")
            self.assertIsNone(
                response.context['captureList'][0]['stepSnapshot'].refSnapshot,
                "new reference should be the snapshot itself")
            self.assertIsNone(
                response.context['captureList'][0]['stepSnapshot'].pixelsDiff)
            DiffComputer.stopThread()

            # check snapshot_same_env ref as been changed
            self.assertEqual(
                Snapshot.objects.get(id=snapshot_same_env.id).refSnapshot,
                snapshot_future_ref_same_env,
                "ref snapshot for snapshot_same_env should have changed to snapshot_future_ref_same_env"
            )
            self.assertEqual(
                Snapshot.objects.get(id=2).refSnapshot,
                self.initialRefSnapshot,
                "snapshot previous to snapshot_future_ref_same_env should not have change"
            )

            # check 'initialRefSnapshot' has kept its references
            self.assertEqual(
                len(
                    ExcludeZone.objects.filter(
                        snapshot=self.initialRefSnapshot)), 2)

            # check new ref 'snapshot_future_ref_same_env' has got a copy of the exclusion zones
            self.assertEqual(
                len(
                    ExcludeZone.objects.filter(
                        snapshot=snapshot_future_ref_same_env)), 2)
Example #8
0
    def test_make_new_ref_diff_image(self):
        """
        Compare 2 pictures (force computation to be sure we have diff data)
        Check we get the diff percentage
        """
        with open("snapshotServer/tests/data/test_Image1.png",
                  'rb') as imgFile:
            with open("snapshotServer/tests/data/test_Image1Mod.png",
                      'rb') as img_file_mod:

                img = ImageFile(imgFile)
                img_mod = ImageFile(img_file_mod)

                snapshot_future_ref_same_env = Snapshot(
                    stepResult=self.sr1,
                    refSnapshot=self.initialRefSnapshot,
                    pixelsDiff=None)
                snapshot_future_ref_same_env.save()
                snapshot_future_ref_same_env.image.save("img", img)
                snapshot_future_ref_same_env.save()

                exclusion1 = ExcludeZone(x=0,
                                         y=0,
                                         width=10,
                                         height=10,
                                         snapshot=self.initialRefSnapshot)
                exclusion1.save()
                exclusion2 = ExcludeZone(x=10,
                                         y=10,
                                         width=10,
                                         height=10,
                                         snapshot=self.initialRefSnapshot)
                exclusion2.save()
                self.assertEqual(
                    len(
                        ExcludeZone.objects.filter(
                            snapshot=self.initialRefSnapshot)), 2)
                self.assertEqual(
                    len(
                        ExcludeZone.objects.filter(
                            snapshot=snapshot_future_ref_same_env)), 0)

                snapshot_same_env = Snapshot(
                    stepResult=self.step_result_same_env,
                    refSnapshot=self.initialRefSnapshot,
                    pixelsDiff=None)
                snapshot_same_env.save()
                snapshot_same_env.image.save("img", img_mod)
                snapshot_same_env.save()

                # force computing
                self.client.get(
                    reverse('pictureView',
                            kwargs={
                                'testCaseInSessionId': self.tcs1.id,
                                'testStepId': 1
                            }) + "?makeRef=True&snapshotId=" +
                    str(snapshot_future_ref_same_env.id))

                DiffComputer.stopThread()

                # ask for the step snapshot and look for data
                response = self.client.get(
                    reverse('pictureView',
                            kwargs={
                                'testCaseInSessionId': self.tcs_same_env.id,
                                'testStepId': 1
                            }) + "?snapshotId=" + str(snapshot_same_env.id))
                self.assertIsNotNone(response.context['captureList'][0]
                                     ['stepSnapshot'].pixelsDiff)
                self.assertTrue(response.context['captureList'][0]
                                ['diffPercentage'] > 0.086)