def test_is_ok_with_one_step_ko(self):
        tcs = TestCaseInSession.objects.get(pk=5)
        s1 = TestStep.objects.get(pk=2)
        s2 = TestStep.objects.get(pk=3)
        sr1 = StepResult(step=s1, testCase=tcs, result=False)
        sr1.save()
        sr2 = StepResult(step=s2, testCase=tcs, result=True)
        sr2.save()

        self.assertFalse(tcs.isOkWithResult())
Beispiel #2
0
    def setUp(self):
        self.client = Client()
        authenticate_test_client_for_web_view(self.client)

        # prepare data
        self.testCase = TestCase.objects.get(id=1)
        self.initialRefSnapshot = Snapshot.objects.get(id=1)
        self.step1 = TestStep.objects.get(id=1)

        self.session1 = TestSession(
            sessionId="1237",
            date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC),
            browser="firefox",
            version=Version.objects.get(pk=1),
            environment=TestEnvironment.objects.get(id=1),
            ttl=datetime.timedelta(0))
        self.session1.save()
        self.tcs1 = TestCaseInSession(testCase=self.testCase,
                                      session=self.session1)
        self.tcs1.save()
        self.sr1 = StepResult(step=self.step1, testCase=self.tcs1, result=True)
        self.sr1.save()

        self.session_same_env = TestSession(
            sessionId="1238",
            date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC),
            browser="firefox",
            version=Version.objects.get(pk=1),
            environment=TestEnvironment.objects.get(id=1),
            ttl=datetime.timedelta(0))
        self.session_same_env.save()
        self.tcs_same_env = TestCaseInSession(testCase=self.testCase,
                                              session=self.session_same_env)
        self.tcs_same_env.save()
        self.step_result_same_env = StepResult(step=self.step1,
                                               testCase=self.tcs_same_env,
                                               result=True)
        self.step_result_same_env.save()

        # session with other env (AUT instead of DEV), other characteristics remain the same as session1
        self.session_other_env = TestSession.objects.get(pk=10)
        self.tcs_other_env = TestCaseInSession.objects.get(pk=9)
        self.step_result_other_env = StepResult.objects.get(pk=11)

        # session with other browser (chrome instead of firefox), other characteristics remain the same as session1
        self.session_other_browser = TestSession.objects.get(pk=11)
        self.tcs_other_browser = TestCaseInSession.objects.get(pk=10)
        self.step_result_other_browser = StepResult.objects.get(pk=12)
 def test_delete_old_sessions_with_no_reference(self):
     """
     Delete sessions that have snapshots (but no reference, with a ttl > 0, which are older than the ttl
     """
     s1 = TestSession(sessionId="1234", 
                      date=timezone.now() - datetime.timedelta(days=4), 
                      browser="firefox", 
                      environment=TestEnvironment.objects.get(pk=1), 
                      version=Version.objects.get(pk=1), 
                      ttl=datetime.timedelta(days=0))
     s1.save()
     step = TestStep(name="step1")
     step.save()
     tc1 = TestCase(name="case1", application=Application.objects.get(pk=1))
     tc1.save()
     tcs1 = TestCaseInSession(testCase=tc1, session=s1)
     tcs1.save()
     tcs1.testSteps.set([step])
     tcs1.save()
     tsr1 = StepResult(step=step, testCase=tcs1, result=True)
     tsr1.save()
     
     # add a snapshot without reference => its a reference itself
     sn0 = Snapshot(stepResult=StepResult.objects.get(pk=1), image=None, refSnapshot=None, pixelsDiff=None)
     sn0.save()
     sn1 = Snapshot(stepResult=tsr1, image=None, refSnapshot=sn0, pixelsDiff=None)
     sn1.save()
     
     s1.ttl = datetime.timedelta(days=3)
     s1.save()
     
     # s1 should have been deleted
     self.assertRaises(TestSession.DoesNotExist, TestSession.objects.get, pk=s1.id)
