scrape-changes 0.1.0.4 → 0.1.0.5
raw patch · 2 files changed
+30/−33 lines, 2 filesdep ~email-validatedep ~http-clientdep ~lensPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: email-validate, http-client, lens, mime-mail, network-uri, shakespeare, text, validation
API changes (from Hackage documentation)
Files
- scrape-changes.cabal +13/−13
- test/Network/ScrapeChanges/Internal/Test.hs +17/−20
scrape-changes.cabal view
@@ -1,5 +1,5 @@ name: scrape-changes-version: 0.1.0.4+version: 0.1.0.5 synopsis: Scrape websites for changes description: This library scrapes websites and invokes callbacks when there are changes, similar to a RSS reader. Sending an email by invoking sendmail is a built-in callback mechanism. Of course, users can provide@@ -23,16 +23,16 @@ other-modules: other-extensions: build-depends: base >=4.8 && <5.0- , validation >=0.5.1 && < 0.6- , lens >=4.12 && <4.20- , mime-mail >= 0.4 && < 0.5- , network-uri >=2.6.1.0 && < 2.7- , email-validate >= 2.0 && < 3.0+ , validation >=0.5.1+ , lens >=4.12+ , mime-mail >= 0.4+ , network-uri >=2.6.1.0+ , email-validate >= 2.0 , semigroups >= 0.16 , cron >= 0.3.2 , attoparsec >= 0.13.0 , wreq >= 0.4.0.0- , http-client >= 0.4 && < 1.0+ , http-client >= 0.4 , hashable >= 1.2.3.3 , directory >= 1.2.2.0 , filepath >= 1.4.0.0@@ -40,7 +40,7 @@ , bytestring >= 0.10 , hslogger >= 1.2.9 , strict >= 0.3.2- , text >= 1.2.1.0 && < 1.2.3.0+ , text >= 1.2.1.0 hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall@@ -56,15 +56,15 @@ , test-framework-quickcheck2 >=0.3.0.3 , test-framework-hunit >= 0.3.0.2 , HUnit >= 1.2.5.2- , validation >=0.5.1 && < 0.6- , lens >=4.12 && <4.20- , email-validate >= 2.0 && < 3.0+ , validation >=0.5.1+ , lens >=4.12+ , email-validate >= 2.0 , cron >= 0.3.2 , semigroups >= 0.16 , hashable >= 1.2.3.3 , scrape-changes- , text >= 1.2.1.0 && < 1.2.3.0- , shakespeare >= 2.0.0 && < 2.1.0+ , text >= 1.2.1.0+ , shakespeare >= 2.0.0 default-language: Haskell2010 source-repository head
test/Network/ScrapeChanges/Internal/Test.hs view
@@ -24,18 +24,18 @@ newtype NCronScheduleString = NCronScheduleString { nCronScheduleStringRun :: String } deriving Show instance Show ScrapeConfig where- show (ScrapeConfig url (MailConfig mail))= show [lt| + show (ScrapeConfig url (MailConfig mail))= show [lt| ScrapeConfig { _scrapeInfoUrl = #{url} , _scrapeInfoCallbackConfig = MailConfig #{show mail} } |]- show (ScrapeConfig url (OtherConfig _))= show [lt| + show (ScrapeConfig url (OtherConfig _))= show [lt| ScrapeConfig { _scrapeInfoUrl = #{url} , _scrapeInfoCallbackConfig = OtherConfig (\x -> return ()) } |] -instance Arbitrary NCronScheduleString where +instance Arbitrary NCronScheduleString where arbitrary = NCronScheduleString <$> oneof [pure correctCronScheduleString, arbitrary] correctCronScheduleString :: String@@ -60,13 +60,10 @@ instance Arbitrary ScrapeConfig where arbitrary = helper <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary- where helper scrapeInfoUrl' config' mailFromAddr mailToAddrs = + where helper scrapeInfoUrl' config' mailFromAddr mailToAddrs = let setConfig = scrapeInfoCallbackConfig .~ config' in setConfig $ SC.mailScrapeConfig scrapeInfoUrl' mailFromAddr mailToAddrs -instance Arbitrary a => Arbitrary (NonEmpty a) where- arbitrary = (:|) <$> arbitrary <*> arbitrary- tMailAddr :: MailAddr tMailAddr = MailAddr (Just $ TextLazy.pack "Max Mustermann") "max@mustermann.com" @@ -79,20 +76,20 @@ correctMailScrapeConfig :: ScrapeConfig correctMailScrapeConfig = SC.mailScrapeConfig correctUrl tMailAddr (tMailAddr :| []) -correctOtherScrapeConfig :: ScrapeConfig +correctOtherScrapeConfig :: ScrapeConfig correctOtherScrapeConfig = let setCallbackConfig = scrapeInfoCallbackConfig .~ OtherConfig (const $ return ()) in setCallbackConfig correctMailScrapeConfig validateScrapeConfigWithBadInfoUrlShouldNotValidate :: Assertion-validateScrapeConfigWithBadInfoUrlShouldNotValidate = +validateScrapeConfigWithBadInfoUrlShouldNotValidate = let wrongUrl = "httpp://www.google.de"- scrapeInfo = scrapeInfoUrl .~ wrongUrl $ correctMailScrapeConfig + scrapeInfo = scrapeInfoUrl .~ wrongUrl $ correctMailScrapeConfig result = SUT.validateScrapeConfig scrapeInfo- in Just [UrlProtocolInvalid] @=? result ^? V._Failure + in Just [UrlProtocolInvalid] @=? result ^? V._Failure validateScrapeConfigShouldValidateOnValidInput :: Assertion validateScrapeConfigShouldValidateOnValidInput =- let scrapeInfo = scrapeInfoUrl .~ correctUrl $ correctMailScrapeConfig + let scrapeInfo = scrapeInfoUrl .~ correctUrl $ correctMailScrapeConfig result = SUT.validateScrapeConfig scrapeInfo in result @=? V.AccSuccess scrapeInfo @@ -103,7 +100,7 @@ badUrlErrorsOnly = (null . (L.\\ [UrlNotAbsolute, UrlProtocolInvalid])) <$> (result ^? V._Failure) p2 = property $ False `M.fromMaybe` badUrlErrorsOnly in p1 .||. p2- + validateScrapeConfigWithMailConfigShouldSatisfyAllInvariants :: ScrapeConfig -> Property validateScrapeConfigWithMailConfigShouldSatisfyAllInvariants si = M.isJust (si ^? scrapeInfoCallbackConfig . _MailConfig) ==> let result = SUT.validateScrapeConfig si@@ -111,7 +108,7 @@ mailConfigLens = scrapeInfoCallbackConfig . _MailConfig (Just mailConfig) = si ^? mailConfigLens invalidMailAddr = not . EmailValidate.isValid . (^. ByteStringLens.packedChars)- invalidMailAddrsProp es = let expected = (\errors' -> (`elem` errors') `L.all` es) <$> failure + invalidMailAddrsProp es = let expected = (\errors' -> (`elem` errors') `L.all` es) <$> failure in True `M.fromMaybe` expected mailFromAddr = mailConfig ^. mailFrom . mailAddr mailToAddrs = mailConfig ^.. mailTo . traverse . mailAddr@@ -121,7 +118,7 @@ in property invalidMailFromAddrsProp .&&. property invalidMailToAddrsProp validateCronScheduleShouldSatisfyAllInvariants :: NCronScheduleString -> Property-validateCronScheduleShouldSatisfyAllInvariants c = +validateCronScheduleShouldSatisfyAllInvariants c = let result = SUT.validateCronSchedule $ nCronScheduleStringRun c isCorrect = nCronScheduleStringRun c /= correctCronScheduleString || M.isJust (result ^? V._Success)@@ -129,22 +126,22 @@ in property isCorrect .||. property containsExpectedError differentScrapeConfigsShouldYieldToDifferentHashes :: ScrapeConfig -> ScrapeConfig -> Property-differentScrapeConfigsShouldYieldToDifferentHashes c1 c2 = +differentScrapeConfigsShouldYieldToDifferentHashes c1 c2 = let isOtherConfig = M.isJust . (^? scrapeInfoCallbackConfig . _OtherConfig)- in not (isOtherConfig c1 && isOtherConfig c2) ==> + in not (isOtherConfig c1 && isOtherConfig c2) ==> let hashedC1 = Hashable.hash c1 hashedC2 = Hashable.hash c2- correspondenceBetweenEqualsAndHashable = + correspondenceBetweenEqualsAndHashable = label "correspondenceBetweenEqualsAndHashable" $ if c1 == c2 then hashedC1 == hashedC2 else hashedC1 /= hashedC2 differentMailConfigAttribute = let setMailSubject = set $ scrapeInfoCallbackConfig . _MailConfig . mailSubject c1' = c1 & setMailSubject (TextLazy.pack "sub1")- c2' = c2 & setMailSubject (TextLazy.pack "sub2") + c2' = c2 & setMailSubject (TextLazy.pack "sub2") in label "differentMailConfigAttribute" $ c1' /= c2' in correspondenceBetweenEqualsAndHashable .&&. differentMailConfigAttribute tests :: [TF.Test]-tests = +tests = [ testGroup "Network.ScrapeChanges.Internal" [