예제 #1
0
    def test_validate_submission_time_different_timezone(self):
        """
        Test that submission_time timezone is converted to the applications
        timezone and correctly validated
        """
        # Works with different timezones
        # Create task with start date based on a Timezone
        instance = self._create_instance()
        # Create start and end date as UTC+3
        start_date = datetime.now(pytz.timezone('Africa/Nairobi'))
        end_date = start_date + timedelta(days=2)
        task = mommy.make(
            'main.Task',
            target_content_type=self.xform_type,
            target_object_id=instance.xform.id,
            start=start_date.isoformat(),
            end=end_date.isoformat(),
        )

        data = instance.json
        # Store Submission as Datestring with no TZInfo
        submission_time = start_date + timedelta(minutes=60)
        end_time = submission_time + timedelta(minutes=10)

        # Create a TaskOccurence within the submission_time window
        # Based on GMT+3
        mommy.make('main.TaskOccurrence',
                   task=task,
                   date=submission_time.date(),
                   start_time=start_date.time(),
                   end_time=end_time.time())

        submission_time = submission_time.astimezone(pytz.utc)
        data['_submission_time'] = submission_time.isoformat()

        status, comment = validate_submission_time(task,
                                                   data['_submission_time'])

        self.assertEqual(Submission.PENDING, status)
        self.assertEqual("", comment)

        # Test still validates if timezone is not specified in submission_time
        data['_submission_time'] = data['_submission_time'].replace(
            '+00:00', '')
        status, comment = validate_submission_time(task,
                                                   data['_submission_time'])

        self.assertEqual(Submission.PENDING, status)
        self.assertEqual("", comment)
예제 #2
0
    def test_validate_submission_time_with_invalid_data(self):
        """
        Test that validate_submission_time works the way it should
        for invalid data
        """
        instance = self._create_instance()
        data = instance.json

        data['_submission_time'] = "2018-06-18T22:42:07"

        task = mommy.make(
            'main.Task',
            timing_rule='FREQ=DAILY;INTERVAL=1;UNTIL=20180618T210000Z',
            target_content_type=self.xform_type,
            target_object_id=instance.xform.id)

        status, comment = validate_submission_time(task,
                                                   data['_submission_time'])

        self.assertEqual(Submission.REJECTED, status)
        self.assertEqual(INVALID_SUBMISSION_TIME, comment)
예제 #3
0
    def test_validate_submission_time(self):
        """
        Test that validate_submission_time works the way
        it should for valid data
        """
        instance = self._create_instance()
        data = instance.json
        now = timezone.now()
        rrule = f'FREQ=DAILY;INTERVAL=1;UNTIL={now.year + 1}0729T210000Z'

        task = mommy.make('main.Task',
                          timing_rule=rrule,
                          target_content_type=self.xform_type,
                          target_object_id=instance.xform.id)

        data['_submission_time'] = (task.start +
                                    timedelta(minutes=45)).isoformat()

        status, comment = validate_submission_time(task,
                                                   data['_submission_time'])

        self.assertEqual(Submission.PENDING, status)
        self.assertEqual("", comment)