Exemple #1
0
    def test_positive_values_in_btree(self):
        bt = family.IO.BTree()

        for i in range(1, 10000, 10):
            bt[time_to_64bit_int(i)] = str(i)

        for i in range(1, 10000, 10):
            assert_that(bt, has_entry(time_to_64bit_int(i), str(i)))
Exemple #2
0
    def test_increasing(self):

        prev = 0
        i = 1
        while i < 10000:

            ti = time_to_64bit_int(i)
            nti = time_to_64bit_int(-i)

            assert_that(ti, greater_than(time_to_64bit_int(prev)))
            assert_that(ti, greater_than(nti))

            prev = i
            i += 1.5
Exemple #3
0
    def createDeliveryAttempt(self, payload_data):
        attempt = self._new_deliveryAttempt()
        attempt.payload_data = payload_data

        # Store the attempt (make it contained by this object) before we
        # conceivably change its status. Changing the status
        # can fire events, and we need to know the parent for those events to
        # work properly.

        # Choose names that are easily sortable, since that's
        # our iteration order.
        now = str(time_to_64bit_int(time.time()))
        name = INameChooser(self).chooseName(now, attempt)  # pylint:disable=too-many-function-args,assignment-from-no-return
        self[name] = attempt

        # Verify the destination. Fail early
        # if it doesn't pass.
        validator = component.getUtility(IWebhookDestinationValidator, u'',
                                         self)
        try:
            validator.validateTarget(self.to)
        except Exception:  # pylint:disable=broad-except
            # The exception value can vary; it's not intended to be presented to end
            # users as-is
            attempt.message = (
                u'Verification of the destination URL failed. Please check the domain.'
            )
            attempt.internal_info.storeExceptionInfo(sys.exc_info())
            attempt.status = 'failed'  # This could cause pruning

        return attempt
Exemple #4
0
    def test_combined_normalizer(self):
        orig = datetime.datetime(2014, 2, 24, 12, 30, 7, 650261)
        orig = time.mktime(orig.timetuple())

        minute_normalized = datetime.datetime(2014, 2, 24, 12, 30)
        minute_normalized = time.mktime(minute_normalized.timetuple())
        minute_normalized = time_to_64bit_int(minute_normalized)

        hour_normalized = datetime.datetime(2014, 2, 24, 12)
        hour_normalized = time.mktime(hour_normalized.timetuple())
        hour_normalized = time_to_64bit_int(hour_normalized)

        normalizer = TimestampToNormalized64BitIntNormalizer()

        # default to minute
        assert_that(normalizer.value(orig), is_(minute_normalized))

        # change resolution
        normalizer.resolution = TimestampNormalizer.RES_HOUR
        assert_that(normalizer.value(orig), is_(hour_normalized))
Exemple #5
0
    def test_combined_normalizer_query(self):
        orig = datetime.datetime(2014, 2, 24, 12, 30, 7, 650261)
        orig = time.mktime(orig.timetuple())

        minute_normalized = datetime.datetime(2014, 2, 24, 12, 30)
        minute_normalized_time = time.mktime(minute_normalized.timetuple())
        minute_normalized = time_to_64bit_int(minute_normalized_time)

        hour_normalized = datetime.datetime(2014, 2, 24, 12)
        hour_normalized_time = time.mktime(hour_normalized.timetuple())
        hour_normalized = time_to_64bit_int(hour_normalized_time)

        normalizer = TimestampToNormalized64BitIntNormalizer()

        index = NormalizationWrapper('field',
                                     index=IntegerValueIndex(),
                                     normalizer=normalizer)

        self.field = orig

        index.index_doc(1, self)

        # Exact-match query for the original value
        assert_that(index.apply((orig, orig)), contains(1))

        # exact-match query for the normalized value
        assert_that(
            index.apply((minute_normalized_time, minute_normalized_time)),
            contains(1))

        # range query, beginning time only
        assert_that(index.apply({'between': (hour_normalized_time, )}),
                    contains(1))

        self.field = 1234
        index.index_doc(2, self)

        assert_that(index.apply({'any': None}), contains_inanyorder(1, 2))

        assert_that(list(index.sort((2, 1))), contains(2, 1))