def test_getting_uncompleted_todos_when_todos_is_not_none(self): todo1 = { 'userId': 1, 'id': 1, 'title': 'Make the bed', 'completed': False } todo2 = { 'userId': 1, 'id': 2, 'title': 'Walk the dog', 'completed': True } # Configure mock to return a response with a JSON-serialized list of # todos. self.mock_get_todos.return_value = Mock() self.mock_get_todos.return_value.json.return_value = [todo1, todo2] # Call the service, which will get a list of todos filtered on # completed. uncompleted_todos = get_uncompleted_todos() # Confirm that the mock was called. assert_true(self.mock_get_todos.called) # Confirm that the expected filtered list of todos was returned. assert_list_equal(uncompleted_todos, [todo1])
def test_getting_uncompleted_todos_when_todos_is_not_none(self): todo1 = { 'userId': 1, 'id': 1, 'title': 'Make the bed', 'completed': False } todo2 = { 'userId': 2, 'id': 2, 'title': 'Walk the dog', 'completed': True } # Configure mock to return a response with a JSON-serialized list of todos. self.mock_get_todos.return_value = Mock() self.mock_get_todos.return_value.json.return_value = [todo1, todo2] # Call the service, which will get a list of todos filtered on completed. uncompleted_todos = get_uncompleted_todos() # Confirm that the mock was called. assert_true(self.mock_get_todos.called) # Confirm that the expected filtered list of todos was returned. assert_list_equal(uncompleted_todos, [todo1])
def test_getting_uncompleted_todos_when_todos_is_none(self): # Configure mock to return None. self.mock_get_todos.return_value = None # Call the service, which will return an empty list. uncompleted_todos = get_uncompleted_todos() # Confirm that the mock was called. assert_true(self.mock_get_todos.called) # Confirm that an empty list was returned. assert_list_equal(uncompleted_todos, [])