def test_delete_loops_through_all_resources():
    FAKE_WEB_ROOT = 'test_web_root'
    FILE_PATH_1 = 'some_path_1'
    FILE_PATH_2 = 'some_path_2'
    FILE_CONTENT = 'some_content'

    FILE_RELATIVE_PATH_1 = os.path.join(FAKE_WEB_ROOT, FILE_PATH_1)
    FILE_RELATIVE_PATH_2 = os.path.join(FAKE_WEB_ROOT, FILE_PATH_2)

    settings = CustomSettings(WEB_ROOT=FAKE_WEB_ROOT)

    with remove_web_root_from_settings():
        instance = StaticGenerator(
            FILE_PATH_1, FILE_PATH_2,
            settings=settings,
        )

        with open(FILE_RELATIVE_PATH_1, 'w') as fd1, open(FILE_RELATIVE_PATH_2, 'w') as fd2:
            fd1.write(FILE_CONTENT)
            fd2.write(FILE_CONTENT)

        assert os.path.exists(FILE_RELATIVE_PATH_1), 'File {file_path} was not created'.format(file_path=FILE_RELATIVE_PATH_1)
        assert os.path.exists(FILE_RELATIVE_PATH_2), 'File {file_path} was not created'.format(file_path=FILE_RELATIVE_PATH_2)

        instance.delete()

        assert not os.path.exists(FILE_RELATIVE_PATH_1), 'File {file_path} still exists =P'.format(file_path=FILE_RELATIVE_PATH_1)
        assert not os.path.exists(FILE_RELATIVE_PATH_2), 'File {file_path} still exists =P'.format(file_path=FILE_RELATIVE_PATH_2)
예제 #2
0
def test_delete_loops_through_all_resources():
    FAKE_WEB_ROOT = 'test_web_root'
    FILE_PATH_1 = 'some_path_1'
    FILE_PATH_2 = 'some_path_2'
    FILE_CONTENT = 'some_content'

    FILE_RELATIVE_PATH_1 = os.path.join(FAKE_WEB_ROOT, FILE_PATH_1)
    FILE_RELATIVE_PATH_2 = os.path.join(FAKE_WEB_ROOT, FILE_PATH_2)

    settings = CustomSettings(WEB_ROOT=FAKE_WEB_ROOT)

    with remove_web_root_from_settings():
        instance = StaticGenerator(
            FILE_PATH_1,
            FILE_PATH_2,
            settings=settings,
        )

        with open(FILE_RELATIVE_PATH_1,
                  'w') as fd1, open(FILE_RELATIVE_PATH_2, 'w') as fd2:
            fd1.write(FILE_CONTENT)
            fd2.write(FILE_CONTENT)

        assert os.path.exists(
            FILE_RELATIVE_PATH_1), 'File {file_path} was not created'.format(
                file_path=FILE_RELATIVE_PATH_1)
        assert os.path.exists(
            FILE_RELATIVE_PATH_2), 'File {file_path} was not created'.format(
                file_path=FILE_RELATIVE_PATH_2)

        instance.delete()

        assert not os.path.exists(
            FILE_RELATIVE_PATH_1), 'File {file_path} still exists =P'.format(
                file_path=FILE_RELATIVE_PATH_1)
        assert not os.path.exists(
            FILE_RELATIVE_PATH_2), 'File {file_path} still exists =P'.format(
                file_path=FILE_RELATIVE_PATH_2)
def test_delete_loops_through_all_resources():
    mox = Mox()
    http_request, model_base, manager, model, queryset = get_mocks(mox)

    fs_mock = mox.CreateMockAnything()
    fs_mock.join('test_web_root',
                 'some_path').AndReturn("test_web_root/some_path")
    fs_mock.dirname("test_web_root/some_path").AndReturn("test_web_root")
    fs_mock.exists("test_web_root/some_path").AndReturn(True)
    fs_mock.remove("test_web_root/some_path")
    fs_mock.rmdir("test_web_root")

    fs_mock.join('test_web_root',
                 'some_path_2').AndReturn("test_web_root/some_path_2")
    fs_mock.dirname('test_web_root/some_path_2').AndReturn("test_web_root")
    fs_mock.exists("test_web_root/some_path_2").AndReturn(True)
    fs_mock.remove("test_web_root/some_path_2")
    fs_mock.rmdir("test_web_root")

    settings = CustomSettings(WEB_ROOT="test_web_root")

    mox.ReplayAll()

    instance = StaticGenerator("some_path",
                               "some_path_2",
                               http_request=http_request,
                               model_base=model_base,
                               manager=manager,
                               model=model,
                               queryset=queryset,
                               settings=settings,
                               fs=fs_mock)

    instance.delete()

    mox.VerifyAll()
def test_delete_loops_through_all_resources():
    mox = Mox()
    http_request, model_base, manager, model, queryset = get_mocks(mox)

    fs_mock = mox.CreateMockAnything()
    fs_mock.join("test_web_root", "some_path").AndReturn("test_web_root/some_path")
    fs_mock.dirname("test_web_root/some_path").AndReturn("test_web_root")
    fs_mock.exists("test_web_root/some_path").AndReturn(True)
    fs_mock.remove("test_web_root/some_path")
    fs_mock.rmdir("test_web_root")

    fs_mock.join("test_web_root", "some_path_2").AndReturn("test_web_root/some_path_2")
    fs_mock.dirname("test_web_root/some_path_2").AndReturn("test_web_root")
    fs_mock.exists("test_web_root/some_path_2").AndReturn(True)
    fs_mock.remove("test_web_root/some_path_2")
    fs_mock.rmdir("test_web_root")

    settings = CustomSettings(WEB_ROOT="test_web_root")

    mox.ReplayAll()

    instance = StaticGenerator(
        "some_path",
        "some_path_2",
        http_request=http_request,
        model_base=model_base,
        manager=manager,
        model=model,
        queryset=queryset,
        settings=settings,
        fs=fs_mock,
    )

    instance.delete()

    mox.VerifyAll()