async def test_run__passes_correct_blocklists_to_subscriptions(mock_client):
    submission = MockSubmission("12322")
    api = MockExportAPI().with_submission(submission)
    watcher = SubscriptionWatcher(api, mock_client)
    method_called = MockMethod([submission])
    watcher._get_new_results = method_called.async_call
    watcher.BACK_OFF = 1
    watcher.blocklists = {156: {"test", "ych"}, -200: {"example"}}
    sub1 = MockSubscription("deer", 156)
    sub2 = MockSubscription("dog", -232)
    watcher.subscriptions = [sub1, sub2]

    task = asyncio.get_event_loop().create_task(watcher_killer(watcher))
    # Run watcher
    await watcher.run()
    await task

    assert submission in sub1.submissions_checked
    assert len(sub1.blocklists) == 1
    assert sub1.blocklists[0] in [
        AndQuery([NotQuery(WordQuery("test")),
                  NotQuery(WordQuery("ych"))]),
        AndQuery([NotQuery(WordQuery("ych")),
                  NotQuery(WordQuery("test"))])
    ]
    assert submission in sub2.submissions_checked
    assert len(sub2.blocklists) == 1
    assert sub2.blocklists[0] == AndQuery([])
    assert method_called.called
async def test_run__calls_get_new_results(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    method_called = MockMethod([])
    watcher._get_new_results = method_called.async_call
    # Shorten the wait
    watcher.BACK_OFF = 1

    task = asyncio.get_event_loop().create_task(watcher_killer(watcher))
    # Run watcher
    await watcher.run()
    await task

    assert method_called.called
async def test_run__calls_update_latest_ids(mock_client):
    submission1 = MockSubmission("12322")
    submission2 = MockSubmission("12324")
    api = MockExportAPI().with_submissions([submission1, submission2])
    watcher = SubscriptionWatcher(api, mock_client)
    mock_new_results = MockMethod([submission1, submission2])
    watcher._get_new_results = mock_new_results.async_call
    mock_update_latest = MockMethod()
    watcher._update_latest_ids = mock_update_latest.call
    # Shorten the wait
    watcher.BACK_OFF = 1

    task = asyncio.get_event_loop().create_task(watcher_killer(watcher))
    # Run watcher
    await watcher.run()
    await task

    assert mock_update_latest.called
    assert mock_update_latest.args[0] == [submission2]
async def test_run__checks_all_new_results(mock_client):
    submission1 = MockSubmission("12322")
    submission2 = MockSubmission("12324")
    api = MockExportAPI().with_submissions([submission1, submission2])
    watcher = SubscriptionWatcher(api, mock_client)
    method_called = MockMethod([submission1, submission2])
    watcher._get_new_results = method_called.async_call
    watcher.BACK_OFF = 1
    sub = MockSubscription("deer", 0)
    watcher.subscriptions = [sub]

    task = asyncio.get_event_loop().create_task(watcher_killer(watcher))
    # Run watcher
    await watcher.run()
    await task

    assert submission1 in sub.submissions_checked
    assert submission2 in sub.submissions_checked
    assert method_called.called