当前位置: 首页>>代码示例>>Python>>正文


Python Plot.audits方法代码示例

本文整理汇总了Python中treemap.models.Plot.audits方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.audits方法的具体用法?Python Plot.audits怎么用?Python Plot.audits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treemap.models.Plot的用法示例。


在下文中一共展示了Plot.audits方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_record_is_created_when_nullables_are_still_pending

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
    def test_record_is_created_when_nullables_are_still_pending(self):
        new_plot = Plot(geom=self.p1, instance=self.instance)
        new_plot.save_with_user(self.pending_user)

        new_tree = Tree(plot=new_plot, instance=self.instance,
                        diameter=10, height=10, readonly=False)

        new_tree.save_with_user(self.pending_user)

        approve_or_reject_audits_and_apply(
            new_plot.audits(),
            self.commander_user, True)

        insert_audit = Audit.objects.filter(model='Tree')\
                                    .get(field='id')
        field_audits = Audit.objects.filter(model='Tree')\
                                    .filter(field__in=['readonly', 'diameter',
                                                       'plot'])
        for audit in field_audits:
            approve_or_reject_audit_and_apply(
                audit, self.commander_user, approved=True)

        approve_or_reject_audit_and_apply(insert_audit,
                                          self.commander_user, True)

        real_tree = Tree.objects.get(pk=new_tree.pk)

        self.assertEqual(real_tree.plot_id, new_plot.pk)
        self.assertEqual(real_tree.diameter, 10)
        self.assertEqual(real_tree.height, None)
        self.assertNotEqual(real_tree.readonly, True)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:33,代码来源:test_audit.py

示例2: AuditDetailTagTest

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
class AuditDetailTagTest(OTMTestCase):

    def setUp(self):
        self.p1 = Point(-8515222.0, 4953200.0)

        self.instance = make_instance(point=self.p1)
        self.user = make_commander_user(self.instance)

        self.plot = Plot(geom=self.p1, instance=self.instance)
        self.plot.save_with_user(self.user)

        self.tree = Tree(
            plot=self.plot, instance=self.instance, readonly=False)
        self.tree.save_with_user(self.user)

    def test_tree_link(self):
        audit = self.tree.audits()[0]
        link = audit_detail_link(audit)

        target = reverse('tree_detail',
                         kwargs={'instance_url_name': self.instance.url_name,
                                 'feature_id': self.tree.plot.pk,
                                 'tree_id': self.tree.pk})

        self.assertEqual(link, target)

    def test_plot_link(self):
        audit = self.plot.audits()[0]
        link = audit_detail_link(audit)

        target = reverse('map_feature_detail',
                         kwargs={'instance_url_name': self.instance.url_name,
                                 'feature_id': self.plot.pk})

        self.assertEqual(link, target)

    def test_bad_model_returns_none(self):
        audit = self.plot.audits()[0]
        audit.model = 'invaild'

        self.assertIsNone(audit_detail_link(audit))

    def test_bad_id_returns_none(self):
        audit = self.plot.audits()[0]
        audit.model_id = -1000

        self.assertIsNone(audit_detail_link(audit))
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:49,代码来源:test_audit.py

示例3: test_lots_of_trees_and_plots

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
    def test_lots_of_trees_and_plots(self):
        """
        Make 3 plots: 2 pending and 1 approved
        Make 4 trees: 1 on each pending plot, 2 on approved plot
        Approve one pending plot.
        Approve all trees. The one on the (Still) pending plot
        should fail. all else should pass.
        """
        p1 = Point(0, 0)
        p2 = Point(1, 1)
        p3 = Point(2, 2)
        plot1 = Plot(geom=p1, instance=self.instance)
        plot2 = Plot(geom=p2, instance=self.instance)
        plot3 = Plot(geom=p3, instance=self.instance)
        plot1.save_with_user(self.commander_user)
        plot2.save_with_user(self.pending_user)
        plot3.save_with_user(self.pending_user)
        tree1 = Tree(plot=plot1, instance=self.instance)
        tree1.save_with_user(self.pending_user)
        tree2 = Tree(plot=plot1, instance=self.instance)
        tree2.save_with_user(self.pending_user)
        tree3 = Tree(plot=plot2, instance=self.instance)
        tree3.save_with_user(self.pending_user)
        tree4 = Tree(plot=plot3, instance=self.instance)
        tree4.save_with_user(self.pending_user)

        approve_or_reject_audits_and_apply(
            plot2.audits(),
            self.commander_user, True)

        approve_or_reject_audits_and_apply(
            tree1.audits(),
            self.commander_user, True)

        approve_or_reject_audits_and_apply(
            tree2.audits(),
            self.commander_user, True)

        approve_or_reject_audits_and_apply(
            tree3.audits(),
            self.commander_user, True)

        self.assertRaises(ObjectDoesNotExist, Plot.objects.get, pk=plot3.pk)
        self.assertRaises(ObjectDoesNotExist,
                          approve_or_reject_audits_and_apply,
                          tree4.audits(),
                          self.commander_user, True)
