Example #1
0
    def test_non_treemap_model(self):
        self.instance.add_map_feature_types(['Bioswale'])

        body = {'udf.name': 'Testing choice',
                'udf.model': 'Bioswale',
                'udf.type': 'string'}

        udf_create(body, self.instance)
Example #2
0
    def test_non_treemap_model(self):
        self.instance.add_map_feature_types(['Bioswale'])

        body = {'udf.name': 'Testing choice',
                'udf.model': 'Bioswale',
                'udf.type': 'string'}

        udf_create(body, self.instance)
Example #3
0
    def test_adds_udf_to_role_when_created(self):
        body = {"udf.name": "cool udf", "udf.model": "Plot", "udf.type": "string"}

        udf_create(body, self.instance)

        roles_in_instance = Role.objects.filter(instance=self.instance)

        self.assertGreater(len(roles_in_instance), 0)

        for role in roles_in_instance:
            perms = [perm.field_name for perm in role_field_permissions(role, self.instance)]

            self.assertIn("udf:cool udf", perms)
Example #4
0
def create_udfs(udfs, instance):
    for model, model_rules in udfs.items():
        for field, field_rules in model_rules.items():
            # convert the migrator udf schema
            # to the udf-lib friendly schema

            name = field_rules["udf.name"]
            model_type = to_model_name(model)
            choices = field_rules.get("udf.choices")
            datatype_type = field_rules.get("udf.type", "choice" if choices else "string")

            udf_params = {"udf.name": name, "udf.model": model_type, "udf.type": datatype_type, "udf.choices": choices}

            if not udf_lib.udf_exists(udf_params, instance):
                print "Creating udf %s" % name
                udf_lib.udf_create(udf_params, instance)
Example #5
0
    def test_adds_udf_to_role_when_created(self):
        body = {'udf.name': 'cool udf',
                'udf.model': 'Plot',
                'udf.type': 'string'}

        udf_create(body, self.instance)

        roles_in_instance = Role.objects.filter(instance=self.instance)

        self.assertGreater(len(roles_in_instance), 0)

        for role in roles_in_instance:
            perms = [perm.field_name
                     for perm in role_permissions(role, self.instance)]

            self.assertIn('udf:cool udf', perms)
Example #6
0
    def test_create_non_choice_udf(self):
        body = {"udf.name": " cool udf  ", "udf.model": "Plot", "udf.type": "string"}

        udf = udf_create(body, self.instance)
        self.assertEqual(udf.instance_id, self.instance.pk)
        self.assertEqual(udf.model_type, "Plot")
        self.assertEqual(udf.name, "cool udf")
        self.assertEqual(udf.datatype_dict["type"], "string")
Example #7
0
    def test_create_non_choice_udf(self):
        body = {'udf.name': ' cool udf  ',
                'udf.model': 'Plot',
                'udf.type': 'string'}

        udf = udf_create(body, self.instance)
        self.assertEqual(udf.instance_id, self.instance.pk)
        self.assertEqual(udf.model_type, 'Plot')
        self.assertEqual(udf.name, 'cool udf')
        self.assertEqual(udf.datatype_dict['type'], 'string')
Example #8
0
    def test_create_choice_udf(self):
        body = {"udf.name": "cool udf", "udf.model": "Plot", "udf.type": "choice", "udf.choices": ["a", "b", "c"]}

        udf = udf_create(body, self.instance)

        self.assertEqual(udf.instance_id, self.instance.pk)
        self.assertEqual(udf.model_type, "Plot")
        self.assertEqual(udf.name, "cool udf")
        self.assertEqual(udf.datatype_dict["type"], "choice")
        self.assertEqual(udf.datatype_dict["choices"], ["a", "b", "c"])
Example #9
0
def create_udfs(udfs, instance):
    for model, model_rules in udfs.items():
        for field, field_rules in model_rules.items():
            # convert the migrator udf schema
            # to the udf-lib friendly schema

            name = field_rules['udf.name']
            model_type = to_model_name(model)
            choices = field_rules.get('udf.choices')
            datatype_type = field_rules.get('udf.type',
                                            'choice' if choices else 'string')

            udf_params = {
                'udf.name': name,
                'udf.model': model_type,
                'udf.type': datatype_type,
                'udf.choices': choices
            }

            if not udf_lib.udf_exists(udf_params, instance):
                print "Creating udf %s" % name
                udf_lib.udf_create(udf_params, instance)
Example #10
0
    def test_create_choice_udf(self):
        body = {'udf.name': 'cool udf',
                'udf.model': 'Plot',
                'udf.type': 'choice',
                'udf.choices': ['a', 'b', 'c']}

        udf = udf_create(body, self.instance)

        self.assertEqual(udf.instance_id, self.instance.pk)
        self.assertEqual(udf.model_type, 'Plot')
        self.assertEqual(udf.name, 'cool udf')
        self.assertEqual(udf.datatype_dict['type'], 'choice')
        self.assertEqual(udf.datatype_dict['choices'], ['a', 'b', 'c'])
Example #11
0
def create_udfs(udfs, instance):
    for model, model_rules in udfs.items():
        for field, field_rules in model_rules.items():
            # convert the migrator udf schema
            # to the udf-lib friendly schema

            name = field_rules['udf.name']
            model_type = to_model_name(model)
            choices = field_rules.get('udf.choices')
            datatype_type = field_rules.get(
                'udf.type', 'choice' if choices else 'string')

            udf_params = {
                'udf.name': name,
                'udf.model': model_type,
                'udf.type': datatype_type,
                'udf.choices': choices
            }

            if not udf_lib.udf_exists(udf_params, instance):
                print "Creating udf %s" % name
                udf_lib.udf_create(udf_params, instance)
Example #12
0
def udf_create(request, instance):
    params = json_from_request(request)
    udf = lib.udf_create(params, instance)
    add_udf_notification(instance, to_model_name(udf.full_name))
    return udf_context(instance, udf)
Example #13
0
def udf_create(request, instance):
    params = json_from_request(request)
    udf = lib.udf_create(params, instance)
    add_udf_notification(instance, to_model_name(udf.full_name))
    return udf_context(instance, udf)