def test_site_routeRequest_HandlesDirectoryListing(): staticDir = Site(RootWithStaticDirectory()) request = TestRequest([], "/files/") action = staticDir.routeRequest(request) response = action.render(request) assert isinstance(action, DirectoryLister)
def test_site_routeRequest_CorrectlyRoutesToAChildOfstaticFileResource(): staticDir = Site(RootWithStaticDirectory()) request = TestRequest([], "/files/a.txt") action = staticDir.routeRequest(request) response = action.render(request) assert not isinstance(action, DirectoryLister) assert response == NOT_DONE_YET assert request.written[0].count("a") > 0
def test_site_routeRequest_CorrectlyHandlesSubDirectories(): staticDir = Site(RootWithStaticDirectory()) request = TestRequest([], "/files/subdir/b.txt") action = staticDir.routeRequest(request) response = action.render(request) assert not isinstance(action, DirectoryLister) assert response == NOT_DONE_YET assert request.written[0].count("b") > 0
def test_filtersAreCalled(): root = Root() site = Site(root) request = TestRequest([],"/anAction") action = site.routeRequest(request) assert isinstance(action, OneTimeResource) assert action.func == root.anAction response = action.render(request) assert response == "anActionWasCalled" assert getattr(root, "preFilterWasCalled", False) == True assert getattr(root, "postFilterWasCalled", False) == True
def test_site_routRequest_HandlesIndexAsResource(): staticSite = Site(RootWithStaticIndex()) request = TestRequest([], "/") action = staticSite.routeRequest(request) response = action.render(request) assert response == NOT_DONE_YET with open(relPath("LICENSE.txt")) as testFile: expected = testFile.read() assert len(request.written) == 1, "Expected written log to be equal to one" actualSize = len(request.written[0]) expectedSize = len(expected) actual = request.written[0] assert expectedSize == actualSize, "Expected size doesn't match actual" assert expected == actual, "Expecting actual written body to equal expected body"