Beispiel #4
0
    def test_is_ko_with_snapshots_ko_and_result_ok(self):
        """
        Step is KO when at least one snapshot is KO even if step result is OK
        """
        tcs = TestCaseInSession.objects.get(pk=5)
        step = TestStep.objects.get(pk=2)
        step_result = StepResult(step=step, testCase=tcs,
                                 result=True)  # step without snapshots
        step_result.save()

        # one snapshot with comparison error
        snapshot1 = Snapshot(stepResult=step_result,
                             image=None,
                             refSnapshot=None,
                             pixelsDiff=b"12345",
                             tooManyDiffs=True)
        snapshot1.save()

        # one snapshot without comparison error
        snapshot2 = Snapshot(stepResult=step_result,
                             image=None,
                             refSnapshot=None,
                             pixelsDiff=None,
                             tooManyDiffs=False)
        snapshot2.save()

        # Step is KO because one snapshot has comparison error
        self.assertFalse(step.isOkWithSnapshots(tcs))
 def setUp(self):
     super().setUp()
     self.app = Application(name="test")
     self.app.save()
     self.v1 = Version(application=self.app, name='1.0')
     self.v1.save()
     self.v2 = Version(application=self.app, name='2.0')
     self.v2.save()
     env = TestEnvironment(name='DEV')
     env.save()
     self.session1 = TestSession(sessionId="1234", date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC), browser="firefox", environment=env, version=self.v1, ttl=datetime.timedelta(0))
     self.session1.save()
     self.session_same_env = TestSession(sessionId="1235", date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC), browser="firefox", environment=env, version=self.v1, ttl=datetime.timedelta(0))
     self.session_same_env.save()
     self.session3 = TestSession(sessionId="1236", date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC), browser="firefox", environment=env, version=self.v2, ttl=datetime.timedelta(0))
     self.session3.save()
     self.session4 = TestSession(sessionId="1237", date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC), browser="firefox", environment=env, version=self.v2, ttl=datetime.timedelta(0))
     self.session4.save()
     self.step = TestStep(name="step1")
     self.step.save()
     self.tc1 = TestCase(name="case1", application=self.app)
     self.tc1.save()
     self.tcs1 = TestCaseInSession(testCase=self.tc1, session=self.session1)
     self.tcs1.save()
     self.tcs_same_env = TestCaseInSession(testCase=self.tc1, session=self.session_same_env)
     self.tcs_same_env.save()
     self.tcs3 = TestCaseInSession(testCase=self.tc1, session=self.session3)
     self.tcs3.save()
     self.tcs4 = TestCaseInSession(testCase=self.tc1, session=self.session4)
     self.tcs4.save()
     self.tcs1.testSteps.set([self.step])
     self.tcs1.save()
     self.tcs_same_env.testSteps.set([self.step])
     self.tcs_same_env.save()
     self.tsr1 = StepResult(step=self.step, testCase=self.tcs1, result=True)
     self.tsr1.save()
     self.tsr2 = StepResult(step=self.step, testCase=self.tcs_same_env, result=True)
     self.tsr2.save()
     self.tsr3 = StepResult(step=self.step, testCase=self.tcs3, result=True)
     self.tsr3.save()
     self.tsr4 = StepResult(step=self.step, testCase=self.tcs4, result=True)
     self.tsr4.save()