开发者ID:mmcfarland,项目名称:OTM2,代码行数:49,代码来源:audit.py

示例4: test_insert_writes_when_approved

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
    def test_insert_writes_when_approved(self):

        new_plot = Plot(geom=self.p1, instance=self.instance)
        new_plot.save_with_user(self.pending_user)

        new_tree = Tree(plot=new_plot, instance=self.instance)
        new_tree.save_with_user(self.pending_user)

        self.assertEquals(Plot.objects.count(), 0)
        self.assertEquals(Tree.objects.count(), 0)

        approve_or_reject_audits_and_apply(
            list(new_tree.audits()) + list(new_plot.audits()),
            self.commander_user, True)

        self.assertEqual(Plot.objects.all().count(), 1)
        self.assertEqual(Tree.objects.all().count(), 1)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:19,代码来源:test_audit.py

示例5: test_basic_audit

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
    def test_basic_audit(self):
        p = Point(-8515222.0, 4953200.0)
        plot = Plot(geom=p, instance=self.instance)
        plot.save_with_user(self.user1)

        self.assertAuditsEqual([
            self.make_audit(plot.pk, 'id', None, str(plot.pk), model='Plot'),
            self.make_audit(plot.pk, 'readonly', None, 'False',
                            model='Plot'),
            self.make_audit(plot.pk, 'geom', None, str(plot.geom),
                            model='Plot')], plot.audits())

        t = Tree(plot=plot, instance=self.instance, readonly=True)

        t.save_with_user(self.user1)

        expected_audits = [
            self.make_audit(t.pk, 'id', None, str(t.pk)),
            self.make_audit(t.pk, 'readonly', None, True),
            self.make_audit(t.pk, 'plot', None, plot.pk)]

        self.assertAuditsEqual(expected_audits, t.audits())

        t.readonly = False
        t.save_with_user(self.user2)

        expected_audits.insert(
            0, self.make_audit(t.pk, 'readonly', 'True', 'False',
                               action=Audit.Type.Update, user=self.user2))

        self.assertAuditsEqual(expected_audits, t.audits())

        old_pk = t.pk
        t.delete_with_user(self.user1)

        expected_audits.insert(
            0, self.make_audit(old_pk, None, None, None,
                               action=Audit.Type.Delete, user=self.user1))

        self.assertAuditsEqual(
            expected_audits,
            Audit.audits_for_model('Tree', self.instance, old_pk))
开发者ID:mmcfarland,项目名称:OTM2,代码行数:44,代码来源:audit.py

示例6: test_approve_insert_without_required_raises_integrity_error

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
    def test_approve_insert_without_required_raises_integrity_error(self):
        new_plot = Plot(geom=self.p1, instance=self.instance)
        new_plot.save_with_user(self.pending_user)

        new_tree = Tree(plot=new_plot, instance=self.instance,
                        diameter=10, height=10, readonly=False)
        new_tree.save_with_user(self.pending_user)

        approve_or_reject_audits_and_apply(
            new_plot.audits(),
            self.commander_user, True)

        diameter_audit = Audit.objects.get(model='Tree',
                                           field='diameter',
                                           model_id=new_tree.pk)
        insert_audit = Audit.objects.get(model='Tree',
                                         model_id=new_tree.pk,
                                         field='id')

        approve_or_reject_audit_and_apply(
            diameter_audit, self.commander_user, approved=True)

        self.assertRaises(IntegrityError, approve_or_reject_audit_and_apply,
                          insert_audit, self.commander_user, True)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:26,代码来源:test_audit.py

