Add functions to handle routing keys

This commit is contained in:
2021-10-22 10:36:05 -04:00
parent d85ad919b3
commit 2f6c2822b6
3 changed files with 44 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
from unittest import TestCase
from hexlib.env import get_redis
from hexlib.mq import RedisMQ
from hexlib.mq import RedisMQ, parse_routing_key, RoutingKeyParts
class TestRedisMQ(TestCase):
@@ -47,3 +47,16 @@ class TestRedisMQ(TestCase):
with self.assertRaises(ValueError):
mq.publish({"a": 1}, item_project="test", item_type="msg")
class TestRoutingKey(TestCase):
def test1(self):
key = "arc.chan.4chan.post.b"
parts = parse_routing_key(key)
self.assertEqual(parts, RoutingKeyParts("arc", "chan", "4chan", "post", "b"))
def test2(self):
key = "arc.reddit.submission.birdpics"
parts = parse_routing_key(key)
self.assertEqual(parts, RoutingKeyParts("arc", "reddit", None, "submission", "birdpics"))