~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/test_http.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-05-29 13:07:56 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20130529130756-3h7dh05a39n9uvq5
Tags: 1:0.2.4-0ubuntu1
* New upstream release. 
* debian/control: Add python-d2to1 and python-pbr
* debian/control: Add testrepository, dropped python-nose
* debian/control: Add python-six

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import json
1
2
import mock
2
3
 
3
4
import requests
52
53
                # Automatic JSON parsing
53
54
                self.assertEqual(body, {"hi": "there"})
54
55
 
55
 
    def test_get_error(self):
 
56
    def test_get_error_with_plaintext_resp(self):
56
57
        cl = get_authed_client()
57
58
 
58
59
        fake_err_response = utils.TestResponse({
64
65
        with mock.patch.object(requests, "request", err_MOCK_REQUEST):
65
66
            self.assertRaises(exceptions.BadRequest, cl.get, '/hi')
66
67
 
 
68
    def test_get_error_with_json_resp(self):
 
69
        cl = get_authed_client()
 
70
        err_response = {
 
71
            "error": {
 
72
                "code": 400,
 
73
                "title": "Error title",
 
74
                "message": "Error message string"
 
75
            }
 
76
        }
 
77
        fake_err_response = utils.TestResponse({
 
78
            "status_code": 400,
 
79
            "text": json.dumps(err_response)
 
80
        })
 
81
        err_MOCK_REQUEST = mock.Mock(return_value=(fake_err_response))
 
82
 
 
83
        with mock.patch.object(requests, "request", err_MOCK_REQUEST):
 
84
            exc_raised = False
 
85
            try:
 
86
                cl.get('/hi')
 
87
            except exceptions.BadRequest as exc:
 
88
                exc_raised = True
 
89
                self.assertEqual(exc.message, "Error message string")
 
90
            self.assertTrue(exc_raised, 'Exception not raised.')
 
91
 
67
92
    def test_post(self):
68
93
        cl = get_authed_client()
69
94