def test_delete_files_kwargs_model(self, create_app, mock_blog_model):
        assert "my_video.mp4" in os.listdir("tests/test_path/blogs/1")
        m = mock_blog_model(
            name="hello",
            my_video__file_name="my_video.mp4",
            my_video__mime_type="video/mpeg",
            my_video__file_type="mp4",
        )

        db.session.add(m)
        db.session.commit()

        blog = m.get_blog()

        assert getattr(blog, "my_video__file_name") == "my_video.mp4"
        assert getattr(blog, "my_video__mime_type") == "video/mpeg"
        assert getattr(blog, "my_video__file_type") == "mp4"

        file_upload.delete_files(blog,
                                 db,
                                 files=["my_video"],
                                 clean_up="model")

        db.session.add(m)
        db.session.commit()
        result = m.get_blog()

        assert "my_video.mp4" in os.listdir("tests/test_path/blogs/1")
        assert getattr(result, "my_video__file_name") is None
        assert getattr(result, "my_video__mime_type") is None
        assert getattr(result, "my_video__file_type") is None
Пример #2
0
    def test_delete_with_parent_true(self, create_app, mock_blog_model):
        assert "my_video.mp4" in os.listdir("tests/test_path/blogs/1")
        m = mock_blog_model(
            name="hello",
            my_video__file_name="my_video.mp4",
            my_video__mime_type="video/mpeg",
            my_video__file_type="mp4",
        )

        db.session.add(m)
        db.session.commit()

        blog = m.get_blog()

        assert getattr(blog, "my_video__file_name") == "my_video.mp4"
        assert getattr(blog, "my_video__mime_type") == "video/mpeg"
        assert getattr(blog, "my_video__file_type") == "mp4"
        assert ["1"] == os.listdir("tests/test_path/blogs")
        assert blog.id == 1

        file_upload.delete_files(blog, db, parent=True, files=["my_video"])
        result = os.listdir("tests/test_path/blogs")

        assert [] == result
        assert getattr(blog, "my_video__file_name") is not "my_video.mp4"
        assert getattr(blog, "my_video__mime_type") is not "video/mpeg"
        assert getattr(blog, "my_video__file_type") is not "mp4"