예제 #1
0
def test_get_model_permissions():
    """
    We can create the correct model permissions from user permissions
    """
    user = UserFactory(permissions=("books.view_book", "books.view_author"))

    assert get_view_permissions(user) == {"books.book", "books.author"}

    # test for camel cased app names
    user = MagicMock()
    user.get_all_permissions = Mock(
        return_value={"BookShelf.view_author", "BookShelf.view_book"})

    assert get_view_permissions(user) == {"BookShelf.book", "BookShelf.author"}
예제 #2
0
def test_get_model_permissions():
    """
    We can create the correct model permissions from user permissions
    """
    user = UserFactory(permissions=("books.view_book", "books.view_author"))

    assert get_view_permissions(user) == {"books.book", "books.author"}
예제 #3
0
def test_get_model_permissions_lowercased():
    """
    When our permissions are upper cased (we had an app with an upper case letter) we still get user perms in lower case
    """
    user = UserFactory(permissions=("books.view_book", "books.view_author"))
    user.user_permissions.update(codename=Upper("codename"))

    assert get_view_permissions(user) == {"books.book", "books.author"}
예제 #4
0
def test_get_model_permissions():
    """
    We can create the correct model permissions from user permissions
    """

    user = user_with_permissions('polls.view_poll', 'polls.view_choice')

    assert get_view_permissions(user) == {'polls.poll', 'polls.choice'}
예제 #5
0
def test_get_model_permissions_lowercased():
    """
    When our permissions are upper cased (we had an app with an upper case letter) we still get user perms in lower case
    """

    user = user_with_permissions("polls.view_poll", "polls.view_choice")
    user.user_permissions.update(codename=Upper("codename"))

    assert get_view_permissions(user) == {"polls.poll", "polls.choice"}