示例7: ReviewTest

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
class ReviewTest(MultiUserTestCase):
    def setUp(self):
        super(ReviewTest, self).setUp()

        self.plot = Plot(geom=self.p1, instance=self.instance)
        self.plot.save_with_user(self.commander_user)

    def test_simple_approve(self):
        self.plot.width = 444
        self.plot.save_with_user(self.commander_user)

        width_audit = self.plot.audits().order_by('-created')[0]

        # Sanity check
        self.assertEqual(width_audit.field, 'width')

        # Should not have a reference associated with it
        self.assertIsNone(width_audit.ref)

        approve_or_reject_existing_edit(
            width_audit, self.commander_user, approved=True)

        width_audit_reloaded = Audit.objects.get(pk=width_audit.pk)
        self.assertIsNotNone(width_audit_reloaded.ref)

        refd = width_audit_reloaded.ref
        self.assertEqual(refd.action, Audit.Type.ReviewApprove)

    def test_reject_regular_edit(self):
        self.plot.width = 444
        self.plot.save_with_user(self.commander_user)

        self.plot.width = 555
        self.plot.save_with_user(self.commander_user)

        width_audit = self.plot.audits().order_by('-created')[0]

        # Sanity check
        self.assertEqual(width_audit.field, 'width')

        # Should not have a reference associated with it
        self.assertIsNone(width_audit.ref)

        approve_or_reject_existing_edit(
            width_audit, self.commander_user, approved=False)

        width_audit_reloaded = Audit.objects.get(pk=width_audit.pk)
        self.assertIsNotNone(width_audit_reloaded.ref)

        refd = width_audit_reloaded.ref
        self.assertEqual(refd.action, Audit.Type.ReviewReject)

        plot_reloaded = Plot.objects.get(pk=self.plot.pk)
        self.assertEqual(plot_reloaded.width, 444)

    def test_reject_id_edit(self):
        id_audit = self.plot.audits().get(field='id')

        approve_or_reject_existing_edit(
            id_audit, self.commander_user, approved=False)

        all_audits = list(self.plot.audits())

        self.assertNotEqual(len(all_audits), 0)

        updated_audit = Audit.objects.get(pk=id_audit.pk)
        ref_audit = updated_audit.ref

        self.assertIsNotNone(ref_audit)
        self.assertEqual(ref_audit.action, Audit.Type.ReviewReject)

        self.assertRaises(Plot.DoesNotExist,
                          Plot.objects.get, pk=self.plot.pk)

    def test_requires_write_permissions_on_field(self):
        self.plot.width = 333
        self.plot.save_with_user(self.commander_user)

        width_audit = self.plot.audits().order_by('-created')[0]

        # Read only can't edit
        FieldPermission.objects.filter(field_name='width').update(
            permission_level=FieldPermission.READ_ONLY)

        self.assertRaises(AuthorizeException,
                          approve_or_reject_existing_edit,
                          width_audit, self.commander_user, approved=True)

        # Neither can 'write with audit'
        FieldPermission.objects.filter(field_name='width').update(
            permission_level=FieldPermission.WRITE_WITH_AUDIT)

        self.assertRaises(AuthorizeException,
                          approve_or_reject_existing_edit,
                          width_audit, self.commander_user, approved=True)

        # But write directly can
        FieldPermission.objects.filter(field_name='width').update(
            permission_level=FieldPermission.WRITE_DIRECTLY)

#.........这里部分代码省略.........
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:103,代码来源:test_audit.py