Beispiel #6
0
    def test_is_ko_without_snapshots_and_result_ko(self):
        """
        Step is OK when no snapshot is present and step result is OK
        """
        tcs = TestCaseInSession.objects.get(pk=5)
        step = TestStep.objects.get(pk=2)
        step_result = StepResult(step=step, testCase=tcs,
                                 result=False)  # step without snapshots
        step_result.save()

        self.assertFalse(step.isOkWithSnapshots(tcs))
    def test_post_snapshot_existing_ref_in_previous_version(self):
        """
        Check that we search for a reference in a previous version if none is found in the current one
        """

        # same as self.testCase in a greater version
        session3 = TestSession(sessionId="8890",
                               date=datetime.datetime(2017,
                                                      5,
                                                      7,
                                                      tzinfo=pytz.UTC),
                               browser="firefox",
                               version=Version.objects.get(pk=2),
                               environment=TestEnvironment.objects.get(id=1),
                               ttl=datetime.timedelta(0))
        session3.save()
        tcs3 = TestCaseInSession(testCase=self.testCase, session=session3)
        tcs3.save()
        tcs3.testSteps.set([TestStep.objects.get(id=1)])
        tcs3.save()
        sr3 = StepResult(step=TestStep.objects.get(id=1),
                         testCase=tcs3,
                         result=True)
        sr3.save()

        with open('snapshotServer/tests/data/engie.png', 'rb') as fp:
            self.client.post(reverse('upload', args=['img']),
                             data={
                                 'stepResult': self.sr1.id,
                                 'image': fp,
                                 'name': 'img',
                                 'compare': 'true'
                             })
            uploaded_snapshot_1 = Snapshot.objects.filter(
                stepResult__testCase=self.tcs1, stepResult__step__id=1).last()

        with open('snapshotServer/tests/data/engie.png', 'rb') as fp:
            response = self.client.post(reverse('upload', args=['img']),
                                        data={
                                            'stepResult': sr3.id,
                                            'image': fp,
                                            'name': 'img',
                                            'compare': 'true'
                                        })
            self.assertEqual(
                response.status_code, 201,
                'status code should be 201: ' + str(response.content))

            uploaded_snapshot_2 = Snapshot.objects.filter(
                stepResult__testCase=tcs3, stepResult__step__id=1).last()
            self.assertIsNotNone(uploaded_snapshot_2,
                                 "the uploaded snapshot should be recorded")
            self.assertEqual(uploaded_snapshot_2.refSnapshot,
                             uploaded_snapshot_1)
