def test_delete_from_path(): 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") settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() instance = StaticGenerator(http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock) instance.delete_from_path("some_path") mox.VerifyAll()
def test_delete_raises_when_unable_to_delete_file(): 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").AndRaise(ValueError()) settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() instance = StaticGenerator(http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock) try: instance.delete_from_path("some_path") except StaticGeneratorException, e: assert str(e) == 'Could not delete file: test_web_root/some_path' mox.VerifyAll() return
def test_delete_ignores_folder_delete_when_unable_to_delete_folder(): 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").AndRaise(OSError()) settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() instance = StaticGenerator(http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock) instance.delete_from_path("some_path") assert True, "Should work even when raising OSError"
def test_delete_raises_when_unable_to_delete_file(): mox = Mox() FAKE_WEB_ROOT = 'test_web_root' FILE_PATH = 'some_path' FILE_RELATIVE_PATH = os.path.join(FAKE_WEB_ROOT, FILE_PATH) settings = CustomSettings(WEB_ROOT=FAKE_WEB_ROOT) mox.StubOutWithMock(os.path, 'exists') mox.StubOutWithMock(os, 'remove') os.path.exists(FILE_RELATIVE_PATH).AndReturn(True) os.remove(FILE_RELATIVE_PATH).AndRaise(Exception()) mox.ReplayAll() with remove_web_root_from_settings(): instance = StaticGenerator(settings=settings, ) try: instance.delete_from_path(FILE_PATH) except StaticGeneratorException, e: assert str(e) == 'Could not delete file: {file_path}'.format( file_path=FILE_RELATIVE_PATH) mox.VerifyAll() return finally:
def test_delete_from_path(): 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") settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() instance = StaticGenerator( http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock, ) instance.delete_from_path("some_path") mox.VerifyAll()
def test_delete_ignores_folder_delete_when_unable_to_delete_folder(): 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").AndRaise(OSError()) settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() instance = StaticGenerator( http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock, ) instance.delete_from_path("some_path") assert True, "Should work even when raising OSError"
def test_delete_raises_when_unable_to_delete_file(): 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").AndRaise(ValueError()) settings = CustomSettings(WEB_ROOT="test_web_root") mox.ReplayAll() instance = StaticGenerator( http_request=http_request, model_base=model_base, manager=manager, model=model, queryset=queryset, settings=settings, fs=fs_mock, ) try: instance.delete_from_path("some_path") except StaticGeneratorException, e: assert str(e) == "Could not delete file: test_web_root/some_path" mox.VerifyAll() return
def test_delete_raises_when_unable_to_delete_file(): mox = Mox() FAKE_WEB_ROOT = 'test_web_root' FILE_PATH = 'some_path' FILE_RELATIVE_PATH = os.path.join(FAKE_WEB_ROOT, FILE_PATH) settings = CustomSettings(WEB_ROOT=FAKE_WEB_ROOT) mox.StubOutWithMock(os.path, 'exists') mox.StubOutWithMock(os, 'remove') os.path.exists(FILE_RELATIVE_PATH).AndReturn(True) os.remove(FILE_RELATIVE_PATH).AndRaise(Exception()) mox.ReplayAll() with remove_web_root_from_settings(): instance = StaticGenerator( settings=settings, ) try: instance.delete_from_path(FILE_PATH) except StaticGeneratorException, e: assert str(e) == 'Could not delete file: {file_path}'.format(file_path=FILE_RELATIVE_PATH) mox.VerifyAll() return finally:
def test_delete_from_path(): FAKE_WEB_ROOT = 'test_web_root' FILE_PATH = 'some_path' FILE_RELATIVE_PATH = os.path.join(FAKE_WEB_ROOT, FILE_PATH) settings = CustomSettings(WEB_ROOT=FAKE_WEB_ROOT) with remove_web_root_from_settings(): instance = StaticGenerator( settings=settings, ) assert os.path.exists(FILE_RELATIVE_PATH), 'File {file_path} already exists =P'.format(file_path=FILE_RELATIVE_PATH) instance.delete_from_path(FILE_PATH) assert not os.path.exists(FILE_RELATIVE_PATH), 'File {file_path} still exists'.format(file_path=FILE_RELATIVE_PATH)
def test_delete_from_path(): FAKE_WEB_ROOT = 'test_web_root' FILE_PATH = 'some_path' FILE_RELATIVE_PATH = os.path.join(FAKE_WEB_ROOT, FILE_PATH) settings = CustomSettings(WEB_ROOT=FAKE_WEB_ROOT) with remove_web_root_from_settings(): instance = StaticGenerator(settings=settings, ) assert os.path.exists( FILE_RELATIVE_PATH), 'File {file_path} already exists =P'.format( file_path=FILE_RELATIVE_PATH) instance.delete_from_path(FILE_PATH) assert not os.path.exists( FILE_RELATIVE_PATH), 'File {file_path} still exists'.format( file_path=FILE_RELATIVE_PATH)