def test_response_set_content_type_not_set(): resp = falcon.Response() assert 'content-type' not in resp._headers resp._set_media_type() assert 'content-type' not in resp._headers
def test_response_set_content_type_set(): resp = falcon.Response() resp._set_media_type(MEDIA_TEXT) assert resp._headers['content-type'] == MEDIA_TEXT
def test_response_repr(self): resp = falcon.Response() _repr = '<%s: %s>' % (resp.__class__.__name__, resp.status) self.assertEqual(resp.__repr__(), _repr)
def test_add_link_invalid_crossorigin_value(self, crossorigin): resp = falcon.Response() with pytest.raises(ValueError): resp.add_link('/related/resource', 'next', crossorigin=crossorigin)
def create_resp(): '''creates a falcon response''' resp = falcon.Response() return resp
def test_on_get_response(self): """Basic test for the compuate image show proxy.""" client, env = get_client_env() req = api.Request(env, sl_client=client) resp = falcon.Response() app = mock.MagicMock() show_controller = images.ComputeImageShow(app) def fake_image_get(req, resp, image_id, tenant_id=None): resp.status = 200 resp.body = { "size": "74185822", "created": "2011-01-01T01:02:03Z", "id": image_id, "links": [ { "href": FAKE_SELF_LINK, "rel": "self" }, ], "metadata": {}, "min_disk": 0, "min_ram": 0, "name": "fakeimage7", "progress": 100, "status": "active", "updated": "2011-01-01T01:02:03Z" } with mock.patch.object(glance_images.ImageV2, 'on_get', side_effect=fake_image_get) as image_show_mock: show_controller.on_get(req, resp, FAKE_IMAGE_GUID) image_show_mock.assert_called_once_with(req, resp, FAKE_IMAGE_GUID, None) self.assertEqual(200, resp.status) self.assertIn('image', resp.body) image = resp.body['image'] expected_image = { "OS-EXT-IMG-SIZE:size": "74185822", "created": "2011-01-01T01:02:03Z", "id": FAKE_IMAGE_GUID, "links": [ { "href": FAKE_SELF_LINK, "rel": "self" }, ], "metadata": {}, "minDisk": 0, "minRam": 0, "name": "fakeimage7", "progress": 100, "status": 'ACTIVE', "updated": "2011-01-01T01:02:03Z" } self.assertDictEqual(expected_image, image)
def test_returns_200_when_gift_card_mark_used(self) -> None: request = falcon.testing.create_req() response = falcon.Response() when(self.use_case).mark_used(self.gift_card.id).thenReturn(None) self.resource.on_post(request, response, self.gift_card.id) self.assertEqual(falcon.HTTP_200, response.status)
def test_raises_400_when_gift_card_not_found(self) -> None: request = falcon.testing.create_req() response = falcon.Response() when(self.use_case).mark_used(self.gift_card.id).thenRaise(GiftCardNotFound) with self.assertRaises(errors.HTTPBadRequest): self.resource.on_post(request, response, self.gift_card.id)
def test_on_get(self, mockListInstance): client, env = get_client_env() href = u'http://localhost:5000/compute/v2/333582/servers/4846014' inst = { 'status': 'ACTIVE', 'updated': '2014-05-23T10:58:29-05:00', 'hostId': 4846014, 'user_id': 206942, 'addresses': { 'public': [{ 'version': 4, 'addr': '23.246.195.197', 'OS-EXT-IPS:type': 'fixed' }], 'private': [{ 'version': 4, 'addr': '10.107.38.132', 'OS-EXT-IPS:type': 'fixed' }] }, 'links': [{ 'href': href, 'rel': 'self' }], 'created': '2014-05-23T10:57:07-05:00', 'tenant_id': 333582, 'OS-EXT-STS:power_state': 1, 'accessIPv4': '', 'accessIPv6': '', 'OS-EXT-STS:vm_state': 'ACTIVE', 'OS-EXT-STS:task_state': None, 'flavor': { 'id': '1', 'links': [{ 'href': 'http://localhost:5000/compute/v2/flavors/1', 'rel': 'bookmark' }] }, 'OS-EXT-AZ:availability_zone': 154820, 'id': '4846014', 'security_groups': [{ 'name': 'default' }], 'name': 'minwoo-metis', 'metadata': {}, 'image': {}, } status = {'keyName': 'ACTIVE', 'name': 'Active'} pwrState = {'keyName': 'RUNNING', 'name': 'Running'} sshKeys = [] dataCenter = {'id': 154820, 'name': 'dal06', 'longName': 'Dallas 6'} orderItem = { 'itemId': 858, 'setupFee': '0', 'promoCodeId': '', 'oneTimeFeeTaxRate': '.066', 'description': '2 x 2.0 GHz Cores', 'laborFee': '0', 'oneTimeFee': '0', 'itemPriceId': '1641', 'setupFeeTaxRate': '.066', 'order': { 'userRecordId': 206942, 'privateCloudOrderFlag': False }, 'laborFeeTaxRate': '.066', 'categoryCode': 'guest_core', 'setupFeeDeferralMonths': 12, 'parentId': '', 'recurringFee': '0', 'id': 34750548, 'quantity': '', } billingItem = { 'modifyDate': '2014-06-05T08:37:01-05:00', 'resourceTableId': 4846014, 'hostName': 'minwoo-metis', 'recurringMonths': 1, 'orderItem': orderItem, } mockListInstance.return_value = { 'billingItem': billingItem, 'datacenter': dataCenter, 'powerState': pwrState, 'sshKeys': sshKeys, 'status': status, 'accountId': 'foobar', 'id': '1234', 'createDate': 'foobar', 'hostname': 'foobar', 'modifyDate': 'foobar' } req = api.Request(env, sl_client=client) resp = falcon.Response() instance = servers.ServersDetailV2(app=mock.MagicMock()) instance.on_get(req, resp, TENANT_ID) self.assertEqual(set(resp.body['servers'][0].keys()), set(inst.keys())) self.assertEqual(resp.status, 200)
def perform_attach_action(self, body_str, tenant_id, instance_id): self.client, self.env = get_client_env(body=body_str) self.req = api.Request(self.env, sl_client=self.client) self.resp = falcon.Response() instance = volumes.OSVolumeAttachmentsV2() instance.on_post(self.req, self.resp, tenant_id, instance_id)
def test_non_ascii_name(self, name): resp = falcon.Response() self.assertRaises(KeyError, resp.set_cookie, name, 'ok_value')
def set_bad_cookie_value(): resp = falcon.Response() resp.set_cookie("ok_name", u"unicode_\xc3\xa6\xc3\xb8")
def set_bad_cookie_name(): resp = falcon.Response() resp.set_cookie(u"unicode_\xc3\xa6\xc3\xb8", "ok_value")