示例8: ScalarUDFTest

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
class ScalarUDFTest(TestCase):

    def setUp(self):
        self.instance = make_instance()
        self.p = Point(-8515941.0, 4953519.0)

        def make_and_save_type(dtype):
            UserDefinedFieldDefinition.objects.create(
                instance=self.instance,
                model_type='Plot',
                datatype=json.dumps({'type': dtype}),
                iscollection=False,
                name='Test %s' % dtype)

        allowed_types = 'float', 'int', 'string', 'user', 'date'

        addl_fields = ['udf:Test %s' % ttype for ttype in allowed_types]
        addl_fields.append('udf:Test choice')

        self.commander_user = make_commander_user(self.instance)
        set_write_permissions(self.instance, self.commander_user,
                              'Plot', addl_fields)

        for dtype in allowed_types:
            make_and_save_type(dtype)

        self.choice_udfd = UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'choice',
                                 'choices': ['a', 'b', 'c']}),
            iscollection=False,
            name='Test choice')

        self.plot = Plot(geom=self.p, instance=self.instance)
        self.plot.save_with_user(self.commander_user)

        psycopg2.extras.register_hstore(connection.cursor(), globally=True)

    def _test_datatype(self, field, value):
        self.plot.udfs[field] = value
        self.plot.save_with_user(self.commander_user)

        self.plot = Plot.objects.get(pk=self.plot.pk)

        self.assertEqual(
            self.plot.udfs[field], value)

    def test_int_datatype(self):
        self._test_datatype('Test int', 4)

    def test_int_validation_non_integer(self):
        self.assertRaises(ValidationError,
                          self._test_datatype, 'Test int', 42.3)

        self.assertRaises(ValidationError,
                          self._test_datatype, 'Test int', 'blah')

    def test_float_datatype(self):
        self._test_datatype('Test float', 4.4)

    def test_float_validation(self):
        self.assertRaises(ValidationError,
                          self._test_datatype, 'Test float', 'blah')

    def test_cant_update_choices_on_non_choice_model(self):
        floatfield = UserDefinedFieldDefinition\
            .objects\
            .filter(name='Test float')

        self.assertRaises(ValidationError,
                          floatfield[0].update_choice,
                          'a', 'b')

    def test_update_invalid_choice(self):
        self.assertRaises(ValidationError,
                          self.choice_udfd.update_choice,
                          'WHAT?????', 'm')

    def test_delete_choice_value(self):
        self.plot.udfs['Test choice'] = 'a'
        self.plot.save_with_user(self.commander_user)

        self.plot = Plot.objects.get(pk=self.plot.pk)
        audit = self.plot.audits().get(field='udf:Test choice')

        self.assertEqual(
            self.plot.udfs['Test choice'], 'a')
        self.assertEqual(
            audit.current_value, 'a')

        self.choice_udfd.delete_choice('a')

        self.plot = Plot.objects.get(pk=self.plot.pk)
        audit = self.plot.audits().filter(field='udf:Test choice')

        self.assertEqual(
            self.plot.udfs['Test choice'], None)
        self.assertEqual(
            audit.exists(), False)
#.........这里部分代码省略.........
开发者ID:danmcginnis,项目名称:OTM2,代码行数:103,代码来源:udfs.py

示例9: UDFAuditTest

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
class UDFAuditTest(TestCase):
    def setUp(self):
        self.instance = make_instance()
        self.commander_user = make_commander_user(self.instance)
        set_write_permissions(self.instance, self.commander_user,
                              'Plot', ['udf:Test choice'])

        self.p = Point(-8515941.0, 4953519.0)

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'choice',
                                 'choices': ['a', 'b', 'c']}),
            iscollection=False,
            name='Test choice')

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'string'}),
            iscollection=False,
            name='Test unauth')

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps([{'type': 'choice',
                                  'name': 'a choice',
                                  'choices': ['a', 'b', 'c']},
                                 {'type': 'string',
                                  'name': 'a string'}]),
            iscollection=True,
            name='Test collection')

        self.plot = Plot(geom=self.p, instance=self.instance)
        self.plot.save_with_user(self.commander_user)

        psycopg2.extras.register_hstore(connection.cursor(), globally=True)

    def test_mask_unauthorized_with_udfs(self):
        officer_user = make_officer_user(self.instance)

        self.plot.udfs['Test choice'] = 'b'
        self.plot.save_with_user(self.commander_user)
        self.plot.udfs['Test unauth'] = 'foo'
        self.plot.save_base()

        newplot = Plot.objects.get(pk=self.plot.pk)
        self.assertEqual(newplot.udfs['Test choice'], 'b')
        self.assertEqual(newplot.udfs['Test unauth'], 'foo')

        newplot = Plot.objects.get(pk=self.plot.pk)
        newplot.mask_unauthorized_fields(self.commander_user)
        self.assertEqual(newplot.udfs['Test choice'], 'b')
        self.assertEqual(newplot.udfs['Test unauth'], None)

        newplot = Plot.objects.get(pk=self.plot.pk)
        newplot.mask_unauthorized_fields(officer_user)
        self.assertEqual(newplot.udfs['Test choice'], None)
        self.assertEqual(newplot.udfs['Test unauth'], None)

    def test_update_field_creates_audit(self):
        self.plot.udfs['Test choice'] = 'b'
        self.plot.save_with_user(self.commander_user)

        last_audit = list(self.plot.audits())[-1]

        self.assertEqual(last_audit.model, 'Plot')
        self.assertEqual(last_audit.model_id, self.plot.pk)
        self.assertEqual(last_audit.field, 'udf:Test choice')
        self.assertEqual(last_audit.previous_value, None)
        self.assertEqual(last_audit.current_value, 'b')

        self.plot.udfs['Test choice'] = 'c'
        self.plot.save_with_user(self.commander_user)

        last_audit = list(self.plot.audits())[-1]

        self.assertEqual(last_audit.model, 'Plot')
        self.assertEqual(last_audit.model_id, self.plot.pk)
        self.assertEqual(last_audit.field, 'udf:Test choice')
        self.assertEqual(last_audit.previous_value, 'b')
        self.assertEqual(last_audit.current_value, 'c')

    def test_cant_edit_unauthorized_collection(self):
        self.plot.udfs['Test collection'] = [
            {'a choice': 'a', 'a string': 's'}]

        self.assertRaises(AuthorizeException,
                          self.plot.save_with_user, self.commander_user)

    def test_cant_edit_unauthorized_field(self):
        self.plot.udfs['Test unauth'] = 'c'
        self.assertRaises(AuthorizeException,
                          self.plot.save_with_user, self.commander_user)

    def test_create_and_apply_pending(self):
        pending = self.plot.audits().filter(requires_auth=True)

