def test_remove_sub__removes_subscription(context): api = MockExportAPI() watcher = SubscriptionWatcher(api, context.bot) watcher.subscriptions.add(Subscription("example", 18749)) watcher.subscriptions.add(Subscription("test", 18747)) new_sub = Subscription("test", 18749) new_sub.latest_update = datetime.datetime.now() watcher.subscriptions.add(new_sub) func = SubscriptionFunctionality(watcher) list_subs = MockMethod("Listing subscriptions") func._list_subs = list_subs.call resp = func._remove_sub(18749, "test") assert "Removed subscription: \"test\"." in resp assert list_subs.called assert list_subs.args[0] == 18749 assert "Listing subscriptions" in resp assert len(watcher.subscriptions) == 2 subscriptions = list(watcher.subscriptions) if subscriptions[0].query == "test": assert subscriptions[0].destination == 18747 assert subscriptions[1].query == "example" assert subscriptions[1].destination == 18749 else: assert subscriptions[0].query == "example" assert subscriptions[0].destination == 18749 assert subscriptions[1].query == "test" assert subscriptions[1].destination == 18747
def test_to_json(): sub = Subscription("test query", -12322) sub.latest_update = datetime.datetime(2019, 9, 17, 21, 8, 35) data = sub.to_json() assert "query" in data assert data["query"] == "test query" assert "destination" in data assert data["destination"] == -12322 assert "latest_update" in data assert data["latest_update"] == "2019-09-17T21:08:35"
def test_to_json_and_back(): sub = Subscription("something", 3223) sub.latest_update = datetime.datetime(2019, 9, 17, 21, 16, 14, tzinfo=datetime.timezone.utc) data = sub.to_json() new_sub = Subscription.from_json(data) assert new_sub.query == sub.query assert new_sub.destination == sub.destination assert new_sub.latest_update == sub.latest_update