def _test_negative_adjustment(self, initial, adjusted): iuser = self.unprivileged_user.get_instance_user(self.instance) iuser.reputation = initial iuser.save_base() audit = Audit(model='Tree', model_id=1, action=Audit.Type.Insert, instance=self.instance, field='readonly', previous_value=None, current_value=True, user=self.unprivileged_user, requires_auth=True) audit.save() self.assertEqual(initial, iuser.reputation) review_audit = Audit(model='Tree', model_id=1, action=Audit.Type.PendingReject, instance=self.instance, field='readonly', previous_value=None, current_value=True, user=self.privileged_user) review_audit.save() audit.ref = review_audit audit.save() # requery iuser iuser = self.unprivileged_user.get_instance_user(self.instance) self.assertEqual(adjusted, iuser.reputation)
def setUp(self): self.instance = make_instance(name='Test Instance') self.species = Species(instance=self.instance, common_name='Test Common Name', genus='Test Genus', cultivar='Test Cultivar', species='Test Species') self.species.save_base() self.user = make_user(username='******', password='******') self.import_event = ImportEvent(imported_by=self.user) self.import_event.save_base() self.plot = Plot(geom=Point(0, 0), instance=self.instance, address_street="123 Main Street") self.plot.save_base() self.tree = Tree(plot=self.plot, instance=self.instance) self.tree.save_base() self.boundary = make_simple_boundary("Test Boundary") self.role = make_commander_role(self.instance) self.role.name = "Test Role" self.role.save() self.field_permission = FieldPermission( model_name="Tree", field_name="readonly", permission_level=FieldPermission.READ_ONLY, role=self.role, instance=self.instance) self.field_permission.save_base() self.audit = Audit(action=Audit.Type.Update, model="Tree", field="readonly", model_id=1, user=self.user, previous_value=True, current_value=False) self.audit.save_base() self.reputation_metric = ReputationMetric(instance=self.instance, model_name="Tree", action="Test Action") self.reputation_metric.save_base()
def test_reputation_metric_positive_adjustment_for_rm(self): self.assertEqual(0, self.unprivileged_user.get_reputation(self.instance)) audit = Audit(model='Tree', model_id=1, action=Audit.Type.Insert, instance=self.instance, field='readonly', previous_value=None, current_value=True, user=self.unprivileged_user) ReputationMetric.apply_adjustment(audit) self.assertEqual(2, self.unprivileged_user.get_reputation(self.instance))
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))
def test_basic_audit(self): plot = Plot(geom=self.instance.center, 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))
class ModelUnicodeTests(OTMTestCase): def setUp(self): self.instance = make_instance(name='Test Instance') self.species = Species(instance=self.instance, common_name='Test Common Name', genus='Test Genus', cultivar='Test Cultivar', species='Test Species') self.species.save_base() self.user = make_user(username='******', password='******') self.plot = Plot(geom=Point(1, 1), instance=self.instance, address_street="123 Main Street") self.plot.save_base() self.tree = Tree(plot=self.plot, instance=self.instance) self.tree.save_base() self.boundary = make_simple_boundary("Test Boundary") self.role = Role(instance=self.instance, name='Test Role', rep_thresh=2) self.role.save() self.field_permission = FieldPermission( model_name="Tree", field_name="readonly", permission_level=FieldPermission.READ_ONLY, role=self.role, instance=self.instance) self.field_permission.save_base() self.audit = Audit(action=Audit.Type.Update, model="Tree", field="readonly", model_id=1, user=self.user, previous_value=True, current_value=False) self.audit.save_base() self.reputation_metric = ReputationMetric(instance=self.instance, model_name="Tree", action="Test Action") self.reputation_metric.save_base() def test_instance_model(self): self.assertEqual(unicode(self.instance), "Test Instance") def test_species_model(self): self.assertEqual( unicode(self.species), "Test Common Name [Test Genus Test Species 'Test Cultivar']") def test_user_model(self): self.assertEqual(unicode(self.user), 'commander') def test_plot_model(self): self.assertEqual(unicode(self.plot), 'Plot (1.0, 1.0) 123 Main Street') def test_tree_model(self): self.assertEqual(unicode(self.tree), '') def test_boundary_model(self): self.assertEqual(unicode(self.boundary), 'Test Boundary') def test_role_model(self): self.assertEqual(unicode(self.role), 'Test Role (%s)' % self.role.pk) def test_field_permission_model(self): self.assertEqual(unicode(self.field_permission), 'Tree.readonly - Test Role (%s) - Read Only' % self.role.pk) def test_audit_model(self): self.assertEqual( unicode(self.audit), 'pk=%s - action=Update - Tree.readonly:(1) - True => False' % self.audit.pk) def test_reputation_metric_model(self): self.assertEqual(unicode(self.reputation_metric), 'Test Instance - Tree - Test Action')
class ModelUnicodeTests(OTMTestCase): def setUp(self): self.instance = make_instance(name='Test Instance') self.species = Species(instance=self.instance, common_name='Test Common Name', genus='Test Genus', cultivar='Test Cultivar', species='Test Species') self.species.save_base() self.user = make_user(username='******', password='******') self.plot = Plot(geom=Point(1, 1), instance=self.instance, address_street="123 Main Street") self.plot.save_base() self.tree = Tree(plot=self.plot, instance=self.instance) self.tree.save_base() self.boundary = make_simple_boundary("Test Boundary") self.role = Role(instance=self.instance, name='Test Role', rep_thresh=2) self.role.save() self.field_permission = FieldPermission( model_name="Tree", field_name="readonly", permission_level=FieldPermission.READ_ONLY, role=self.role, instance=self.instance) self.field_permission.save_base() self.audit = Audit(action=Audit.Type.Update, model="Tree", field="readonly", model_id=1, user=self.user, previous_value=True, current_value=False) self.audit.save_base() self.reputation_metric = ReputationMetric(instance=self.instance, model_name="Tree", action="Test Action") self.reputation_metric.save_base() def test_instance_model(self): self.assertEqual(unicode(self.instance), "Test Instance") def test_species_model(self): self.assertEqual( unicode(self.species), "Test Common Name [Test Genus Test Species 'Test Cultivar']") def test_user_model(self): self.assertEqual(unicode(self.user), 'commander') def test_plot_model(self): self.assertEqual(unicode(self.plot), 'Plot (1.0, 1.0) 123 Main Street') def test_tree_model(self): self.assertEqual(unicode(self.tree), '') def test_boundary_model(self): self.assertEqual(unicode(self.boundary), 'Test Boundary') def test_role_model(self): self.assertEqual(unicode(self.role), 'Test Role (%s)' % self.role.pk) def test_field_permission_model(self): self.assertEqual( unicode(self.field_permission), 'Tree.readonly - Test Role (%s) - Read Only' % self.role.pk) def test_audit_model(self): self.assertEqual( unicode(self.audit), 'pk=%s - action=Update - Tree.readonly:(1) - True => False' % self.audit.pk) def test_reputation_metric_model(self): self.assertEqual(unicode(self.reputation_metric), 'Test Instance - Tree - Test Action')