def test_get_zone_not_found(self): """Tests Zone when UUID was not found""" self.oneview_client.server_profile_templates.get.side_effect = \ HPOneViewException({ 'errorCode': 'RESOURCE_NOT_FOUND', 'message': 'SPT not found' }) response = self.client.get( "/redfish/v1/CompositionService/ResourceZones/" + self.spt_id) self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) self.assertEqual("application/json", response.mimetype)
def test_get_zone_not_found(self, g_mock): """Tests Zone when UUID was not found""" g_mock.oneview_client.server_profile_templates.get.side_effect = \ HPOneViewException({ 'errorCode': 'RESOURCE_NOT_FOUND', 'message': 'SPT not found' }) response = self.app.get( "/redfish/v1/CompositionService/ResourceZones/1f0ca9ef-7f81-45e3" "-9d64-341b46cf87e0") self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) self.assertEqual("application/json", response.mimetype)
def test_remove_token_when_authorization_token_fail( self, get_auth_mode, _, uuid_mock): """Tests removing a session when Oneview raises authorization error""" err = HPOneViewException({ 'errorCode': 'AUTHORIZATION', 'message': 'Invalid user information', }) get_auth_mode.return_value = 'session' self.oneview_client.server_profile_templates.get_all.side_effect = err self._build_common_sessions(uuid_mock) # Raises the error response = self.client.get( '/redfish/v1/CompositionService/' 'ResourceZones', headers={'X-Auth-Token': 'abc'}, content_type='application/json') result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_401_UNAUTHORIZED, response.status_code) self.assertEqual('application/json', response.mimetype) self.assertIn('Invalid user information', str(result)) # when gets the Active Session should have only 2 sessions with open('oneview_redfish_toolkit/mockups/redfish/' 'SessionCollection.json') as f: expected_session_collection = json.load(f) del expected_session_collection["Members"][0] expected_session_collection["*****@*****.**"] = 2 resp_active_sess = self.client.get( "/redfish/v1/SessionService/Sessions", content_type='application/json') result_active_sess = json.loads(resp_active_sess.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, resp_active_sess.status_code) self.assertEqual("application/json", resp_active_sess.mimetype) self.assertEqualMockup(expected_session_collection, result_active_sess)
def test_post_session_oneview_exception(self, oneview_client_mockup): """Tests post session with HPOneViewException""" oneview_client = oneview_client_mockup() e = HPOneViewException({ 'errorCode': 'HTTP_401_UNAUTHORIZED', 'message': 'Invalid user information', }) oneview_client.connection.get_session_id.side_effect = e # POST Session response = self.app.post("/redfish/v1/SessionService/Sessions", data=json.dumps( dict(UserName="******", Password="******")), content_type='application/json') self.assertEqual(status.HTTP_401_UNAUTHORIZED, response.status_code) self.assertEqual("application/json", response.mimetype)