Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

test a decorator python

from nose.tools import assert_equal
from mock import Mock

class TestLoginRequired(object):
    def test_no_user(self):
        func = Mock()
        decorated_func = login_required(func)
        request = prepare_request_without_user()
        response = decorated_func(request)
        assert not func.called
        # assert response is redirect

    def test_bad_user(self):
        func = Mock()
        decorated_func = login_required(func)
        request = prepare_request_with_non_authenticated_user()
        response = decorated_func(request)
        assert not func.called
        # assert response is redirect

    def test_ok(self):
        func = Mock(return_value='my response')
        decorated_func = login_required(func)
        request = prepare_request_with_ok_user()
        response = decorated_func(request)
        func.assert_called_with(request)
        assert_equal(response, 'my response')
Comment

PREVIOUS NEXT
Code Example
Python :: stack overflow pop item from list in python 
Python :: Start Django Project At http://127.0.0.1:8080/ 
Python :: implementation of binary search tree in python 
Python :: Custom RGB To Hex Conversion with Python 
Python :: Incrémenter/décrémenter variable python 
Python :: python autorun script 
Python :: convert to string except missing 
Python :: mysql connector select 
Python :: Different ways to test multiple 
Python :: Creating a Tuple with Mixed Datatypes. 
Python :: Display complete information about the DataFrame 
Python :: multiple ternary operator python 
Python :: check if varible is emyt pyton 
Python :: short hand function pytho 
Python :: choose what items on python 
Python :: how to run a string as a line of code in pytho 
Python :: python yield async await 
Python :: how to clear formatting in python 
Python :: Send Variable Over In Python Views 
Python :: Python script to do something at the same time every day 
Python :: enumerate for string 
Python :: generate natural numbers python 
Python :: python long multiline text 
Python :: python get object attributes 
Python :: dataframe no names from file 
Python :: machine learning project outline 
Python :: sort files in windows order python 
Python :: how to write a program that interacts with the terminal 
Python :: how to sum a column in csv python using list in python 
Python :: odd number list generator 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =