def test_get(self):
     response = self.client.get(reverse("formidable:accesses_list"))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(response.data), 4)
     for access in response.data:
         self.assertIn("id", access)
         self.assertIn("label", access)
         self.assertIn(access["id"], [obj.id for obj in get_accesses()])
         self.assertIn(access["label"], [obj.label for obj in get_accesses()])
 def test_get(self):
     response = self.client.get(reverse('formidable:accesses_list'))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(response.data), 4)
     for access in response.data:
         self.assertIn('id', access)
         self.assertIn('label', access)
         self.assertIn(access['id'], [obj.id for obj in get_accesses()])
         self.assertIn(access['label'],
                       [obj.label for obj in get_accesses()])
 def test_get(self):
     response = self.client.get(reverse('formidable:accesses_list'))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(response.data), 4)
     for access in response.data:
         self.assertIn('id', access)
         self.assertIn('label', access)
         self.assertIn(
             access['id'], [obj.id for obj in get_accesses()]
         )
         self.assertIn(
             access['label'], [obj.label for obj in get_accesses()]
         )
Exemplo n.º 4
0
 def test_get(self):
     response = self.client.get(reverse('formidable:accesses_list'))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(len(response.data), 5)
     for access in response.data:
         self.assertIn('id', access)
         self.assertIn('label', access)
         self.assertIn(access['id'], [obj.id for obj in get_accesses()])
         self.assertIn(access['label'],
                       [obj.label for obj in get_accesses()])
         self.assertIn('preview_as', access)
         if access['id'] == 'robot':
             self.assertEqual(access['preview_as'], 'TABLE')
         else:
             self.assertEqual(access['preview_as'], 'FORM')
    def test_delete_field_on_update(self):
        self.form.fields.create(
            type_id='text', slug='textslug', label=u'mytext',
            order=self.form.get_next_field_order()
        )
        self.form.fields.create(
            order=self.form.get_next_field_order(),
            type_id='text', slug='delete-slug', label='text'
        )

        for access in get_accesses():
            for field in self.form.fields.all():
                field.accesses.create(access_id=access.id, level=u'EDITABLE')

        res = self.client.put(self.edit_url, form_data,  format='json')
        self.assertEquals(res.status_code, 200)
        form = Formidable.objects.order_by('pk').last()
        self.assertEquals(form.pk, self.form.pk)
        self.assertEquals(form.fields.count(), 1)
        field = form.fields.first()
        self.assertEquals(field.label, u'hello')
        self.assertEquals(field.accesses.count(), 4)
        self.assertTrue(field.accesses.filter(
            access_id=u'padawan', level='REQUIRED'
        ).exists())
        self.assertTrue(field.accesses.filter(
            access_id=u'human', level='HIDDEN'
        ).exists())
        self.assertTrue(field.accesses.filter(
            access_id="jedi-master", level="READONLY"
        ).exists())
