def setUp(self):
        self.instance = make_instance()
        self.instance.save()
        self.role = Role(name='role', instance=self.instance, rep_thresh=0)
        self.role.save()

        self.observer = make_observer_user(self.instance)

        self.udf_role = Role(name='udf', instance=self.instance, rep_thresh=0)
        self.udf_role.save()

        self.template_dir = tempfile.mkdtemp()
        self.template_file_path = os.path.join(self.template_dir,
                                               "field_template.html")

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

        udf_perm, __ = FieldPermission.objects.get_or_create(
            model_name='Plot', field_name='udf:Test choice',
            permission_level=FieldPermission.READ_ONLY,
            role=self.role, instance=self.instance)
        udf_perm.save()
        udf_write_perm, __ = FieldPermission.objects.get_or_create(
            model_name='Plot', field_name='udf:Test choice',
            permission_level=FieldPermission.WRITE_DIRECTLY,
            role=self.udf_role, instance=self.instance)
        udf_write_perm.save()
    def setUp(self):
        self.instance = make_instance()

        self.user = make_user(username='******', password='******')

        self.role = Role(name='role', instance=self.instance, rep_thresh=0)
        self.role.save()

        self.user_perm, __ = FieldPermission.objects.get_or_create(
            model_name='Plot', field_name='width',
            permission_level=FieldPermission.NONE,
            role=self.role, instance=self.instance)

        iuser = InstanceUser(instance=self.instance, user=self.user,
                             role=self.role)
        iuser.save_with_user(self.user)

        inst_role = Role(name='inst def role',
                         instance=self.instance,
                         rep_thresh=0)
        inst_role.save()

        self.inst_perm, __ = FieldPermission.objects.get_or_create(
            model_name='Plot', field_name='width',
            permission_level=FieldPermission.NONE,
            role=inst_role, instance=self.instance)

        self.instance.default_role = inst_role
        self.instance.save()

        self.plot = Plot(instance=self.instance)
Example #3
0
    def test_user_roles_updated(self):
        iuser = InstanceUser(user=self.user2,
                             instance=self.instance,
                             role=self.instance.default_role)
        iuser.save_with_user(self.commander)

        new_role = Role(name='Ambassador',
                        instance=self.instance,
                        rep_thresh=0)
        new_role.save()

        body = {'users': {iuser.pk: {'role': new_role.pk, 'admin': False}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander), self.instance)

        #requery iuser
        iuser = InstanceUser.objects.get(pk=iuser.pk)
        self.assertEqual(iuser.role, new_role)
        self.assertEqual(iuser.admin, False)

        body = {'users': {iuser.pk: {'role': new_role.pk, 'admin': True}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander), self.instance)

        #requery iuser
        iuser = InstanceUser.objects.get(pk=iuser.pk)
        self.assertEqual(iuser.role, new_role)
        self.assertEqual(iuser.admin, True)
Example #4
0
    def setUp(self):
        self.instance = make_instance()
        self.commander = make_commander_user(self.instance)

        self.new_role = Role(name='Ambassador', instance=self.instance,
                             rep_thresh=0)
        self.new_role.save()

        self.factory = RequestFactory()
Example #5
0
    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()
Example #6
0
    def test_invites_updated(self):
        email = "*****@*****.**"
        invite = InstanceInvitation(email=email,
                                    instance=self.instance,
                                    created_by=self.user4,
                                    role=self.instance.default_role)
        invite.save()

        new_role = Role(name='Ambassador',
                        instance=self.instance,
                        rep_thresh=0)
        new_role.save()

        body = {'invites': {invite.pk: {'role': new_role.pk}}}

        update_user_roles(
            make_request(method='POST',
                         body=json.dumps(body),
                         user=self.commander), self.instance)

        # requery invite
        invite = InstanceInvitation.objects.get(pk=invite.pk)
        self.assertEqual(invite.role, new_role)