news_tests )
where
-import Control.Monad.IO.Class ( MonadIO, liftIO )
import Data.Data ( Data, constrFields, dataTypeConstrs, dataTypeOf )
import Data.List.Utils ( join, split )
import Data.Tuple.Curry ( uncurryN )
xpTriple,
xpWrap )
-import Network.Services.TSN.Report ( report_error )
import TSN.Codegen (
tsn_codegen_config,
tsn_db_field_namer -- Used in a test.
)
-import TSN.DbImport ( DbImport(..) )
+import TSN.DbImport ( DbImport(..), ImportResult(..) )
import Xml ( ToFromXml(..), pickle_unpickle )
-- used our named fields.
to_xml (NewsTeam {..}) = NewsTeamXml db_team_name
-- We can't create a DefaultKey Message...
- from_xml = error "Called from_xml on a NewsTeam"
+ from_xml = error "Called from_xml on a NewsTeam."
-- unless we're handed one.
from_xml_fk key = (NewsTeam key) . xml_team_name
-- used our named fields.
to_xml (NewsLocation {..}) = NewsLocationXml db_city db_state db_country
-- We can't create a DefaultKey Message...
- from_xml = error "Called from_xml on a NewsLocation"
+ from_xml = error "Called from_xml on a NewsLocation."
-- unless we're given one.
from_xml_fk key (NewsLocationXml x y z) = NewsLocation key x y z
case root_element of
Nothing -> do
let errmsg = "Could not unpickle News message in dbimport."
- liftIO $ report_error errmsg
- return Nothing
+ return $ ImportFailed errmsg
Just message -> do
news_id <- insert (from_xml message :: Message)
let nts :: [NewsTeam] = map (from_xml_fk news_id)
nt_ids <- mapM insert nts
loc_ids <- mapM insert nlocs
- return $ Just (1 + (length nt_ids) + (length loc_ids))
+ return $ ImportSucceeded (1 + (length nt_ids) + (length loc_ids))
-- * Tasty Tests