Пример #1
0
    def test_save_patch(self, base_mock):
        base_mock.configure_mock(id=1, slug='test', _original_values={'slug': 'test-old'})
        base_mock.WRITABLE_FIELDS = ('slug', )

        base_mock.api = MagicMock(**{'patch.return_value': {'id': 1, 'slug': 'test'}})
        BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock._update_fields.call_count, 1)
Пример #2
0
    def test_save_patch(self, base_mock):
        base_mock.configure_mock(id=1, slug='test', _original_values={'slug': 'test-old'})
        base_mock.WRITABLE_FIELDS = ('slug', )

        base_mock.api = MagicMock(**{'patch.return_value': {'id': 1, 'slug': 'test'}})
        BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock._update_fields.call_count, 1)
Пример #3
0
    def test_save_post_update_protected(self, base_mock):
        base_mock.configure_mock(id=None,
                                 slug="test",
                                 update_protected_dict=None,
                                 _original_values={})
        base_mock.READ_ONLY_FIELDS = ("id", )
        base_mock.UPDATE_PROTECTED_FIELDS = ("update_protected_dict", )
        base_mock.WRITABLE_FIELDS = ("slug", )
        base_mock.fields.return_value = ("id", "slug", "update_protected_dict")

        base_mock.update_protected_dict = {"create": "create-allowed"}
        base_mock.api = MagicMock(
            **{
                "post.return_value": {
                    "id": 1,
                    "slug": "test",
                    "update_protected_dict": {
                        "create": "create-allowed"
                    },
                }
            })

        BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock.update_protected_dict,
                         {"create": "create-allowed"})
Пример #4
0
    def test_save_post_update_protected(self, base_mock):
        base_mock.configure_mock(id=None,
                                 slug='test',
                                 update_protected_dict=None,
                                 _original_values={})
        base_mock.READ_ONLY_FIELDS = ('id', )
        base_mock.UPDATE_PROTECTED_FIELDS = ('update_protected_dict', )
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'update_protected_dict')

        base_mock.update_protected_dict = {'create': 'create-allowed'}
        base_mock.api = MagicMock(
            **{
                'post.return_value': {
                    'id': 1,
                    'slug': 'test',
                    'update_protected_dict': {
                        'create': 'create-allowed'
                    }
                }
            })

        BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock.update_protected_dict,
                         {'create': 'create-allowed'})
Пример #5
0
    def test_save_post_client_error(self, base_mock):
        base_mock.configure_mock(id=None, slug='test')
        base_mock.api = MagicMock(**{'post.side_effect': slumber.exceptions.HttpClientError(
            message='', content='', response='')})

        with self.assertRaises(slumber.exceptions.HttpClientError):
            BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock._update_fields.call_count, 0)
Пример #6
0
    def test_save_post_client_error(self, base_mock):
        base_mock.configure_mock(id=None, slug='test')
        base_mock.api = MagicMock(**{'post.side_effect': slumber.exceptions.HttpClientError(
            message='', content='', response='')})

        with self.assertRaises(slumber.exceptions.HttpClientError):
            BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock._update_fields.call_count, 0)
Пример #7
0
 def test_save_post(self, base_mock):
     base_mock.configure_mock(id=None, slug='test')
     base_mock.WRITABLE_FIELDS = ('slug', )
     base_mock.api = MagicMock(
         **{'post.return_value': {
             'id': 1,
             'slug': 'test'
         }})
     BaseResolweResource.save(base_mock)
     self.assertEqual(base_mock._update_fields.call_count, 1)
Пример #8
0
 def test_save_post(self, base_mock):
     base_mock.configure_mock(id=None, slug="test")
     base_mock.WRITABLE_FIELDS = ("slug", )
     base_mock.api = MagicMock(
         **{"post.return_value": {
             "id": 1,
             "slug": "test"
         }})
     BaseResolweResource.save(base_mock)
     self.assertEqual(base_mock._update_fields.call_count, 1)
Пример #9
0
    def test_save_post_read_only(self, base_mock):
        base_mock.configure_mock(id=None, slug='test', read_only_dict=None, _original_values={})
        base_mock.READ_ONLY_FIELDS = ('id', 'read_only_dict')
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'read_only_dict')

        base_mock.read_only_dict = {'change': 'change-not-allowed'}

        message = 'Not allowed to change read only fields read_only_dict'
        with six.assertRaisesRegex(self, ValueError, message):
            BaseResolweResource.save(base_mock)
