# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
import pytest


@pytest.fixture
def app():
    import main
    main.app.testing = True
    return main.app.test_client()


def test_index(app):
    r = app.get('/')
    assert r.status_code == 200


@mock.patch('logging.warn')
def test_log_payload(logging_mock, app):
    payload = 'hello'

    r = app.post('/log_payload', data=payload)
    assert r.status_code == 200

    assert logging_mock.called


@mock.patch('logging.warn')
def test_empty_payload(logging_mock, app):
    r = app.post('/log_payload')
    assert r.status_code == 200

    assert logging_mock.called

@@ -594,20 +594,8 @@
 e.%0A%0A
-import mock%0A
 impo
@@ -793,36 +793,8 @@
 0%0A%0A%0A
-@mock.patch('logging.warn')%0A
 def 
@@ -806,36 +806,30 @@
 log_payload(
-logging_mock
+capsys
 , app):%0A    
@@ -843,13 +843,20 @@
  = '
-hello
+test_payload
 '%0A%0A 
@@ -942,64 +942,64 @@
     
-assert logging_mock.called%0A%0A%0A@mock.patch('logging.warn')
+out, _ = capsys.readouterr()%0A    assert payload in out%0A%0A
 %0Adef
@@ -1018,28 +1018,22 @@
 payload(
-logging_mock
+capsys
 , app):%0A
@@ -1106,31 +1106,67 @@
     
-assert logging_mock.called
+out, _ = capsys.readouterr()%0A    assert 'empty payload' in out
 %0A

Convert tasks example to use logging for testability (#1219)