-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
274 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{-# OPTIONS_GHC -F -pgmF htfpp #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- Base functions for integration tests | ||
module Integration.Base where | ||
|
||
import Control.Concurrent.MVar | ||
import Control.Monad | ||
import Control.Monad.State | ||
|
||
import qualified Data.ByteString.Lazy as LB | ||
import qualified Data.ByteString.UTF8 as U | ||
import Data.List | ||
import Data.List.Split | ||
import qualified Data.Map as M | ||
|
||
import Happstack.Server | ||
|
||
import Test.Framework | ||
import Test.HUnit | ||
|
||
import App | ||
import Import | ||
import Language | ||
|
||
|
||
-- Site handler with a test address | ||
testHandler :: ServerPartT App Response | ||
testHandler = site "http://test" | ||
|
||
-- Make a request to the application | ||
testRequest :: Request -> IO Response | ||
testRequest req = do | ||
app <- loadApp "testsuite/Integration/content" | ||
runApp app $ simpleHTTP'' testHandler req | ||
|
||
assertContains :: (Eq a, Show a) => [a] -> [a] -> Assertion | ||
assertContains needle haystack = | ||
subAssert $ assertBoolVerbose | ||
(show needle ++ " not found in:\n" ++ show haystack) | ||
(needle `isInfixOf` haystack) | ||
|
||
-- Create a request with a specified URL | ||
-- Happstack doesn't make it easy | ||
mkRequest :: String -> IO Request | ||
mkRequest rPath = do | ||
inputsBody <- newEmptyMVar | ||
rBody <- newMVar (Body LB.empty) | ||
return Request { rqSecure = False | ||
, rqMethod = GET | ||
, rqPaths = filter (/= "") $ splitOn "/" rPath | ||
, rqUri = rPath | ||
, rqQuery = "" | ||
, rqInputsQuery = [] | ||
, rqInputsBody = inputsBody | ||
, rqCookies = [] | ||
, rqVersion = HttpVersion 1 1 | ||
, rqHeaders = M.empty | ||
, rqBody = rBody | ||
, rqPeer = ("", 0) | ||
} | ||
|
||
withLang :: LanguagePreference -> Request -> Request | ||
withLang lang req = req { rqHeaders = newHeaders } | ||
where newHeaders = M.insert "accept-language" (HeaderPair "Accept-Language" [U.fromString pref]) (rqHeaders req) | ||
pref = show lang | ||
|
||
-- Extract contents from a response | ||
responseContent :: Response -> IO String | ||
responseContent r@(Response _ _ _ _ _) = return $ U.toString $ LB.toStrict $ rsBody r | ||
responseContent f@(SendFile _ _ _ _ _ _ _) = do | ||
contents <- readFile $ sfFilePath f | ||
let offset = fromIntegral $ sfOffset f | ||
let count = fromIntegral $ sfCount f | ||
return $ drop offset $ take count contents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{-# OPTIONS_GHC -F -pgmF htfpp #-} | ||
|
||
module Integration.TestArticle where | ||
|
||
import Control.Monad | ||
|
||
import Data.LanguageCodes | ||
|
||
import Language | ||
|
||
import Integration.Base | ||
|
||
import Test.Framework | ||
|
||
|
||
test_article = do | ||
req <- mkRequest "/2015/01/01/first-test" | ||
article <- testRequest req | ||
resp <- responseContent article | ||
assertContains | ||
"<h2 id=\"first-test-article\">First test article</h2>" | ||
resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{-# OPTIONS_GHC -F -pgmF htfpp #-} | ||
|
||
module Integration.TestHome where | ||
|
||
import Integration.Base | ||
|
||
import Test.Framework | ||
|
||
|
||
test_home = do | ||
req <- mkRequest "/" | ||
home <- testRequest req | ||
resp <- responseContent home | ||
assertContains "Test site" resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{-# OPTIONS_GHC -F -pgmF htfpp #-} | ||
|
||
module Integration.TestStatic where | ||
|
||
import Control.Monad | ||
|
||
import Language | ||
|
||
import Integration.Base | ||
|
||
import Test.Framework | ||
|
||
|
||
test_static = do | ||
req <- mkRequest "/some-verification-file.html" | ||
static <- testRequest req | ||
resp <- responseContent static | ||
assertEqual | ||
"This is the exact content of the verification file.\n" | ||
resp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
lang: en | ||
slug: first-test | ||
--- | ||
|
||
First test article | ||
------------------ | ||
|
||
Test content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
slug: about | ||
lang: en | ||
--- | ||
|
||
Test About | ||
---------- | ||
|
||
Integration test site |
1 change: 1 addition & 0 deletions
1
testsuite/Integration/content/static/some-verification-file.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is the exact content of the verification file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
home: | ||
en: Home | ||
ru: Главная | ||
zh: 首页 | ||
|
||
siteName: | ||
en: Test site |
Oops, something went wrong.