From c3179e71dcf68f4ac3790f75e0723482f992453e Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 9 Oct 2022 14:45:36 +0700 Subject: [PATCH] more test --- src/page-file.rkt | 58 +++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/page-file.rkt b/src/page-file.rkt index 76134e4..4905c76 100644 --- a/src/page-file.rkt +++ b/src/page-file.rkt @@ -22,10 +22,10 @@ (provide page-file) -;(module+ test -; (require rackunit) -; (define category-json-data -; '#hasheq((batchcomplete . #t) (continue . #hasheq((cmcontinue . "page|4150504c45|41473") (continue . "-||"))) (query . #hasheq((categorymembers . (#hasheq((ns . 0) (pageid . 25049) (title . "Item (entity)")) #hasheq((ns . 0) (pageid . 128911) (title . "3D")) #hasheq((ns . 0) (pageid . 124018) (title . "A Very Fine Item")) #hasheq((ns . 0) (pageid . 142208) (title . "Amethyst Shard")) #hasheq((ns . 0) (pageid . 121612) (title . "Ankle Monitor"))))))))) +(module+ test + (require rackunit) + (define test-media-detail + '#hasheq((fileTitle . "Example file") (videoEmbedCode . "") (imageUrl . "https://static.wikia.nocookie.net/examplefile") (rawImageUrl . "https://static.wikia.nocookie.net/examplefile") (userName . "blankie") (isPostedIn . #t) (smallerArticleList . (list #hasheq((title . "Example_article") (titleText . "Example article")))) (articleListIsSmaller . 0) (exists . #t) (imageDescription . #f)))) (define (url-content-type url) (log-outgoing url) @@ -41,23 +41,6 @@ `(audio (@ (src ,maybe-proxied-url) (controls)))] [(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,maybe-proxied-url) (controls)))] [else `""])) -(module+ test - (require rackunit) - (parameterize ([(config-parameter 'strict_proxy) "true"]) - (check-equal? (get-media-html "https://static.wikia.nocookie.net/a" "image/jpeg") - `(img (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fa")))) - (check-equal? (get-media-html "https://static.wikia.nocookie.net/b" "audio/mp3") - `(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fb") - (controls))))) - (parameterize ([(config-parameter 'strict_proxy) "no"]) - (check-equal? (get-media-html "https://static.wikia.nocookie.net/c" "application/ogg") - `(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fc") - (controls)))) - (check-equal? (get-media-html "https://static.wikia.nocookie.net/d" "video/mp4") - `(video (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fd") - (controls))))) - (check-equal? (get-media-html "https://example.com" "who knows") `"") - (check-equal? (get-media-html "https://example.com" #f) `"")) (define (generate-results-page #:source-url source-url #:wikiname wikiname @@ -145,11 +128,28 @@ (response/output #:code 200 #:headers (list referrer-policy) (λ (out) (write-html body out))))))) -;(module+ test -; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor") -; (generate-results-page -; #:source-url "" -; #:wikiname "test" -; #:title "Category:Items" -; #:members-data category-json-data -; #:page '(div "page text")))))) +(module+ test + (parameterize ([(config-parameter 'strict_proxy) "true"]) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/a" "image/jpeg") + `(img (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fa")))) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/b" "audio/mp3") + `(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fb") + (controls))))) + (parameterize ([(config-parameter 'strict_proxy) "no"]) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/c" "application/ogg") + `(audio (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fc") + (controls)))) + (check-equal? (get-media-html "https://static.wikia.nocookie.net/d" "video/mp4") + `(video (@ (src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fd") + (controls))))) + (check-equal? (get-media-html "https://example.com" "who knows") `"") + (check-equal? (get-media-html "https://example.com" #f) `"")) +(module+ test + (parameterize ([(config-parameter 'strict_proxy) "true"]) + (check-not-false ((query-selector (attribute-selector 'src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fexamplefile") + (generate-results-page + #:source-url "" + #:wikiname "test" + #:title "File:Example file" + #:media-detail test-media-detail + #:image-content-type "image/jpeg"))))))