'Test that our logic related to `use_first_unread_anchor`
invokes the `message_id = LARGER_THAN_MAX_MESSAGE_ID` hack for
the `/* get_messages */` query when relevant muting
is in effect.
This is a very arcane test on arcane, but very heavily
field-tested, logic in get_messages_backend().  If
this test breaks, be absolutely sure you know what you\'re
doing.'

def test_use_first_unread_anchor_with_muted_topics(self):

    realm = get_realm('zulip')
    self.make_stream('web    stuff')
    user_profile = self.example_user('hamlet')
    user_profile.muted_topics = ujson.dumps([['Scotland', 'golf'], ['web    stuff', 'css'], ['bogus', 'bogus']])
    user_profile.save()
    query_params = dict(use_first_unread_anchor='true', anchor=0, num_before=0, num_after=0, narrow='[["stream",    "Scotland"]]')
    request = POSTRequestMock(query_params, user_profile)
    with queries_captured() as all_queries:
        get_messages_backend(request, user_profile)
    queries = [q for q in all_queries if str(q['sql']).startswith('SELECT    message_id,    flags')]
    self.assertEqual(len(queries), 1)
    stream = get_stream('Scotland', realm)
    recipient_id = get_recipient(Recipient.STREAM, stream.id).id
    cond = "AND    NOT    (recipient_id    =    {scotland}    AND    upper(subject)    =    upper('golf'))".format(scotland=recipient_id)
    self.assertIn(cond, queries[0]['sql'])
    queries = [q for q in all_queries if ('/*    get_messages    */' in q['sql'])]
    self.assertEqual(len(queries), 1)
    self.assertIn(('AND    message_id    =    %d' % (LARGER_THAN_MAX_MESSAGE_ID,)), queries[0]['sql'])