Пример #10
0
    def test_save_post_read_only(self, base_mock):
        base_mock.configure_mock(id=None, slug='test', read_only_dict=None, _original_values={})
        base_mock.READ_ONLY_FIELDS = ('id', 'read_only_dict')
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'read_only_dict')

        base_mock.read_only_dict = {'change': 'change-not-allowed'}

        message = 'Not allowed to change read only fields read_only_dict'
        with six.assertRaisesRegex(self, ValueError, message):
            BaseResolweResource.save(base_mock)
Пример #11
0
    def test_save_patch(self, base_mock):
        base_mock.configure_mock(id=1,
                                 slug="test",
                                 _original_values={"slug": "test-old"})
        base_mock.WRITABLE_FIELDS = ("slug", )

        base_mock.api = MagicMock(
            **{"patch.return_value": {
                "id": 1,
                "slug": "test"
            }})
        BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock._update_fields.call_count, 1)
Пример #12
0
    def test_save_post_update_protected(self, base_mock):
        base_mock.configure_mock(id=None, slug='test', update_protected_dict=None,
                                 _original_values={})
        base_mock.READ_ONLY_FIELDS = ('id', )
        base_mock.UPDATE_PROTECTED_FIELDS = ('update_protected_dict', )
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'update_protected_dict')

        base_mock.update_protected_dict = {'create': 'create-allowed'}
        base_mock.api = MagicMock(**{'post.return_value': {
            'id': 1, 'slug': 'test', 'update_protected_dict': {'create': 'create-allowed'}}})

        BaseResolweResource.save(base_mock)
        self.assertEqual(base_mock.update_protected_dict, {'create': 'create-allowed'})
Пример #13
0
    def test_save_post_read_only(self, base_mock):
        base_mock.configure_mock(id=None,
                                 slug="test",
                                 read_only_dict=None,
                                 _original_values={})
        base_mock.READ_ONLY_FIELDS = ("id", "read_only_dict")
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ("slug", )
        base_mock.fields.return_value = ("id", "slug", "read_only_dict")

        base_mock.read_only_dict = {"change": "change-not-allowed"}

        message = "Not allowed to change read only fields read_only_dict"
        with self.assertRaisesRegex(ValueError, message):
            BaseResolweResource.save(base_mock)
Пример #14
0
    def test_save_patch_read_only(self, base_mock):
        base_mock.READ_ONLY_FIELDS = ("id", "read_only_dict")
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ("slug", )
        base_mock.fields.return_value = ("id", "slug", "read_only_dict")
        read_only_dict = {}
        BaseResolweResource._update_fields(base_mock, {
            "id": 1,
            "slug": "test",
            "read_only_dict": read_only_dict
        })
        base_mock.read_only_dict["change"] = "change-not-allowed"

        message = "Not allowed to change read only fields read_only_dict"
        with self.assertRaisesRegex(ValueError, message):
            BaseResolweResource.save(base_mock)
Пример #15
0
    def test_save_patch_read_only(self, base_mock):
        base_mock.READ_ONLY_FIELDS = ('id', 'read_only_dict')
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'read_only_dict')
        read_only_dict = {}
        BaseResolweResource._update_fields(base_mock, {
            'id': 1,
            'slug': 'test',
            'read_only_dict': read_only_dict
        })
        base_mock.read_only_dict['change'] = 'change-not-allowed'

        message = 'Not allowed to change read only fields read_only_dict'
        with self.assertRaisesRegex(ValueError, message):
            BaseResolweResource.save(base_mock)
Пример #16
0
    def test_save_patch_read_only(self, base_mock):
        base_mock.READ_ONLY_FIELDS = ('id', 'read_only_dict')
        base_mock.UPDATE_PROTECTED_FIELDS = ()
        base_mock.WRITABLE_FIELDS = ('slug', )
        base_mock.fields.return_value = ('id', 'slug', 'read_only_dict')
        read_only_dict = {}
        BaseResolweResource._update_fields(
            base_mock,
            {
                'id': 1,
                'slug': 'test',
                'read_only_dict': read_only_dict
            }
        )
        base_mock.read_only_dict['change'] = 'change-not-allowed'

        message = 'Not allowed to change read only fields read_only_dict'
        with six.assertRaisesRegex(self, ValueError, message):
            BaseResolweResource.save(base_mock)
Пример #17
0
 def test_save_post(self, base_mock):
     base_mock.configure_mock(id=None, slug='test')
     base_mock.WRITABLE_FIELDS = ('slug', )
     base_mock.api = MagicMock(**{'post.return_value': {'id': 1, 'slug': 'test'}})
     BaseResolweResource.save(base_mock)
     self.assertEqual(base_mock._update_fields.call_count, 1)