Beispiel #8
0
    def clean(self):
        super().clean()
        try:
            self.cleaned_data['stepName']
            self.cleaned_data['testCaseName']
            self.cleaned_data['versionId']
            self.cleaned_data['environmentId']
            self.cleaned_data['browser']
        except KeyError as e:
            raise forms.ValidationError(
                "stepName, testCaseName, version, environment, browser must be specified"
            )

        # create the StepResult object from provided data
        version = Version.objects.get(id=self.cleaned_data['versionId'])
        environment = TestEnvironment.objects.get(
            id=self.cleaned_data['environmentId'])
        test_case = TestCase(name=self.cleaned_data['testCaseName'],
                             application=version.application)
        test_session = TestSession(sessionId='123',
                                   version=version,
                                   browser=self.cleaned_data['browser'],
                                   environment=environment,
                                   compareSnapshot=True,
                                   ttl=datetime.timedelta(days=0))

        step = TestStep.objects.get(name=self.cleaned_data['stepName'])
        test_case_in_session = TestCaseInSession(testCase=test_case,
                                                 session=test_session)
        self.cleaned_data['stepResult'] = StepResult(
            step=step, testCase=test_case_in_session, result=True)
        self.cleaned_data['storeSnapshot'] = False

        if self.cleaned_data['diffTolerance'] == None:
            self.cleaned_data['diffTolerance'] = 0.0

        if self.cleaned_data['compare'] not in ['true', 'false']:
            self.cleaned_data['compare'] = 'true'
 def test_delete_old_sessions_with_reference(self):
     """
     Do not delete sessions that have reference snapshots, with a ttl > 0, which are older than the ttl
     """
     s1 = TestSession(sessionId="1234", 
                      date=timezone.now() - datetime.timedelta(days=4), 
                      browser="firefox", 
                      environment=TestEnvironment.objects.get(pk=1), 
                      version=Version.objects.get(pk=1), 
                      ttl=datetime.timedelta(days=0))
     s1.save()
     step1 = TestStep(name="step1")
     step1.save()
     step2 = TestStep(name="step2")
     step2.save()
     tc1 = TestCase(name="case1", application=Application.objects.get(pk=1))
     tc1.save()
     tcs1 = TestCaseInSession(testCase=tc1, session=s1)
     tcs1.save()
     tcs1.testSteps.set([step1])
     tcs1.save()
     tsr1 = StepResult(step=step1, testCase=tcs1, result=True)
     tsr1.save()
     tsr2 = StepResult(step=step2, testCase=tcs1, result=True)
     tsr2.save()
     
     # add a snapshot without reference => its a reference itself
     sn1 = Snapshot(stepResult=tsr1, image=None, refSnapshot=None, pixelsDiff=None)
     sn1.save()
     sn2 = Snapshot(stepResult=tsr2, image=None, refSnapshot=sn1, pixelsDiff=None)
     sn2.save()
     
     s1.ttl = datetime.timedelta(days=3)
     s1.save()
     
     # old session without reference
     s2 = TestSession(sessionId="1235", 
                      date=timezone.now() - datetime.timedelta(days=4), 
                      browser="firefox", 
                      environment=TestEnvironment.objects.get(pk=1), 
                      version=Version.objects.get(pk=1), 
                      ttl=datetime.timedelta(days=0))
     s2.save()
     tcs2 = TestCaseInSession(testCase=tc1, session=s2)
     tcs2.save()
     tcs2.testSteps.set([step1])
     tcs2.save()
     tsr2 = StepResult(step=step1, testCase=tcs2, result=True)
     tsr2.save()
     
     # add a snapshot with reference
     sn2 = Snapshot(stepResult=tsr2, image=None, refSnapshot=sn1, pixelsDiff=None)
     sn2.save()
     s2.ttl = datetime.timedelta(days=3)
     s2.save()
     
     # session1 should not be deleted
     TestSession.objects.get(pk=s1.id)
     
     # session2 should  be deleted
     self.assertRaises(TestSession.DoesNotExist, TestSession.objects.get, pk=s2.id)
    def setUp(self):
        authenticate_test_client_for_api(self.client)

        # test in a version
        self.testCase = TestCase(name='test upload',
                                 application=Application.objects.get(id=1))
        self.testCase.save()
        self.step1 = TestStep.objects.get(id=1)

        self.session1 = TestSession(
            sessionId="8888",
            date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC),
            browser="firefox",
            version=Version.objects.get(pk=1),
            environment=TestEnvironment.objects.get(id=1),
            ttl=datetime.timedelta(0))
        self.session1.save()
        self.tcs1 = TestCaseInSession(testCase=self.testCase,
                                      session=self.session1)
        self.tcs1.save()
        self.sr1 = StepResult(step=self.step1, testCase=self.tcs1, result=True)
        self.sr1.save()

        self.session_same_env = TestSession(
            sessionId="8889",
            date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC),
            browser="firefox",
            version=Version.objects.get(pk=1),
            environment=TestEnvironment.objects.get(id=1),
            ttl=datetime.timedelta(0))
        self.session_same_env.save()
        self.tcs_same_env = TestCaseInSession(testCase=self.testCase,
                                              session=self.session_same_env)
        self.tcs_same_env.save()
        self.step_result_same_env = StepResult(step=self.step1,
                                               testCase=self.tcs_same_env,
                                               result=True)
        self.step_result_same_env.save()

        self.session_other_env = TestSession(
            sessionId="8890",
            date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC),
            browser="firefox",
            version=Version.objects.get(pk=1),
            environment=TestEnvironment.objects.get(id=2),
            ttl=datetime.timedelta(0))
        self.session_other_env.save()
        self.tcs_other_env = TestCaseInSession(testCase=self.testCase,
                                               session=self.session_other_env)
        self.tcs_other_env.save()
        self.step_result_other_env = StepResult(step=self.step1,
                                                testCase=self.tcs_other_env,
                                                result=True)
        self.step_result_other_env.save()

        self.session_other_browser = TestSession(
            sessionId="8891",
            date=datetime.datetime(2017, 5, 7, tzinfo=pytz.UTC),
            browser="chrome",
            version=Version.objects.get(pk=1),
            environment=TestEnvironment.objects.get(id=1),
            ttl=datetime.timedelta(0))
        self.session_other_browser.save()
        self.tcs_other_browser = TestCaseInSession(
            testCase=self.testCase, session=self.session_other_browser)
        self.tcs_other_browser.save()
        self.step_result_other_browser = StepResult(
            step=self.step1, testCase=self.tcs_other_browser, result=True)
        self.step_result_other_browser.save()