haskell-neo4j-client 0.3.2.2 → 0.3.2.3
raw patch · 3 files changed
+27/−6 lines, 3 filesdep ~http-client
Dependency ranges changed: http-client
Files
- haskell-neo4j-client.cabal +3/−3
- src/Database/Neo4j/Http.hs +14/−1
- tests/IntegrationTests.hs +10/−2
haskell-neo4j-client.cabal view
@@ -1,5 +1,5 @@ name: haskell-neo4j-client-version: 0.3.2.2+version: 0.3.2.3 synopsis: A Haskell neo4j client description: Library to interact with Neo4j databases. @@ -48,7 +48,7 @@ , HUnit >= 1.2 , Cabal , text >= 1.1- , http-client >= 0.4+ , http-client >= 0.5 , http-client-tls >= 0.2 , http-conduit >= 2.1 , http-types >= 0.8@@ -80,7 +80,7 @@ build-depends: base == 4.* , containers >= 0.5 , text >= 1.1- , http-client >= 0.4+ , http-client >= 0.5 , http-client-tls >= 0.2 , http-conduit >= 2.1 , http-types >= 0.8
src/Database/Neo4j/Http.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} module Database.Neo4j.Http where@@ -77,21 +78,33 @@ let conn = Connection hostname port mgr (Just creds) True liftIO $ runNeo4j cmds conn +#if MIN_VERSION_http_client(0,4,30)+defaultReq = HC.defaultRequest+#else+defaultReq = def+#endif -- | General function for HTTP requests httpReq :: Connection -> HT.Method -> S.ByteString -> L.ByteString -> (HT.Status -> Bool) -> IO (HC.Response L.ByteString) httpReq (Connection h p m c s) method path body statusCheck = do- let request = def {+ let request = defaultReq { HC.host = h, HC.port = p, HC.path = path, HC.method = method, HC.requestBody = HC.RequestBodyLBS body, HC.secure = s,+#if MIN_VERSION_http_client(0,5,0)+ HC.checkResponse = \_ r -> let s = HC.responseStatus r in + if statusCheck s+ then return ()+ else throw (Neo4jUnexpectedResponseException s),+#else HC.checkStatus = \s _ _ -> if statusCheck s then Nothing else Just (toException $ Neo4jUnexpectedResponseException s),+#endif HC.requestHeaders = [(HT.hAccept, "application/json; charset=UTF-8"), (HT.hContentType, "application/json")]} -- TODO: Would be better to use exceptions package Control.Monad.Catch ??
tests/IntegrationTests.hs view
@@ -49,6 +49,14 @@ where --checkExc :: (Exception e, Show e) => Maybe e -> Assertion checkExc Nothing = assertFailure $ "Expected exception " <> show exExc <> " but none raised" checkExc (Just e) = assertEqual "" exExc e++assertFException :: (Neo4jException -> Assertion) -> IO a -> Assertion+assertFException f action = do+ resExc <- getException action+ checkExc resExc+ where --checkExc :: (Exception e, Show e) => Maybe e -> Assertion+ checkExc Nothing = assertFailure $ "Expected exception but none raised"+ checkExc (Just e) = f e -- | handy assertEqual inside a Neo4j monad neo4jEqual :: (Show a, Eq a) => a -> a -> Neo4j ()@@ -98,8 +106,8 @@ -- | Test connecting to a non-existing server case_NoConnection :: Assertion-case_NoConnection = assertException expException $ withConnection "localhost" 77 $ createNode someProperties- where expException = Neo4jHttpException "FailedConnectionException2 \"localhost\" 77 False connect: does not exist (Connection refused)"+case_NoConnection = assertFException f $ withConnection "localhost" 77 $ createNode someProperties+ where f e = assertBool "" $ e == Neo4jHttpException "FailedConnectionException2 \"localhost\" 77 False connect: does not exist (Connection refused)" || e == Neo4jHttpException "HttpExceptionRequest Request {\n host = \"localhost\"\n port = 77\n secure = False\n requestHeaders = [(\"Accept\",\"application/json; charset=UTF-8\"),(\"Content-Type\",\"application/json\")]\n path = \"/db/data/node\"\n queryString = \"\"\n method = \"POST\"\n proxy = Nothing\n rawBody = False\n redirectCount = 10\n responseTimeout = ResponseTimeoutDefault\n requestVersion = HTTP/1.1\n}\n (ConnectionFailure connect: does not exist (Connection refused))" -- | Test connecting to a server with improper credentials case_ImproperCredentials :: Assertion