Ejemplo n.º 1
0
 def test_replace_custom_resources_by_template_return_ok(self):
     # Check
     template = self.fixture.create_and_save_template()
     result = custom_resource_api.get_all_by_template(template)
     self.assertEquals(0, len(result))
     # Act
     custom_resource_api.replace_custom_resources_by_template(
         template, self.fixture.get_dict_all_custom_resource())
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(10, len(result))
Ejemplo n.º 2
0
 def test_replace_custom_resources_by_template_check_old(self):
     # Check
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_custom_resource_all_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     old_cr = list(result)[0]
     self.assertEquals(1, len(result))
     # Act
     custom_resource_api.replace_custom_resources_by_template(
         template, self.fixture.get_dict_all_custom_resource())
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertFalse(old_cr in result)
Ejemplo n.º 3
0
 def test_delete_custom_resources_by_template_return_0(self):
     # Act
     self.fixture.insert_data()
     custom_resource_api.delete_custom_resources_by_template(self.fixture.template)
     result = custom_resource_api.get_all_by_template(self.fixture.template)
     # Assert
     self.assertEquals(0, len(result))
Ejemplo n.º 4
0
 def test_create_all_resource_custom_resource_return_type_is_not_none(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_all_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertIsNotNone(all(item.type for item in result))
Ejemplo n.º 5
0
 def test_create_custom_resource_return_type(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(result[0].type, CUSTOM_RESOURCE_TYPE.RESOURCE.value)
Ejemplo n.º 6
0
 def test_create_custom_resource_return_slug(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(result[0].slug, slugify(result[0].title))
Ejemplo n.º 7
0
 def test_create_custom_resource_return_refinements_value(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(result[0].refinements[0], "unspecified Organization")
Ejemplo n.º 8
0
 def test_create_custom_resource_return_refinements_length(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(len(result[0].refinements), 1)
Ejemplo n.º 9
0
 def test_create_custom_resource_return_refinements_is_not_none(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertIsNotNone(result[0].refinements)
Ejemplo n.º 10
0
 def test_create_all_custom_resource_return_collection_of_custom_resource(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_all_custom_resource(), template
     )
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertTrue(all(isinstance(item, CustomResource) for item in result))
Ejemplo n.º 11
0
 def test_get_all_by_template_return_all(self):
     # Act
     length = len(self.fixture.get_dict_all_custom_resource())
     template = self.fixture.create_and_save_template()
     custom_resource_api.parse_and_save(
         self.fixture.get_dict_all_custom_resource(), template)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(length, len(result))
Ejemplo n.º 12
0
def _init_custom_registry():
    """Init the custom registry.

    Returns:
    """

    try:
        current_template_version = (
            version_manager_api.get_active_global_version_manager_by_title(
                REGISTRY_XSD_FILENAME))
        current_template = template_api.get(
            version_manager_api.get_current(current_template_version))
    except:
        raise Exception("Can't get the current template.")

    if len(custom_resource_api.get_all_by_template(current_template)) > 0:
        print('**********')
        print(custom_resource_api.get_all_by_template(current_template))
        print('**********')
        logger.info(
            "Custom resources related to current template already exist.")
    else:
        json_path = CUSTOM_REGISTRY_FILE_PATH
        if json_path == "":
            raise Exception(
                "Please configure the CUSTOM_REGISTRY_FILE_PATH setting in your project."
            )

        try:
            default_json_path = finders.find(json_path)
            with open(default_json_path) as json_file:
                data = json.load(json_file)
                print('**********')
                print(f'parsing json: {data}')
                print('**********')
                custom_resource_api.parse_and_save(data, current_template)
        except Exception as e:
            logger.error(
                "Impossible to use the custom registry json file: {0}".format(
                    str(e)))
Ejemplo n.º 13
0
def set_current(version):
    """Set the current version of the object, then saves it.

    Args:
        version:

    Returns:

    """
    if custom_resource_api.get_all_by_template(version).count() == 0:
        raise exceptions.ApiError(
            "Please set custom resources to template before setting it to current."
        )
    version_manager_api.set_current(version)
Ejemplo n.º 14
0
 def test_save_list(self):
     # Act
     template = self.fixture.create_and_save_template()
     custom_resource1 = CustomResource(
         template=template, title="title1", type="resource", icon="icon", sort=0
     )
     custom_resource2 = CustomResource(
         template=template, title="title2", type="resource", icon="icon", sort=1
     )
     list_custom = [custom_resource1, custom_resource2]
     custom_resource_api.save_list(list_custom)
     result = custom_resource_api.get_all_by_template(template)
     # Assert
     self.assertEquals(len(list_custom), len(result))
Ejemplo n.º 15
0
    def get(self, request, *args, **kwargs):
        data_context_list = []
        global_template_version_manager = (
            template_version_manager_api.get_global_version_managers(
                request=request))
        if len(global_template_version_manager) == 1:
            template_version_manager = list(global_template_version_manager)[0]
            # get the current version
            current_template_version = template_version_manager.current
            # for each template versions
            for version in template_version_manager.versions:
                # get the template
                template = template_api.get(version, request=request)
                # get all the template's custom resources
                custom_resources = custom_resource_api.get_all_by_template(
                    template)
                # append to list for the context
                data_context_list.append({
                    "template_name":
                    template.display_name,
                    "count":
                    custom_resources.count(),
                    "template_id":
                    str(template.id),
                    "is_current":
                    current_template_version == str(template.id),
                })
        else:
            logger.error("We should only have one template.")

        modals = []

        assets = {
            "js": [],
        }

        context = {
            "objects": data_context_list,
            "object_name": "Custom Resources"
        }

        return admin_render(
            request,
            "core_main_registry_app/admin/custom_registry/list.html",
            modals=modals,
            assets=assets,
            context=context,
        )
Ejemplo n.º 16
0
def _init_custom_registry():
    """Init the custom registry.

    Returns:
    """
    from core_main_registry_app.components.custom_resource import (
        api as custom_resource_api, )

    try:
        current_template_version = (
            system_api.get_active_global_version_manager_by_title(
                REGISTRY_XSD_FILENAME))
        current_template = system_api.get_template_by_id(
            current_template_version.current)
    except:
        raise Exception("Can't get the current template.")

    if len(custom_resource_api.get_all_by_template(current_template)) > 0:
        logger.info(
            "Custom resources related to current template already exist.")
    else:
        json_path = CUSTOM_REGISTRY_FILE_PATH
        if json_path == "":
            raise Exception(
                "Please configure the CUSTOM_REGISTRY_FILE_PATH setting in your project."
            )

        try:
            default_json_path = finders.find(json_path)
            with open(default_json_path) as json_file:
                data = json.load(json_file)
                custom_resource_api.parse_and_save(data, current_template)
        except Exception as e:
            logger.error(
                "Impossible to use the custom registry json file: {0}".format(
                    str(e)))