def test_metric_with_expiration(self, mock_categorize):
        """The ``metric`` method should call the redis ``expire`` method if
        passed an ``expire`` argument."""

        slug = 'categorized-metric'
        n = 1

        # get the keys used for the metric, so we can check for calls
        day, week, month, year = self.r._build_keys(slug)
        self.r.metric(slug, num=n, expire=3600)

        # Verify that setting a metric adds the appropriate slugs to the keys
        # set and then incrememts each key
        self.redis.assert_has_calls([
            call.sadd(self.r._metric_slugs_key, day, week, month, year),
            call.incr(day, n),
            call.incr(week, n),
            call.incr(month, n),
            call.incr(year, n),
        ])

        # Make sure nothing was categorized.
        self.assertFalse(mock_categorize.called)

        # Expiration should have gotten called
        self.redis.expire.assert_has_calls([
            call.expire(day, 3600),
            call.expire(week, 3600),
            call.expire(month, 3600),
            call.expire(year, 3600),
        ])
예제 #2
0
    def test_can_save(self):
        self.mock_request(status_code=200, effective_url="http://www.globo.com")

        self.server.application.girl = Mock()

        response = yield self.authenticated_fetch(
            '/page', method='POST', body=dumps({
                'url': 'http://www.globo.com'
            })
        )

        expect(response.code).to_equal(200)

        page_uuid = UUID(response.body)
        page = Page.by_uuid(page_uuid, self.db)

        expect(page).not_to_be_null()
        expect(str(page_uuid)).to_equal(page.uuid)

        expect(self.server.application.girl.expire.call_count).to_equal(4)
        self.server.application.girl.assert_has_calls([
            call.expire('domains_details'),
            call.expire('failed_responses_count'),
            call.expire('violation_count_for_domains'),
            call.expire('top_violations_in_category_for_domains'),
        ])
예제 #3
0
    def test_metric_with_expiration(self, mock_categorize):
        """The ``metric`` method should call the redis ``expire`` method if
        passed an ``expire`` argument."""

        slug = 'categorized-metric'
        n = 1

        # get the keys used for the metric, so we can check for calls
        keys = self.r._build_keys(slug)
        self.r.metric(slug, num=n, expire=3600)

        # Verify that setting a metric adds the appropriate slugs to the keys
        # set and then incrememts each key
        call_list = [call.sadd(self.r._metric_slugs_key, slug)]
        for k in keys:
            call_list.append(call.incr(k, n))
            call_list.append(call.expire(k, 3600))

        self.redis.assert_has_calls(call_list)

        # Make sure nothing was categorized.
        self.assertFalse(mock_categorize.called)