Projet

Général

Profil

0001-toulouse_smart-manage-status-code-in-mock_response-5.patch

Nicolas Roche, 19 juillet 2021 10:22

Télécharger (1,41 ko)

Voir les différences:

Subject: [PATCH 1/7] toulouse_smart: manage status code in mock_response
 (#55230)

 tests/test_toulouse_smart.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tests/test_toulouse_smart.py
46 46
        @httmock.urlmatch()
47 47
        def error(url, request):
48 48
            assert False, 'request to %s' % (url,)
49 49

  
50 50
        @functools.wraps(func)
51 51
        def wrapper(*args, **kwargs):
52 52
            handlers = []
53 53
            for row in path_contents:
54
                path, content = row
54
                path, content = row[:2]
55
                if len(row) == 3:
56
                    status_code = row[2]
57
                else:
58
                    status_code = 200
55 59

  
56 60
                @httmock.urlmatch(path=path)
57 61
                def handler(url, request):
58
                    return content
62
                    return httmock.response(status_code, content)
59 63

  
60 64
                handlers.append(handler)
61 65
            handlers.append(error)
62 66

  
63 67
            with httmock.HTTMock(*handlers):
64 68
                return func(*args, **kwargs)
65 69

  
66 70
        return wrapper
67
-