Example #1
0
    def test_tags_from_context(self):
        # it should extract only relevant keys
        context = {
            "correlation_id": "44b7f305",
            "delivery_info": '{"eager": "True"}',
            "eta": "soon",
            "expires": "later",
            "hostname": "localhost",
            "id": "44b7f305",
            "reply_to": "44b7f305",
            "retries": 4,
            "timelimit": ("now", "later"),
            "custom_meta": "custom_value",
        }

        metas = tags_from_context(context)
        assert metas["celery.correlation_id"] == "44b7f305"
        assert metas["celery.delivery_info"] == '{"eager": "True"}'
        assert metas["celery.eta"] == "soon"
        assert metas["celery.expires"] == "later"
        assert metas["celery.hostname"] == "localhost"
        assert metas["celery.id"] == "44b7f305"
        assert metas["celery.reply_to"] == "44b7f305"
        assert metas["celery.retries"] == 4
        assert metas["celery.timelimit"] == ("now", "later")
        assert metas.get("custom_meta", None) is None
Example #2
0
    def test_tags_from_context(self):
        # it should extract only relevant keys
        context = {
            'correlation_id': '44b7f305',
            'delivery_info': '{"eager": "True"}',
            'eta': 'soon',
            'expires': 'later',
            'hostname': 'localhost',
            'id': '44b7f305',
            'reply_to': '44b7f305',
            'retries': 4,
            'timelimit': ('now', 'later'),
            'custom_meta': 'custom_value',
        }

        metas = tags_from_context(context)
        eq_(metas['celery.correlation_id'], '44b7f305')
        eq_(metas['celery.delivery_info'], '{"eager": "True"}')
        eq_(metas['celery.eta'], 'soon')
        eq_(metas['celery.expires'], 'later')
        eq_(metas['celery.hostname'], 'localhost')
        eq_(metas['celery.id'], '44b7f305')
        eq_(metas['celery.reply_to'], '44b7f305')
        eq_(metas['celery.retries'], 4)
        eq_(metas['celery.timelimit'], ('now', 'later'))
        ok_(metas.get('custom_meta', None) is None)
Example #3
0
    def test_tags_from_context_empty_keys(self):
        # it should not extract empty keys
        context = {
            "correlation_id": None,
            "exchange": "",
            "timelimit": (None, None),
            "retries": 0,
        }

        tags = tags_from_context(context)
        assert {} == tags
        # edge case: `timelimit` can also be a list of None values
        context = {
            "timelimit": [None, None],
        }

        tags = tags_from_context(context)
        assert {} == tags
Example #4
0
    def test_tags_from_context_empty_keys(self):
        # it should not extract empty keys
        context = {
            'correlation_id': None,
            'exchange': '',
            'timelimit': (None, None),
            'retries': 0,
        }

        tags = tags_from_context(context)
        eq_({}, tags)
        # edge case: `timelimit` can also be a list of None values
        context = {
            'timelimit': [None, None],
        }

        tags = tags_from_context(context)
        eq_({}, tags)