Exemplo n.º 6
0
 def get(self, request, format=None):
     serializer = SimpleAccessSerializer(data=get_accesses())
     if serializer.is_valid():
         return Response(serializer.data)
     else:
         return Response(data=serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 7
0
    def test_delete_field_on_update(self):
        self.form.fields.create(type_id='text',
                                slug='textslug',
                                label='mytext',
                                order=self.form.get_next_field_order())
        self.form.fields.create(order=self.form.get_next_field_order(),
                                type_id='text',
                                slug='delete-slug',
                                label='text')

        for access in get_accesses():
            for field in self.form.fields.all():
                field.accesses.create(access_id=access.id, level='EDITABLE')

        res = self.client.put(self.edit_url, form_data, format='json')
        self.assertEquals(res.status_code, 200)
        form = Formidable.objects.order_by('pk').last()
        self.assertEquals(form.pk, self.form.pk)
        self.assertEquals(form.fields.count(), 1)
        field = form.fields.first()
        self.assertEquals(field.label, 'hello')
        self.assertEquals(field.accesses.count(), 5)
        self.assertTrue(
            field.accesses.filter(access_id='padawan',
                                  level='REQUIRED').exists())
        self.assertTrue(
            field.accesses.filter(access_id='human', level='HIDDEN').exists())
        self.assertTrue(
            field.accesses.filter(access_id="jedi-master",
                                  level="READONLY").exists())
Exemplo n.º 8
0
    def validate(self, data):
        accesses_id = [accesses['access_id'] for accesses in data]

        for access in get_accesses():
            if access.id not in accesses_id:
                data.append({'access_id': access.id, 'level': EDITABLE})

        return data
Exemplo n.º 9
0
 def validate_access_id(self, value):
     accesses_ids = [access.id for access in get_accesses()]
     if value not in accesses_ids:
         raise serializers.ValidationError(
             '{value} is unknown, valid access {accesses_ids}'.format(
                 value=value, accesses_ids=accesses_ids
             )
         )
     return value
Exemplo n.º 10
0
 def get_complete_accesses(self):
     """
     Return an access dict with all the access-rights defined by the client.
     If access-rights are missing in the :attr:`accesses` they will be added
     with a default value of `EDITABLE`.
     If the access-right is unknown, an exception will be raised.
     """
     accesses = {}
     for access in get_accesses():
         if access.id not in self.accesses.keys():
             accesses[access.id] = EDITABLE
         else:
             accesses[access.id] = self.accesses[access.id]
     return accesses
    def test_create_field_on_update(self):
        field = self.form.fields.create(
            type_id="text", slug="textslug", label="mytext", order=self.form.get_next_field_order()
        )
        for access in get_accesses():
            field.accesses.create(access_id=access.id, level="EDITABLE")

        data = deepcopy(form_data)
        data["fields"].extend(form_data_items["fields"])
        res = self.client.put(self.edit_url, data, format="json")
        self.assertEquals(res.status_code, 200)
        form = Formidable.objects.order_by("pk").last()
        self.assertEquals(form.pk, self.form.pk)
        self.assertEquals(form.fields.count(), 2)
 def test_update_simple_fields(self):
     field = self.form.fields.create(
         type_id="text", slug="textslug", label="mytext", order=self.form.get_next_field_order()
     )
     for access in get_accesses():
         field.accesses.create(access_id=access.id, level="EDITABLE")
     res = self.client.put(self.edit_url, form_data, format="json")
     self.assertEquals(res.status_code, 200)
     form = Formidable.objects.order_by("pk").last()
     self.assertEquals(form.pk, self.form.pk)
     self.assertEquals(form.fields.count(), 1)
     field = form.fields.first()
     self.assertEquals(field.label, "hello")
     self.assertEquals(field.accesses.count(), 4)
Exemplo n.º 13
0
 def get_complete_accesses(self):
     """
     Return an access dict with all the access-rights defined by the client.
     If access-rights are missing in the :attr:`accesses` they will be added
     with a default value of `EDITABLE`.
     If the access-right is unknown, an exception will be raised.
     """
     accesses = {}
     for access in get_accesses():
         if access.id not in self.accesses.keys():
             accesses[access.id] = EDITABLE
         else:
             accesses[access.id] = self.accesses[access.id]
     return accesses
Exemplo n.º 14
0
    def test_create_field_on_update(self):
        field = self.form.fields.create(type_id='text',
                                        slug='textslug',
                                        label='mytext',
                                        order=self.form.get_next_field_order())
        for access in get_accesses():
            field.accesses.create(access_id=access.id, level='EDITABLE')

        data = deepcopy(form_data)
        data['fields'].extend(form_data_items['fields'])
        res = self.client.put(self.edit_url, data, format='json')
        self.assertEquals(res.status_code, 200)
        form = Formidable.objects.order_by('pk').last()
        self.assertEquals(form.pk, self.form.pk)
        self.assertEquals(form.fields.count(), 2)
    def test_create_field_on_update(self):
        field = self.form.fields.create(
            type_id='text', slug='textslug', label=u'mytext',
            order=self.form.get_next_field_order()
        )
        for access in get_accesses():
            field.accesses.create(access_id=access.id, level=u'EDITABLE')

        data = deepcopy(form_data)
        data['fields'].extend(form_data_items['fields'])
        res = self.client.put(self.edit_url, data,  format='json')
        self.assertEquals(res.status_code, 200)
        form = Formidable.objects.order_by('pk').last()
        self.assertEquals(form.pk, self.form.pk)
        self.assertEquals(form.fields.count(), 2)
Exemplo n.º 16
0
 def test_update_simple_fields(self):
     field = self.form.fields.create(type_id='text',
                                     slug='textslug',
                                     label='mytext',
                                     order=self.form.get_next_field_order())
     for access in get_accesses():
         field.accesses.create(access_id=access.id, level='EDITABLE')
     res = self.client.put(self.edit_url, form_data, format='json')
     self.assertEquals(res.status_code, 200)
     form = Formidable.objects.order_by('pk').last()
     self.assertEquals(form.pk, self.form.pk)
     self.assertEquals(form.fields.count(), 1)
     field = form.fields.first()
     self.assertEquals(field.label, 'hello')
     self.assertEquals(field.accesses.count(), 5)
 def test_update_simple_fields(self):
     field = self.form.fields.create(
         type_id='text', slug='textslug', label=u'mytext',
         order=self.form.get_next_field_order()
     )
     for access in get_accesses():
         field.accesses.create(access_id=access.id, level=u'EDITABLE')
     res = self.client.put(self.edit_url, form_data,  format='json')
     self.assertEquals(res.status_code, 200)
     form = Formidable.objects.order_by('pk').last()
     self.assertEquals(form.pk, self.form.pk)
     self.assertEquals(form.fields.count(), 1)
     field = form.fields.first()
     self.assertEquals(field.label, u'hello')
     self.assertEquals(field.accesses.count(), 4)
    def test_delete_field_on_update(self):
        self.form.fields.create(type_id="text", slug="textslug", label="mytext", order=self.form.get_next_field_order())
        self.form.fields.create(
            order=self.form.get_next_field_order(), type_id="text", slug="delete-slug", label="text"
        )

        for access in get_accesses():
            for field in self.form.fields.all():
                field.accesses.create(access_id=access.id, level="EDITABLE")

        res = self.client.put(self.edit_url, form_data, format="json")
        self.assertEquals(res.status_code, 200)
        form = Formidable.objects.order_by("pk").last()
        self.assertEquals(form.pk, self.form.pk)
        self.assertEquals(form.fields.count(), 1)
        field = form.fields.first()
        self.assertEquals(field.label, "hello")
        self.assertEquals(field.accesses.count(), 4)
        self.assertTrue(field.accesses.filter(access_id="padawan", level="REQUIRED").exists())
        self.assertTrue(field.accesses.filter(access_id="human", level="HIDDEN").exists())
        self.assertTrue(field.accesses.filter(access_id="jedi-master", level="READONLY").exists())
Exemplo n.º 19
0
 def get_context_data(self):
     context = super().get_context_data()
     context['roles'] = get_accesses()
     return context
Exemplo n.º 20
0
 def get(self, request, format=None):
     serializer = SimpleAccessSerializer(data=get_accesses())
     if serializer.is_valid():
         return Response(serializer.data)
     else:
         return Response(data=serializer.errors, status_code=400)
Exemplo n.º 21
0
 def get_context_data(self):
     context = super(FormidableListView, self).get_context_data()
     context['roles'] = get_accesses()
     return context
Exemplo n.º 22
0
 def check_accesses(self):
     accesses_id = [access.id for access in get_accesses()]
     for access in self.accesses.keys():
         if access not in accesses_id:
             raise AccessUnknow(access)
Exemplo n.º 23
0
 def get(self, request, format=None):
     serializer = SimpleAccessSerializer(data=get_accesses())
     if serializer.is_valid():
         return Response(serializer.data)
     else:
         return Response(data=serializer.errors, status_code=400)
Exemplo n.º 24
0
 def get_context_data(self):
     context = super(FormidableListView, self).get_context_data()
     context['roles'] = get_accesses()
     return context
Exemplo n.º 25
0
 def check_accesses(self):
     accesses_id = [access.id for access in get_accesses()]
     for access in self.accesses.keys():
         if access not in accesses_id:
             raise UnknownAccess(access)