From: David ‘Bombe’ Roden Date: Wed, 24 May 2017 19:25:46 +0000 (+0200) Subject: Use verifyNoRedirect instead of calling the request handler directly X-Git-Tag: 0.9.7^2~199 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4f2dd6da42af253e7545d7cba5d9e5cb2895eb34;p=Sone.git Use verifyNoRedirect instead of calling the request handler directly --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index 7146f2e..a4df75d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -54,38 +54,40 @@ class OptionsPageTest : WebPageTest() { @Test fun `get request stores all preferences in the template context`() { - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["auto-follow"], equalTo(true)) - assertThat(templateContext["show-notification-new-sones"], equalTo(true)) - assertThat(templateContext["show-notification-new-posts"], equalTo(true)) - assertThat(templateContext["show-notification-new-replies"], equalTo(true)) - assertThat(templateContext["enable-sone-insert-notifications"], equalTo(true)) - assertThat(templateContext["load-linked-images"], equalTo("FOLLOWED")) - assertThat(templateContext["show-custom-avatars"], equalTo("FOLLOWED")) - assertThat(templateContext["insertion-delay"], equalTo(1)) - assertThat(templateContext["characters-per-post"], equalTo(50)) - assertThat(templateContext["fcp-full-access-required"], equalTo(1)) - assertThat(templateContext["images-per-page"], equalTo(4)) - assertThat(templateContext["fcp-interface-active"], equalTo(true)) - assertThat(templateContext["require-full-access"], equalTo(true)) - assertThat(templateContext["negative-trust"], equalTo(7)) - assertThat(templateContext["positive-trust"], equalTo(8)) - assertThat(templateContext["post-cut-off-length"], equalTo(51)) - assertThat(templateContext["posts-per-page"], equalTo(10)) - assertThat(templateContext["trust-comment"], equalTo("11")) + verifyNoRedirect { + assertThat(templateContext["auto-follow"], equalTo(true)) + assertThat(templateContext["show-notification-new-sones"], equalTo(true)) + assertThat(templateContext["show-notification-new-posts"], equalTo(true)) + assertThat(templateContext["show-notification-new-replies"], equalTo(true)) + assertThat(templateContext["enable-sone-insert-notifications"], equalTo(true)) + assertThat(templateContext["load-linked-images"], equalTo("FOLLOWED")) + assertThat(templateContext["show-custom-avatars"], equalTo("FOLLOWED")) + assertThat(templateContext["insertion-delay"], equalTo(1)) + assertThat(templateContext["characters-per-post"], equalTo(50)) + assertThat(templateContext["fcp-full-access-required"], equalTo(1)) + assertThat(templateContext["images-per-page"], equalTo(4)) + assertThat(templateContext["fcp-interface-active"], equalTo(true)) + assertThat(templateContext["require-full-access"], equalTo(true)) + assertThat(templateContext["negative-trust"], equalTo(7)) + assertThat(templateContext["positive-trust"], equalTo(8)) + assertThat(templateContext["post-cut-off-length"], equalTo(51)) + assertThat(templateContext["posts-per-page"], equalTo(10)) + assertThat(templateContext["trust-comment"], equalTo("11")) + } } @Test fun `get request without sone does not store sone-specific preferences in the template context`() { unsetCurrentSone() - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["auto-follow"], nullValue()) - assertThat(templateContext["show-notification-new-sones"], nullValue()) - assertThat(templateContext["show-notification-new-posts"], nullValue()) - assertThat(templateContext["show-notification-new-replies"], nullValue()) - assertThat(templateContext["enable-sone-insert-notifications"], nullValue()) - assertThat(templateContext["load-linked-images"], nullValue()) - assertThat(templateContext["show-custom-avatars"], nullValue()) + verifyNoRedirect { + assertThat(templateContext["auto-follow"], nullValue()) + assertThat(templateContext["show-notification-new-sones"], nullValue()) + assertThat(templateContext["show-notification-new-posts"], nullValue()) + assertThat(templateContext["show-notification-new-replies"], nullValue()) + assertThat(templateContext["enable-sone-insert-notifications"], nullValue()) + assertThat(templateContext["load-linked-images"], nullValue()) + assertThat(templateContext["show-custom-avatars"], nullValue()) + } } private fun verifyThatOptionCanBeSet(option: String, setValue: Any?, expectedValue: T, getter: () -> T) { @@ -137,8 +139,9 @@ class OptionsPageTest : WebPageTest() { unsetCurrentSone() setMethod(POST) addHttpRequestPart(name, value) - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["fieldErrors"] as Iterable<*>, hasItem(name)) + verifyNoRedirect { + assertThat(templateContext["fieldErrors"] as Iterable<*>, hasItem(name)) + } } private fun verifyThatPreferencesCanBeSet(name: String, setValue: String?, expectedValue: T, getter: () -> T) { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt index 547c580..303a23c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt @@ -30,8 +30,9 @@ class RescuePageTest : WebPageTest() { @Test fun `get request sets rescuer in template context`() { - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["soneRescuer"], equalTo(soneRescuer)) + verifyNoRedirect { + assertThat(templateContext["soneRescuer"], equalTo(soneRescuer)) + } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt index 8790283..106b350 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt @@ -140,8 +140,9 @@ class SearchPageTest : WebPageTest() { addSone("sone-with-match", soneWithMatch) addSone("sone-without-match", soneWithoutMatch) addHttpRequestParameter("query", "word") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithMatch)) + } } @Test @@ -157,8 +158,9 @@ class SearchPageTest : WebPageTest() { addSone("sone-with-match", soneWithMatch) addSone("sone-without-match", soneWithoutMatch) addHttpRequestParameter("query", "word") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithMatch)) + } } private fun createSoneWithPost(idPostfix: String, text: String, recipient: Sone? = null, sender: Sone? = null) = @@ -171,8 +173,9 @@ class SearchPageTest : WebPageTest() { val postWithEarlyMatch = createSoneWithPost("with-early-match", "optional match") val postWithLaterMatch = createSoneWithPost("with-later-match", "match that is optional") addHttpRequestParameter("query", "optional ") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithEarlyMatch, postWithLaterMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithEarlyMatch, postWithLaterMatch)) + } } @Test @@ -180,8 +183,9 @@ class SearchPageTest : WebPageTest() { val postWithRequiredMatch = createSoneWithPost("with-required-match", "required match") createPost("without-required-match", "not a match") addHttpRequestParameter("query", "+required ") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithRequiredMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithRequiredMatch)) + } } @Test @@ -189,8 +193,9 @@ class SearchPageTest : WebPageTest() { createSoneWithPost("with-forbidden-match", "forbidden match") val postWithoutForbiddenMatch = createSoneWithPost("without-forbidden-match", "not a match") addHttpRequestParameter("query", "match -forbidden") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithoutForbiddenMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithoutForbiddenMatch)) + } } @Test @@ -198,8 +203,9 @@ class SearchPageTest : WebPageTest() { val postWithMatch = createSoneWithPost("with-match", "with + match") createSoneWithPost("without-match", "without match") addHttpRequestParameter("query", "+") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithMatch)) + } } @Test @@ -207,8 +213,9 @@ class SearchPageTest : WebPageTest() { val postWithMatch = createSoneWithPost("with-match", "with - match") createSoneWithPost("without-match", "without match") addHttpRequestParameter("query", "-") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithMatch)) + } } private fun createPost(id: String, text: String, recipient: Sone?) = mock().apply { @@ -235,8 +242,9 @@ class SearchPageTest : WebPageTest() { val postWithMatch = createSoneWithPost("with-match", "test", recipient) createSoneWithPost("without-match", "no match") addHttpRequestParameter("query", "recipient") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["postHits"], contains(postWithMatch)) + verifyNoRedirect { + assertThat(this["postHits"], contains(postWithMatch)) + } } @Test @@ -246,8 +254,9 @@ class SearchPageTest : WebPageTest() { createSoneWithPost("with-match", "test", sender = soneWithProfileField) createSoneWithPost("without-match", "no match") addHttpRequestParameter("query", "value") - page.handleRequest(freenetRequest, templateContext) - assertThat(this["soneHits"], contains(soneWithProfileField)) + verifyNoRedirect { + assertThat(this["soneHits"], contains(soneWithProfileField)) + } } @Suppress("UNCHECKED_CAST") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt index cc4b1dc..90a87c6 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt @@ -20,7 +20,7 @@ class TrustPageTest : WebPageTest() { @Test fun `get method does not redirect`() { - page.handleRequest(freenetRequest, templateContext) + verifyNoRedirect { } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt index c6c37a5..a637b40 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt @@ -20,7 +20,7 @@ class UnbookmarkPageTest : WebPageTest() { @Test fun `get request does not redirect`() { - page.handleRequest(freenetRequest, templateContext) + verifyNoRedirect { } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt index ad5216e..7e19a26 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt @@ -15,7 +15,7 @@ class UnfollowSonePageTest : WebPageTest() { @Test fun `get request does not redirect`() { - page.handleRequest(freenetRequest, templateContext) + verifyNoRedirect { } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt index f1050d2..3fa84fd 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt @@ -17,7 +17,7 @@ class UnlikePageTest : WebPageTest() { @Test fun `get request does not redirect`() { - page.handleRequest(freenetRequest, templateContext) + verifyNoRedirect { } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt index f83190f..5848c49 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt @@ -20,8 +20,9 @@ class UntrustPageTest : WebPageTest() { @Test fun `get request does not redirect`() { - page.handleRequest(freenetRequest, templateContext) - verify(core, never()).untrustSone(eq(currentSone), any()) + verifyNoRedirect { + verify(core, never()).untrustSone(eq(currentSone), any()) + } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt index 8bea89e..dfb9aca 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt @@ -31,9 +31,10 @@ class UploadImagePageTest : WebPageTest() { @Test fun `get request does not redirect or upload anything`() { - page.handleRequest(freenetRequest, templateContext) - verify(core, never()).createTemporaryImage(any(), any()) - verify(core, never()).createImage(any(), any(), any()) + verifyNoRedirect { + verify(core, never()).createTemporaryImage(any(), any()) + verify(core, never()).createImage(any(), any(), any()) + } } @Test @@ -67,9 +68,10 @@ class UploadImagePageTest : WebPageTest() { addHttpRequestPart("parent", "parent-id") addHttpRequestPart("title", "title") addUploadedFile("image", "image.png", "image/png", "no-image.png") - page.handleRequest(freenetRequest, templateContext) - verify(core, never()).createTemporaryImage(any(), any()) - assertThat(templateContext["messages"] as String?, equalTo("Page.UploadImage.Error.InvalidImage")) + verifyNoRedirect { + verify(core, never()).createTemporaryImage(any(), any()) + assertThat(templateContext["messages"] as String?, equalTo("Page.UploadImage.Error.InvalidImage")) + } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt index 1b20bfc..88ca34a 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt @@ -26,26 +26,29 @@ class ViewPostPageTest : WebPageTest() { @Test fun `get request without parameters stores null in template context`() { - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["post"], nullValue()) - assertThat(templateContext["raw"] as? Boolean, equalTo(false)) + verifyNoRedirect { + assertThat(templateContext["post"], nullValue()) + assertThat(templateContext["raw"] as? Boolean, equalTo(false)) + } } @Test fun `get request with invalid post id stores null in template context`() { addHttpRequestParameter("post", "invalid-post-id") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["post"], nullValue()) - assertThat(templateContext["raw"] as? Boolean, equalTo(false)) + verifyNoRedirect { + assertThat(templateContext["post"], nullValue()) + assertThat(templateContext["raw"] as? Boolean, equalTo(false)) + } } @Test fun `get request with valid post id stores post in template context`() { addPost("post-id", post) addHttpRequestParameter("post", "post-id") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["post"], equalTo(post)) - assertThat(templateContext["raw"] as? Boolean, equalTo(false)) + verifyNoRedirect { + assertThat(templateContext["post"], equalTo(post)) + assertThat(templateContext["raw"] as? Boolean, equalTo(false)) + } } @Test @@ -53,9 +56,10 @@ class ViewPostPageTest : WebPageTest() { addPost("post-id", post) addHttpRequestParameter("post", "post-id") addHttpRequestParameter("raw", "true") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["post"], equalTo(post)) - assertThat(templateContext["raw"] as? Boolean, equalTo(true)) + verifyNoRedirect { + assertThat(templateContext["post"], equalTo(post)) + assertThat(templateContext["raw"] as? Boolean, equalTo(true)) + } } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt index 335d839..7161684 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt @@ -42,17 +42,19 @@ class ViewSonePageTest : WebPageTest() { @Test fun `get request without sone parameter stores null in template context`() { - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["sone"], nullValue()) - assertThat(templateContext["soneId"], equalTo("")) + verifyNoRedirect { + assertThat(templateContext["sone"], nullValue()) + assertThat(templateContext["soneId"], equalTo("")) + } } @Test fun `get request with invalid sone parameter stores null in template context`() { addHttpRequestParameter("sone", "invalid-sone-id") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["sone"], nullValue()) - assertThat(templateContext["soneId"], equalTo("invalid-sone-id")) + verifyNoRedirect { + assertThat(templateContext["sone"], nullValue()) + assertThat(templateContext["soneId"], equalTo("invalid-sone-id")) + } } @Test @@ -61,9 +63,10 @@ class ViewSonePageTest : WebPageTest() { whenever(core.getDirectedPosts("sone-id")).thenReturn(emptyList()) addHttpRequestParameter("sone", "sone-id") addSone("sone-id", currentSone) - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["sone"], equalTo(currentSone)) - assertThat(templateContext["soneId"], equalTo("sone-id")) + verifyNoRedirect { + assertThat(templateContext["sone"], equalTo(currentSone)) + assertThat(templateContext["soneId"], equalTo("sone-id")) + } } private fun createPost(id: String, text: String, time: Long, sender: Sone? = null, recipient: Sone? = null) = mock().apply { @@ -81,8 +84,9 @@ class ViewSonePageTest : WebPageTest() { fun `request with valid sone stores posts and directed posts in template context`() { addSone("sone-id", currentSone) addHttpRequestParameter("sone", "sone-id") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["posts"] as Iterable, contains(directed2, post2)) + verifyNoRedirect { + assertThat(templateContext["posts"] as Iterable, contains(directed2, post2)) + } } @Test @@ -91,8 +95,9 @@ class ViewSonePageTest : WebPageTest() { addSone("sone-id", currentSone) addHttpRequestParameter("sone", "sone-id") addHttpRequestParameter("postPage", "1") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["posts"] as Iterable, contains(directed1, post1)) + verifyNoRedirect { + assertThat(templateContext["posts"] as Iterable, contains(directed1, post1)) + } } private fun createReply(text: String, time: Long, post: Post?) = mock().apply { @@ -120,8 +125,9 @@ class ViewSonePageTest : WebPageTest() { whenever(core.getReplies("post3")).thenReturn(listOf(reply6)) addSone("sone-id", currentSone) addHttpRequestParameter("sone", "sone-id") - page.handleRequest(freenetRequest, templateContext) - assertThat(templateContext["repliedPosts"] as Iterable, contains(foreignPost2, foreignPost1)) + verifyNoRedirect { + assertThat(templateContext["repliedPosts"] as Iterable, contains(foreignPost2, foreignPost1)) + } } @Test