def test_data_structure_element_get_by_xpath_raises_does_not_exist_error_if_not_found( self, mock_get): # Arrange mock_request = Mock(spec=HttpRequest) mock_request.user = create_mock_user("1") mock_get.side_effect = exceptions.DoesNotExist("") # Act # Assert with self.assertRaises(exceptions.DoesNotExist): data_structure_element_api.get_by_xpath("value_xpath", mock_request)
def test_data_get_by_xpath_return_data_if_found(self): # Act expected_element = self.fixtures.data_structure_element_collection[ "1121"] result = data_structure_element_api.get_by_xpath( expected_element["options"]["xpath"]["xml"], self.mock_request) # Assert self.assertEqual(result[0], expected_element)
def test_user_not_owner_cannot_perform_operation(self): self.mock_request.user = self.users["user"] result = data_structure_element_api.get_by_xpath( self.fixtures.data_structure_element_collection["1121"].options["xpath"][ "xml" ], self.mock_request, ) self.assertEquals(result.count(), 0)
def build_context(self, request, curate_data_structure, reload_unsaved_changes): # get the role before module initialization role = request.GET.get("role", None) # build context context = super(EnterDataRegistryView, self).build_context(request, curate_data_structure, reload_unsaved_changes) # init variables in context context["data_Elements"] = None context["role_choice"] = None context["role_type"] = None context["icon"]: None context["icon_color"]: None # don't give a role to select, if editing a form if not curate_data_structure.form_string: try: # Get custom resources for the current template custom_resource = custom_resource_api.get_by_current_template_and_slug( role, request=request) except exceptions.DoesNotExist: custom_resource = None list_data_structure_element = data_structure_element_api.get_by_xpath( XPATH_TITLE, request) list_data_structure_element = list(list_data_structure_element) data_id_list = [] for i in range(len(list_data_structure_element)): data_id_list.append(list_data_structure_element[i]["id"]) jquery_selector = jquery_utils.get_jquery_selector_from_data_structure( data_id_list) context["data_Elements"] = jquery_selector # update context with role context["role_choice"] = (custom_resource.role_choice if custom_resource else None) context["role_type"] = (custom_resource.role_type if custom_resource else None) context["icon"] = custom_resource.icon if custom_resource else None context["icon_color"] = (custom_resource.icon_color if custom_resource else None) # return context return context
def test_data_get_by_xpath_return_empty_if_xpath_not_found(self): # Act result = data_structure_element_api.get_by_xpath( "wrong_xpath_value", self.mock_request) # Act self.assertEqual(result.count(), 0)