Exemplo n.º 1
0
def get_locale():
    """Returns the locale for the current request."""
    try:
        return user_locale(request.user_id)
    except AttributeError as e:
        app.logger.warning(e)
    return "en"
Exemplo n.º 2
0
def test_user_locale_no_token(mocker):
    def requests_mock(url, headers):
        assert False

    mocker.patch('requests.get', new=requests_mock)

    assert not settings.MATTERMOST_PA_TOKEN

    actual_locale = mattermost_api.user_locale('user1')
    assert actual_locale == 'en'
Exemplo n.º 3
0
def test_user_locale(mocker, user_id, locale):
    def requests_mock(url, headers):
        assert url == 'http://www.example.com/api/v4/users/' + user_id
        assert headers['Authorization'] == 'Bearer 123abc456xyz'
        if user_id == 'user1':
            return Response(True, json.dumps({'locale': 'en'}))
        if user_id == 'user2':
            return Response(True, json.dumps({'locale': 'de'}))
        if user_id == 'user3':
            return Response(True, json.dumps({'locale': ''}))
        if user_id == 'user4':
            return Response(True, json.dumps({}))
        if user_id == 'user5':
            return Response(False, json.dumps({}))
        assert False

    mocker.patch('requests.get', new=requests_mock)

    assert settings.MATTERMOST_PA_TOKEN

    actual_locale = mattermost_api.user_locale(user_id)
    assert actual_locale == locale