diff --git a/src/page-file.rkt b/src/page-file.rkt index 4905c76..7e04cd2 100644 --- a/src/page-file.rkt +++ b/src/page-file.rkt @@ -22,10 +22,10 @@ (provide page-file) -(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)))) +;(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"))))))))) (define (url-content-type url) (log-outgoing url) @@ -41,6 +41,16 @@ `(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 @@ -128,28 +138,11 @@ (response/output #:code 200 #:headers (list referrer-policy) (λ (out) (write-html body out))))))) -(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")))))) +;(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"))))))