"""Test for serializer's delete_resource."""

from sqlalchemy_jsonapi import errors

from sqlalchemy_jsonapi.unittests.utils import testcases
from sqlalchemy_jsonapi.unittests import models


class DeleteResource(testcases.SqlalchemyJsonapiTestCase):
    """Tests for serializer.delete_resource."""

    def test_delete_resource_successs_response(self):
        """Delete a resource successfully returns 204."""
        user = models.User(
            first='Sally', last='Smith',
            username='SallySmith1', password='password')
        self.session.add(user)
        self.session.commit()

        response = models.serializer.delete_resource(
            self.session, {}, 'users', user.id)

        expected = {
            'meta': {
                'sqlalchemy_jsonapi_version': '4.0.9'
            },
            'jsonapi': {
                'version': '1.0'
            }
        }
        actual = response.data
        self.assertEqual(expected, actual)
        self.assertEqual(204, response.status_code)

    def test_delete_nonexistant_resource(self):
        """Delete notexistant resource returns 404.

        A ResourceTypeNotFoundError is raised.
        """
        with self.assertRaises(errors.ResourceTypeNotFoundError) as error:
            models.serializer.delete_resource(
                self.session, {}, 'non-existant', 1)

        self.assertEqual(error.exception.status_code, 404)

@@ -1412,8 +1412,1042 @@
 e, 404)%0A
+%0A    def test_delete_resource_cascade_with_one_many_relationship(self):%0A        %22%22%22Delete a resource with a cascade and one-to-many relationship.%0A%0A        Ensure all referencing models are removed.%0A        %22%22%22%0A        user = models.User(%0A            first='Sally', last='Smith',%0A            password='password', username='SallySmith1')%0A        self.session.add(user)%0A        blog_post = models.Post(%0A            title='This Is A Title', content='This is the content',%0A            author_id=user.id, author=user)%0A        self.session.add(blog_post)%0A        comment = models.Comment(%0A            content='This is comment 1', author_id=user.id,%0A            post_id=blog_post.id, author=user, post=blog_post)%0A        self.session.add(comment)%0A        self.session.commit()%0A%0A        models.serializer.delete_resource(self.session, %7B%7D, 'users', 1)%0A%0A        post = self.session.query(models.Post).get(1)%0A        comment = self.session.query(models.Comment).get(1)%0A        self.assertEqual(post, None)%0A        self.assertEqual(comment, None)%0A

add test for checking cascade