forked from cadence/breezewiki
		
	Fix tests by providing a fake req
This commit is contained in:
		
							parent
							
								
									9afccbb9cd
								
							
						
					
					
						commit
						50a3bc819a
					
				
					 5 changed files with 24 additions and 7 deletions
				
			
		| 
						 | 
					@ -1,6 +1,7 @@
 | 
				
			||||||
#lang racket/base
 | 
					#lang racket/base
 | 
				
			||||||
(require racket/file
 | 
					(require racket/file
 | 
				
			||||||
         racket/list
 | 
					         racket/list
 | 
				
			||||||
 | 
					         racket/runtime-path
 | 
				
			||||||
         racket/string
 | 
					         racket/string
 | 
				
			||||||
         json
 | 
					         json
 | 
				
			||||||
         (prefix-in easy: net/http-easy)
 | 
					         (prefix-in easy: net/http-easy)
 | 
				
			||||||
| 
						 | 
					@ -29,17 +30,19 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(module+ test
 | 
					(module+ test
 | 
				
			||||||
  (require rackunit
 | 
					  (require rackunit
 | 
				
			||||||
           html-writing))
 | 
					           html-writing
 | 
				
			||||||
 | 
					           "test-utils.rkt"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define always-headers
 | 
					(define always-headers
 | 
				
			||||||
  (list (header #"Referrer-Policy" #"same-origin") ; header to not send referers to fandom
 | 
					  (list (header #"Referrer-Policy" #"same-origin") ; header to not send referers to fandom
 | 
				
			||||||
        (header #"Link" (string->bytes/latin-1 link-header))))
 | 
					        (header #"Link" (string->bytes/latin-1 link-header))))
 | 
				
			||||||
(define timeouts (easy:make-timeout-config #:lease 5 #:connect 5))
 | 
					(define timeouts (easy:make-timeout-config #:lease 5 #:connect 5))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define-runtime-path path-static "../static")
 | 
				
			||||||
(define theme-icons
 | 
					(define theme-icons
 | 
				
			||||||
  (for/hasheq ([theme '(default light dark)])
 | 
					  (for/hasheq ([theme '(default light dark)])
 | 
				
			||||||
    (values theme
 | 
					    (values theme
 | 
				
			||||||
            (html->xexp (file->string (format "static/icon-theme-~a.svg" theme) #:mode 'binary)))))
 | 
					            (html->xexp (file->string (build-path path-static (format "icon-theme-~a.svg" theme)) #:mode 'binary)))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define (application-footer source-url #:license [license-in #f])
 | 
					(define (application-footer source-url #:license [license-in #f])
 | 
				
			||||||
  (define license (or license-in license-default))
 | 
					  (define license (or license-in license-default))
 | 
				
			||||||
| 
						 | 
					@ -190,6 +193,7 @@
 | 
				
			||||||
    (parameterize ([(config-parameter 'strict_proxy) "true"])
 | 
					    (parameterize ([(config-parameter 'strict_proxy) "true"])
 | 
				
			||||||
      (generate-wiki-page
 | 
					      (generate-wiki-page
 | 
				
			||||||
       '(template)
 | 
					       '(template)
 | 
				
			||||||
 | 
					       #:req test-req
 | 
				
			||||||
       #:source-url ""
 | 
					       #:source-url ""
 | 
				
			||||||
       #:title "test"
 | 
					       #:title "test"
 | 
				
			||||||
       #:wikiname "test")))
 | 
					       #:wikiname "test")))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,8 @@
 | 
				
			||||||
 page-category)
 | 
					 page-category)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(module+ test
 | 
					(module+ test
 | 
				
			||||||
  (require rackunit)
 | 
					  (require rackunit
 | 
				
			||||||
 | 
					           "test-utils.rkt")
 | 
				
			||||||
  (define category-json-data
 | 
					  (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")))))))))
 | 
					    '#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")))))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,6 +120,7 @@
 | 
				
			||||||
(module+ test
 | 
					(module+ test
 | 
				
			||||||
  (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")
 | 
					  (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")
 | 
				
			||||||
                                    (generate-results-page
 | 
					                                    (generate-results-page
 | 
				
			||||||
 | 
					                                     #:req test-req
 | 
				
			||||||
                                     #:source-url ""
 | 
					                                     #:source-url ""
 | 
				
			||||||
                                     #:wikiname "test"
 | 
					                                     #:wikiname "test"
 | 
				
			||||||
                                     #:title "Category:Items"
 | 
					                                     #:title "Category:Items"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,8 @@
 | 
				
			||||||
(provide page-file)
 | 
					(provide page-file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(module+ test
 | 
					(module+ test
 | 
				
			||||||
  (require rackunit)
 | 
					  (require rackunit
 | 
				
			||||||
 | 
					           "test-utils.rkt")
 | 
				
			||||||
  (define test-media-detail
 | 
					  (define test-media-detail
 | 
				
			||||||
    '#hasheq((fileTitle . "Example file")
 | 
					    '#hasheq((fileTitle . "Example file")
 | 
				
			||||||
             (videoEmbedCode . "")
 | 
					             (videoEmbedCode . "")
 | 
				
			||||||
| 
						 | 
					@ -162,7 +163,8 @@
 | 
				
			||||||
    (check-not-false
 | 
					    (check-not-false
 | 
				
			||||||
     ((query-selector
 | 
					     ((query-selector
 | 
				
			||||||
       (attribute-selector 'src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fexamplefile")
 | 
					       (attribute-selector 'src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fexamplefile")
 | 
				
			||||||
       (generate-results-page #:source-url ""
 | 
					       (generate-results-page #:req test-req
 | 
				
			||||||
 | 
					                              #:source-url ""
 | 
				
			||||||
                              #:wikiname "test"
 | 
					                              #:wikiname "test"
 | 
				
			||||||
                              #:title "File:Example file"
 | 
					                              #:title "File:Example file"
 | 
				
			||||||
                              #:media-detail test-media-detail
 | 
					                              #:media-detail test-media-detail
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,8 @@
 | 
				
			||||||
 page-search)
 | 
					 page-search)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(module+ test
 | 
					(module+ test
 | 
				
			||||||
  (require rackunit)
 | 
					  (require rackunit
 | 
				
			||||||
 | 
					           "test-utils.rkt")
 | 
				
			||||||
  (define search-json-data
 | 
					  (define search-json-data
 | 
				
			||||||
    '#hasheq((batchcomplete . #t) (query . #hasheq((search . (#hasheq((ns . 0) (pageid . 219) (size . 1482) (snippet . "") (timestamp . "2022-08-21T08:54:23Z") (title . "Gacha Capsule") (wordcount . 214)) #hasheq((ns . 0) (pageid . 201) (size . 1198) (snippet . "") (timestamp . "2022-07-11T17:52:47Z") (title . "Badges") (wordcount . 181)))))))))
 | 
					    '#hasheq((batchcomplete . #t) (query . #hasheq((search . (#hasheq((ns . 0) (pageid . 219) (size . 1482) (snippet . "") (timestamp . "2022-08-21T08:54:23Z") (title . "Gacha Capsule") (wordcount . 214)) #hasheq((ns . 0) (pageid . 201) (size . 1198) (snippet . "") (timestamp . "2022-07-11T17:52:47Z") (title . "Badges") (wordcount . 181)))))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,4 +88,4 @@
 | 
				
			||||||
       (write-html body out))))))
 | 
					       (write-html body out))))))
 | 
				
			||||||
(module+ test
 | 
					(module+ test
 | 
				
			||||||
  (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Gacha_Capsule")
 | 
					  (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Gacha_Capsule")
 | 
				
			||||||
                                    (generate-results-page "" "test" "Gacha" search-json-data)))))
 | 
					                                    (generate-results-page test-req "" "test" "Gacha" search-json-data)))))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										8
									
								
								src/test-utils.rkt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/test-utils.rkt
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					#lang racket/base
 | 
				
			||||||
 | 
					(require web-server/http/request-structs
 | 
				
			||||||
 | 
					         net/url-structs
 | 
				
			||||||
 | 
					         (only-in racket/promise delay))
 | 
				
			||||||
 | 
					(provide
 | 
				
			||||||
 | 
					 test-req)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(define test-req (request #"GET" (url "https" #f "breezewiki.com" #f #t (list (path/param "" '())) '() #f) '() (delay '()) #f "127.0.0.1" 0 "127.0.0.1"))
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue