Пример #1
0
    def test_import_without_mandatory_parameter(self):
        with self.assertRaises(RuntimeError):
            EntityResource.import_data_from_request(
                {
                    'note': 'fuga',
                    'created_user': self._test_user.username,
                }, self._test_user)

        self.assertEqual(Entity.objects.count(), 0)
Пример #2
0
    def test_import_with_invalid_parameter(self):
        with self.assertRaises(RuntimeError):
            EntityResource.import_data_from_request(
                {
                    'name': 'hoge',
                    'note': 'fuga',
                    'invalid_key': 'invalid_value',
                    'created_user': self._test_user.username,
                }, self._test_user)

        self.assertEqual(Entity.objects.count(), 0)
Пример #3
0
 def test_import_with_new_object(self):
     EntityResource.import_data_from_request(
         {
             'name': 'foo',
             'note': 'bar',
             'created_user': self._test_user,
         }, self._test_user)
     self.assertEqual(Entity.objects.count(), 1)
     self.assertEqual(Entity.objects.last().name, 'foo')
     self.assertEqual(Entity.objects.last().note, 'bar')
     self.assertEqual(Entity.objects.last().created_user, self._test_user)
Пример #4
0
    def test_import_with_spoofing_parameter(self):
        user = User.objects.create(username='******')

        EntityResource.import_data_from_request(
            {
                'name': 'entity',
                'note': 'note',
                'created_user': user
            }, self._test_user)

        self.assertEqual(Entity.objects.count(), 0)
Пример #5
0
    def test_import_with_spoofing_parameter(self):
        user = User.objects.create(username="******")

        EntityResource.import_data_from_request(
            {
                "name": "entity",
                "note": "note",
                "created_user": user
            }, self._test_user)

        self.assertEqual(Entity.objects.count(), 0)
Пример #6
0
 def test_import_with_new_object(self):
     EntityResource.import_data_from_request(
         {
             "name": "foo",
             "note": "bar",
             "created_user": self._test_user,
         },
         self._test_user,
     )
     self.assertEqual(Entity.objects.count(), 1)
     self.assertEqual(Entity.objects.last().name, "foo")
     self.assertEqual(Entity.objects.last().note, "bar")
     self.assertEqual(Entity.objects.last().created_user, self._test_user)
Пример #7
0
    def test_import_with_invalid_parameter(self):
        with self.assertRaises(RuntimeError):
            EntityResource.import_data_from_request(
                {
                    "name": "hoge",
                    "note": "fuga",
                    "invalid_key": "invalid_value",
                    "created_user": self._test_user.username,
                },
                self._test_user,
            )

        self.assertEqual(Entity.objects.count(), 0)
Пример #8
0
    def test_import_without_permission_parameter(self):
        user = User.objects.create(username='******')

        entity = Entity(name='origin_name', created_user=user, is_public=False)
        entity.save()

        EntityResource.import_data_from_request(
            {
                'id': entity.id,
                'name': 'changed_name',
                'note': 'changed_note',
                'created_user': entity.created_user.username
            }, self._test_user)

        self.assertEqual(Entity.objects.count(), 1)
        self.assertEqual(Entity.objects.last().name, 'origin_name')
Пример #9
0
    def test_import_with_updating_object(self):
        entity = Entity(name='test01',
                        note='note1',
                        created_user=self._test_user)
        entity.save()

        EntityResource.import_data_from_request(
            {
                'id': entity.id,
                'name': 'changed_name',
                'note': 'changed_note',
                'created_user': entity.created_user.username
            }, self._test_user)

        self.assertEqual(Entity.objects.count(), 1)
        self.assertEqual(Entity.objects.last().name, 'changed_name')
        self.assertEqual(Entity.objects.last().note, 'changed_note')
        self.assertEqual(Entity.objects.last().created_user, self._test_user)
Пример #10
0
    def test_import_without_permission_parameter(self):
        user = User.objects.create(username="******")
        entity = Entity.objects.create(name="origin_name",
                                       created_user=user,
                                       is_public=False)
        entity.save()

        EntityResource.import_data_from_request(
            {
                "id": entity.id,
                "name": "changed_name",
                "note": "changed_note",
                "created_user": entity.created_user.username,
            },
            self._test_user,
        )

        self.assertEqual(Entity.objects.count(), 1)
        self.assertEqual(Entity.objects.last().name, "origin_name")
Пример #11
0
    def test_import_with_updating_object(self):
        entity = Entity(name="test01",
                        note="note1",
                        created_user=self._test_user)
        entity.save()

        EntityResource.import_data_from_request(
            {
                "id": entity.id,
                "name": "changed_name",
                "note": "changed_note",
                "created_user": entity.created_user.username,
            },
            self._test_user,
        )

        self.assertEqual(Entity.objects.count(), 1)
        self.assertEqual(Entity.objects.last().name, "changed_name")
        self.assertEqual(Entity.objects.last().note, "changed_note")
        self.assertEqual(Entity.objects.last().created_user, self._test_user)