def test_good_request_light_control_ros_wait_for_service_failure(self): """ This method performs a good request while ROS is unavailable. """ oldwfs = rospy.wait_for_service rospy.wait_for_service = lambda x, y: (_ for _ in ()).throw(rospy.ROSException) hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = { "name": "notreallyimportant", "diffuse": { "r": "0", "g": "0", "b": "0", "a": "0" }, "attenuation_constant": "0", "attenuation_linear": "0", "attenuation_quadratic": "0" } with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(NRPServicesUnavailableROSService, self.lc.put, 0) try: self.lc.put(0) except NRPServicesUnavailableROSService as e: self.assertEquals(e.error_code, 500) rospy.wait_for_service = oldwfs
def test_good_request_light_control_ros_service_proxy_failure(self): """ This method performs a good request with a ROS failure in the service proxy """ oldsp = rospy.ServiceProxy rospy.ServiceProxy = mock.Mock(return_value=lambda light_name='', diffuse='', attenuation_constant='', attenuation_linear='', attenuation_quadratic='': (_ for _ in ()).throw(rospy.ServiceException)) hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = { "name": "notreallyimportant", "diffuse": { "r": "0", "g": "0", "b": "0", "a": "0" }, "attenuation_constant": "0", "attenuation_linear": "0", "attenuation_quadratic": "0" } with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(NRPServicesClientErrorException, self.lc.put, 0) try: self.lc.put(0) except NRPServicesClientErrorException as e: self.assertEquals(e.error_code, 400) rospy.ServiceProxy = oldsp
def test_material_control_no_visual_path(self): """ This methods crafts a request from the owner of the simulation but missing the 'visual_path'. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = {'material': 'Gazebo/Blue'} with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertEqual(self.mc.put(0)[1], 400)
def test_light_control_only_name(self): """ This method crafts a request from the owner of the simulation with only the 'name' parameter. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = {"name": "notreallyimportant"} with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(Exception, self.lc.put, 0)
def test_material_control_wrong_user(self): """ This method crafts a request from an user which is not the owner of the simulation. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "wrong-owner"} with app.test_request_context(headers=hdr): self.assertRaises(NRPServicesClientErrorException, self.mc.put, 0) try: self.mc.put(0) except NRPServicesClientErrorException as e: self.assertEquals(e.error_code, 401)
def test_material_control_good_request(self): """ This method crafts some successful requests. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = { 'visual_path': 'sensible_model::actual_link::existing_visual', 'material': 'known_material' } with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertEquals(self.mc.put(0)[1], 200)
def test_light_control_no_params(self): """ This method crafts a request from the owner of the simulation missing the other parameters. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = {} with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(NRPServicesClientErrorException, self.lc.put, 0) try: self.lc.put(0) except NRPServicesClientErrorException as e: self.assertEquals(e.error_code, 400)
def test_material_control_invalid_visual_path(self): """ This method crafts a request from the owner of the simulation with an invalid 'visual_path' parameter. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = {'visual_path': 'randomstring::randomstring', 'material': 'Gazebo/Red'} with app.test_request_context(headers=hdr, data=json.dumps(ddict)): try: self.mc.put(0) except NRPServicesClientErrorException as e: self.assertEquals(e.error_code, 404)
def test_light_control_no_diffuse(self): """ This method crafts a request from the owner of the simulation missing only the 'diffuse' parameter. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = { "name": "notreallyimportant", "attenuation_constant": "0", "attenuation_linear": "0", "attenuation_quadratic": "0" } with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(Exception, self.lc.put, 0)
def test_material_control_ros_wait_for_service_failure(self): """ This method performs a good request while ROS is unavailable. """ oldwfs = rospy.wait_for_service rospy.wait_for_service = lambda x, y: (_ for _ in ()).throw(rospy.ROSException) hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = {'visual_path': 'model::link::visual', 'material': 'Gazebo/Red'} with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(NRPServicesUnavailableROSService, self.mc.put, 0) try: self.mc.put(0) except NRPServicesUnavailableROSService as e: self.assertEquals(e.error_code, 500) rospy.wait_for_service = oldwfs
def test_material_control_ros_wait_service_proxy_failure(self): """ This method performs a good request with a ROS failure in the service proxy. """ oldsp = rospy.ServiceProxy rospy.ServiceProxy = mock.Mock(return_value=lambda model_name='', link_name='', visual_name='', property_name='', property_value='': (_ for _ in ()).throw(rospy.ServiceException)) hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = {"visual_path": "model::link::visual", 'material': 'Gazebo/Red'} with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertRaises(NRPServicesGeneralException, self.mc.put, 0) try: self.mc.put(0) except NRPServicesGeneralException as e: self.assertEquals(e.error_code, 500) rospy.ServiceProxy = oldsp
def test_light_control_good_request(self): """ This method crafts a successful request. """ hdr = {UserAuthentication.HTTP_HEADER_USER_NAME: "default-owner"} ddict = { "name": "notreallyimportant", "diffuse": { "r": "0", "g": "0", "b": "0", "a": "0" }, "attenuation_constant": "0", "attenuation_linear": "0", "attenuation_quadratic": "0" } with app.test_request_context(headers=hdr, data=json.dumps(ddict)): self.assertEqual(self.lc.put(0)[1], 200)