def test_pending_udf_audits(self): UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps({'type': 'choice', 'choices': ['1', '2', '3']}), iscollection=False, name='times_climbed') add_field_permissions(self.instance, self.commander_user, 'Plot', ['udf:times_climbed']) FieldPermission.objects.create( model_name='Plot', field_name='udf:times_climbed', permission_level=FieldPermission.WRITE_WITH_AUDIT, role=self.pending_user.get_instance_user(self.instance).role, instance=self.instance) initial_plot = Plot(geom=self.p1, instance=self.instance) initial_plot.udfs['times_climbed'] = '2' initial_plot.save_with_user(self.pending_user) udf_audit = Audit.objects.get(model='Plot', field='udf:times_climbed', model_id=initial_plot.pk) approve_or_reject_audit_and_apply(udf_audit, self.commander_user, approved=True) geom_audit = Audit.objects.get(model='Plot', field='geom', model_id=initial_plot.pk) approve_or_reject_audit_and_apply(geom_audit, self.commander_user, approved=True) readonly_audit = Audit.objects.get(model='Plot', field='readonly', model_id=initial_plot.pk) approve_or_reject_audit_and_apply(readonly_audit, self.commander_user, approved=True) insert_audit = Audit.objects.get(model='Plot', field='id', model_id=initial_plot.pk) approve_or_reject_audit_and_apply(insert_audit, self.commander_user, approved=True) new_plot = Plot.objects.get(pk=initial_plot.pk) self.assertEqual(new_plot.pk, initial_plot.pk) self.assertEqual(new_plot.readonly, False) self.assertEqual(new_plot.geom, self.p1) self.assertEqual(new_plot.udfs['times_climbed'], '2')
def _setup_udfs(self): add_field_permissions(self.instance, self.commander, 'Plot', ['udf:Test string', 'udf:Test date']) add_field_permissions(self.instance, self.commander, 'Tree', ['udf:Test float']) UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps({'type': 'string'}), iscollection=False, name='Test string') UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps({'type': 'date'}), iscollection=False, name='Test date') UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Tree', datatype=json.dumps({'type': 'float'}), iscollection=False, name='Test float') psycopg2.extras.register_hstore(connection.cursor(), globally=True) p1, _ = self.create_tree_and_plot( plotudfs={'Test string': 'testing foo', 'Test date': datetime(2010, 1, 9)}, treeudfs={'Test float': 9.2}) p2, _ = self.create_tree_and_plot( plotudfs={'Test string': 'testing baz or fish', 'Test date': datetime(2012, 1, 9)}, treeudfs={'Test float': 12.0}) p3, _ = self.create_tree_and_plot( plotudfs={'Test string': 'baz', 'Test date': datetime(2014, 1, 9)}, treeudfs={'Test float': 2.2}) return (p.pk for p in [p1, p2, p3])
def setUp(self): self.instance = make_instance() self.commander_user = make_commander_user(self.instance) add_field_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 setUp(self): self.instance = make_instance() self.p = Point(-8515941.0, 4953519.0) UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps([ {'type': 'string', 'name': 'action'}, {'type': 'int', 'name': 'height'}]), iscollection=True, name='Stewardship') self.commander_user = make_commander_user(self.instance) add_field_permissions(self.instance, self.commander_user, 'Plot', ['udf:Stewardship']) 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 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) add_field_permissions(self.instance, self.commander_user, 'Plot', addl_fields) for dtype in allowed_types: make_and_save_type(dtype) 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 setUp(self): self.instance = make_instance() self.commander_user = make_commander_user(self.instance) add_field_permissions(self.instance, self.commander_user, 'Plot', ['udf:Test choice', 'udf:Test string', 'udf:Test int', 'udf:Test date', 'udf:Test float']) 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 string') UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps({'type': 'date'}), iscollection=False, name='Test date') UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps({'type': 'int'}), iscollection=False, name='Test int') UserDefinedFieldDefinition.objects.create( instance=self.instance, model_type='Plot', datatype=json.dumps({'type': 'float'}), iscollection=False, name='Test float') 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 create_and_save_with_choice(c, n=1): plots = [] for i in xrange(n): plot = Plot(geom=self.p, instance=self.instance) plot.udfs['Test choice'] = c plot.save_with_user(self.commander_user) plots.append(plot) return {plot.pk for plot in plots} self.choice_a = create_and_save_with_choice('a', n=2) self.choice_b = create_and_save_with_choice('b', n=3) self.choice_c = create_and_save_with_choice('c', n=7)