#.........这里部分代码省略.........
开发者ID:danmcginnis,项目名称:OTM2,代码行数:103,代码来源:udfs.py

示例10: ScalarUDFTest

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
class ScalarUDFTest(OTMTestCase):
    def setUp(self):
        self.p = Point(-8515941.0, 4953519.0)
        self.instance = make_instance(point=self.p)

        def make_and_save_type(dtype):
            UserDefinedFieldDefinition.objects.create(
                instance=self.instance,
                model_type="Plot",
                datatype=json.dumps({"type": dtype}),
                iscollection=False,
                name="Test %s" % dtype,
            )

        allowed_types = "float", "int", "string", "user", "date"

        addl_fields = ["udf:Test %s" % ttype for ttype in allowed_types]
        addl_fields.append("udf:Test choice")
        addl_fields.append("udf:Test multichoice")

        self.commander_user = make_commander_user(self.instance)
        set_write_permissions(self.instance, self.commander_user, "Plot", addl_fields)

        for dtype in allowed_types:
            make_and_save_type(dtype)

        self.choice_udfd = UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
            iscollection=False,
            name="Test choice",
        )

        self.multichoice_udfd = UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps({"type": "multichoice", "choices": ["a", "b", "c"]}),
            iscollection=False,
            name="Test multichoice",
        )

        self.plot = Plot(geom=self.p, instance=self.instance)
        self.plot.save_with_user(self.commander_user)

        psycopg2.extras.register_hstore(connection.cursor(), globally=True)

    def _test_datatype(self, field, value):
        self.plot.udfs[field] = value
        self.plot.save_with_user(self.commander_user)

        self.plot = Plot.objects.get(pk=self.plot.pk)

        self.assertEqual(self.plot.udfs[field], value)

    def test_int_datatype(self):
        self._test_datatype("Test int", 4)

    def test_int_validation_non_integer(self):
        self.assertRaises(ValidationError, self._test_datatype, "Test int", 42.3)

        self.assertRaises(ValidationError, self._test_datatype, "Test int", "blah")

    def test_float_datatype(self):
        self._test_datatype("Test float", 4.4)

    def test_float_validation(self):
        self.assertRaises(ValidationError, self._test_datatype, "Test float", "blah")

    def test_cant_update_choices_on_non_choice_model(self):
        floatfield = UserDefinedFieldDefinition.objects.filter(name="Test float")

        self.assertRaises(ValidationError, floatfield[0].update_choice, "a", "b")

    def test_update_invalid_choice(self):
        self.assertRaises(ValidationError, self.choice_udfd.update_choice, "WHAT?????", "m")

    def test_delete_choice_value(self):
        self.plot.udfs["Test choice"] = "a"
        self.plot.save_with_user(self.commander_user)

        self.plot = Plot.objects.get(pk=self.plot.pk)
        audit = self.plot.audits().get(field="udf:Test choice")

        self.assertEqual(self.plot.udfs["Test choice"], "a")
        self.assertEqual(audit.current_value, "a")

        self.choice_udfd.delete_choice("a")

        self.plot = Plot.objects.get(pk=self.plot.pk)
        audit = self.plot.audits().filter(field="udf:Test choice")

        self.assertEqual(self.plot.udfs["Test choice"], None)
        self.assertEqual(audit.exists(), False)

        choice = UserDefinedFieldDefinition.objects.get(pk=self.choice_udfd.pk)

        self.assertEqual(set(choice.datatype_dict["choices"]), {"b", "c"})

    def test_delete_multichoice_value(self):
