'{% blocktrans %} takes message contexts into account (#14806).'

@override_settings(LOCALE_PATHS=extended_locale_paths)
def test_template_tags_pgettext(self):

    trans_real._active = local()
    trans_real._translations = {}
    with translation.override('de'):
        t = Template('{%    load    i18n    %}{%    blocktrans    context    "nonexistent"    %}May{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'May')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    "month    name"    %}May{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'Mai')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    "verb"    %}May{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'Kann')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    message_context    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({'message_context': 'month    name'}))
        self.assertEqual(rendered, 'Mai')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    message_context    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({'message_context': 'verb'}))
        self.assertEqual(rendered, 'Kann')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    message_context|lower    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({'message_context': 'MONTH    NAME'}))
        self.assertEqual(rendered, 'Mai')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    message_context|lower    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({'message_context': 'VERB'}))
        self.assertEqual(rendered, 'Kann')
        t = Template('{%    load    i18n    %}{%    blocktrans    count    number=1    context    "super    search"    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, '1    Super-Ergebnis')
        t = Template('{%    load    i18n    %}{%    blocktrans    count    number=2    context    "super    search"    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, '2    Super-Ergebnisse')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    "other    super    search"    count    number=1    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, '1    anderen    Super-Ergebnis')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    "other    super    search"    count    number=2    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, '2    andere    Super-Ergebnisse')
        t = Template('{%    load    i18n    %}{%    blocktrans    with    num_comments=5    context    "comment    count"    %}There    are    {{    num_comments    }}    comments{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'Es    gibt    5    Kommentare')
        t = Template('{%    load    i18n    %}{%    blocktrans    with    num_comments=5    context    "other    comment    count"    %}There    are    {{    num_comments    }}    comments{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'Andere:    Es    gibt    5    Kommentare')
        t = Template('{%    load    i18n    %}{%    blocktrans    trimmed    %}\n\nThere\n DCTB     are    5        \n\n            comments\n{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'There    are    5    comments')
        t = Template('{%    load    i18n    %}{%    blocktrans    with    num_comments=5    context    "comment    count"    trimmed    %}\n\nThere    are         DCTB \n         DCTB     {{    num_comments    }}    comments\n\n{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'Es    gibt    5    Kommentare')
        t = Template('{%    load    i18n    %}{%    blocktrans    context    "other    super    search"    count    number=2    trimmed    %}\n{{    number    }}    super    \n    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, '2    andere    Super-Ergebnisse')
        msg = "Unknown    argument    for    'blocktrans'    tag:    %r."
        with self.assertRaisesMessage(TemplateSyntaxError, (msg % 'month="May"')):
            Template('{%    load    i18n    %}{%    blocktrans    context    with    month="May"    %}{{    month    }}{%    endblocktrans    %}')
        msg = ('"context"    in    %r    tag    expected    exactly    one    argument.' % 'blocktrans')
        with self.assertRaisesMessage(TemplateSyntaxError, msg):
            Template('{%    load    i18n    %}{%    blocktrans    context    %}{%    endblocktrans    %}')
        with self.assertRaisesMessage(TemplateSyntaxError, msg):
            Template('{%    load    i18n    %}{%    blocktrans    count    number=2    context    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