#.........这里部分代码省略.........
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:103,代码来源:test_udfs.py

示例11: UDFAuditTest

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import audits [as 别名]
class UDFAuditTest(OTMTestCase):
    def setUp(self):
        self.p = Point(-8515941.0, 4953519.0)
        self.instance = make_instance(point=self.p)
        self.commander_user = make_commander_user(self.instance)
        set_write_permissions(self.instance, self.commander_user, "Plot", ["udf:Test choice"])

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
            iscollection=False,
            name="Test choice",
        )

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps({"type": "string"}),
            iscollection=False,
            name="Test unauth",
        )

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps(
                [
                    {"type": "choice", "name": "a choice", "choices": ["a", "b", "c"]},
                    {"type": "string", "name": "a string"},
                ]
            ),
            iscollection=True,
            name="Test collection",
        )

        self.plot = Plot(geom=self.p, instance=self.instance)
        self.plot.save_with_user(self.commander_user)

        psycopg2.extras.register_hstore(connection.cursor(), globally=True)

    def test_mask_unauthorized_with_udfs(self):
        officer_user = make_officer_user(self.instance)

        self.plot.udfs["Test choice"] = "b"
        self.plot.save_with_user(self.commander_user)
        self.plot.udfs["Test unauth"] = "foo"
        self.plot.save_base()

        newplot = Plot.objects.get(pk=self.plot.pk)
        self.assertEqual(newplot.udfs["Test choice"], "b")
        self.assertEqual(newplot.udfs["Test unauth"], "foo")

        newplot = Plot.objects.get(pk=self.plot.pk)
        newplot.mask_unauthorized_fields(self.commander_user)
        self.assertEqual(newplot.udfs["Test choice"], "b")
        self.assertEqual(newplot.udfs["Test unauth"], None)

        newplot = Plot.objects.get(pk=self.plot.pk)
        newplot.mask_unauthorized_fields(officer_user)
        self.assertEqual(newplot.udfs["Test choice"], None)
        self.assertEqual(newplot.udfs["Test unauth"], None)

    def test_update_field_creates_audit(self):
        self.plot.udfs["Test choice"] = "b"
        self.plot.save_with_user(self.commander_user)

        last_audit = list(self.plot.audits())[-1]

        self.assertEqual(last_audit.model, "Plot")
        self.assertEqual(last_audit.model_id, self.plot.pk)
        self.assertEqual(last_audit.field, "udf:Test choice")
        self.assertEqual(last_audit.previous_value, None)
        self.assertEqual(last_audit.current_value, "b")

        self.plot.udfs["Test choice"] = "c"
        self.plot.save_with_user(self.commander_user)

        last_audit = list(self.plot.audits())[-1]

        self.assertEqual(last_audit.model, "Plot")
        self.assertEqual(last_audit.model_id, self.plot.pk)
        self.assertEqual(last_audit.field, "udf:Test choice")
        self.assertEqual(last_audit.previous_value, "b")
        self.assertEqual(last_audit.current_value, "c")

    def test_cant_edit_unauthorized_collection(self):
        self.plot.udfs["Test collection"] = [{"a choice": "a", "a string": "s"}]

        self.assertRaises(AuthorizeException, self.plot.save_with_user, self.commander_user)

    def test_cant_edit_unauthorized_field(self):
        self.plot.udfs["Test unauth"] = "c"
        self.assertRaises(AuthorizeException, self.plot.save_with_user, self.commander_user)

    def test_create_and_apply_pending(self):
        pending = self.plot.audits().filter(requires_auth=True)

        self.assertEqual(len(pending), 0)

#.........这里部分代码省略.........
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:103,代码来源:test_udfs.py


注:本文中的treemap.models.Plot.audits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。