Add a test case for a JFile with "TBA" game time.
Update the jfilexml dbschema diagram.
xp_date,
xp_date_padded,
xp_datetime,
xp_date,
xp_date_padded,
xp_datetime,
xp_time_dots,
xp_time_stamp )
import TSN.Team (
xp_time_dots,
xp_time_stamp )
import TSN.Team (
db_schedule_id :: Int,
db_odds_info :: JFileGameOddsInfo,
db_season_type :: Maybe String,
db_schedule_id :: Int,
db_odds_info :: JFileGameOddsInfo,
db_season_type :: Maybe String,
- db_game_time :: UTCTime,
+ db_game_time :: Maybe UTCTime,
db_vleague :: Maybe String,
db_hleague :: Maybe String,
db_vscore :: Int,
db_vleague :: Maybe String,
db_hleague :: Maybe String,
db_vscore :: Int,
xml_odds_info :: JFileGameOddsInfo,
xml_season_type :: Maybe String,
xml_game_date :: UTCTime,
xml_odds_info :: JFileGameOddsInfo,
xml_season_type :: Maybe String,
xml_game_date :: UTCTime,
- xml_game_time :: UTCTime,
+ xml_game_time :: Maybe UTCTime,
xml_vteam :: VTeam,
xml_vleague :: Maybe String,
xml_hteam :: HTeam,
xml_vteam :: VTeam,
xml_vleague :: Maybe String,
xml_hteam :: HTeam,
db_time_remaining = xml_time_remaining,
db_game_status = xml_game_status }
where
db_time_remaining = xml_time_remaining,
db_game_status = xml_game_status }
where
- -- | Make the database \"game time\" from the XML
- -- date/time. Simply take the day part from one and the time
- -- from the other.
- --
- make_game_time d t = UTCTime (utctDay d) (utctDayTime t)
+ -- | Construct the database game time from the XML \<Game_Date\>
+ -- and \<Game_Time\> elements. The \<Game_Time\> elements
+ -- sometimes have a value of \"TBA\"; in that case, we don't
+ -- want to pretend that we know the time by setting it to
+ -- e.g. midnight, so instead we make the entire date/time
+ -- Nothing.
+ make_game_time :: UTCTime -> Maybe UTCTime -> Maybe UTCTime
+ make_game_time _ Nothing = Nothing
+ make_game_time d (Just t) = Just $ UTCTime (utctDay d) (utctDayTime t)
-- | This allows us to insert the XML representation
-- | This allows us to insert the XML representation
pickle_odds_info
(xpElem "seasontype" (xpOption xpText))
(xpElem "Game_Date" xp_date_padded)
pickle_odds_info
(xpElem "seasontype" (xpOption xpText))
(xpElem "Game_Date" xp_date_padded)
- (xpElem "Game_Time" xp_time)
+ (xpElem "Game_Time" xp_tba_time)
pickle_away_team
(xpOption $ xpElem "vleague" xpText)
pickle_home_team
pickle_away_team
(xpOption $ xpElem "vleague" xpText)
pickle_home_team
[ check "pickle composed with unpickle is the identity"
"test/xml/jfilexml.xml",
check "pickle composed with unpickle is the identity (missing fields)"
[ check "pickle composed with unpickle is the identity"
"test/xml/jfilexml.xml",
check "pickle composed with unpickle is the identity (missing fields)"
- "test/xml/jfilexml-missing-fields.xml" ]
+ "test/xml/jfilexml-missing-fields.xml",
+
+ check "pickle composed with unpickle is the identity (TBA game time)"
+ "test/xml/jfilexml-tba-game-time.xml"]
where
check desc path = testCase desc $ do
(expected, actual) <- pickle_unpickle pickle_message path
where
check desc path = testCase desc $ do
(expected, actual) <- pickle_unpickle pickle_message path
test_unpickle_succeeds :: TestTree
test_unpickle_succeeds = testGroup "unpickle tests"
[ check "unpickling succeeds" "test/xml/jfilexml.xml",
test_unpickle_succeeds :: TestTree
test_unpickle_succeeds = testGroup "unpickle tests"
[ check "unpickling succeeds" "test/xml/jfilexml.xml",
check "unpickling succeeds (missing fields)"
check "unpickling succeeds (missing fields)"
- "test/xml/jfilexml-missing-fields.xml" ]
+ "test/xml/jfilexml-missing-fields.xml",
+
+ check "unpickling succeeds (TBA game time)"
+ "test/xml/jfilexml-tba-game-time.xml" ]
where
check desc path = testCase desc $ do
actual <- unpickleable path pickle_message
where
check desc path = testCase desc $ do
actual <- unpickleable path pickle_message
test_on_delete_cascade = testGroup "cascading delete tests"
[ check "deleting auto_racing_results deletes its children"
"test/xml/jfilexml.xml"
test_on_delete_cascade = testGroup "cascading delete tests"
[ check "deleting auto_racing_results deletes its children"
"test/xml/jfilexml.xml"
check "deleting auto_racing_results deletes its children (missing fields)"
"test/xml/jfilexml-missing-fields.xml"
check "deleting auto_racing_results deletes its children (missing fields)"
"test/xml/jfilexml-missing-fields.xml"
+ 44,
+
+ check "deleting auto_racing_results deletes its children (TBA game time)"
+ "test/xml/jfilexml-tba-game-time.xml"
+ 8 ]
where
check desc path expected = testCase desc $ do
results <- unsafe_unpickle path pickle_message
where
check desc path expected = testCase desc $ do
results <- unsafe_unpickle path pickle_message
# and a newsxml that aren't really supposed to import.
find ./test/xml -maxdepth 1 -name '*.xml' | wc -l
>>>
# and a newsxml that aren't really supposed to import.
find ./test/xml -maxdepth 1 -name '*.xml' | wc -l
>>>
>>>= 0
# Run the imports again; we should get complaints about the duplicate
>>>= 0
# Run the imports again; we should get complaints about the duplicate
# occurrences of the string 'ERROR'.
./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l
>>>
# occurrences of the string 'ERROR'.
./dist/build/htsn-import/htsn-import -c 'shelltest.sqlite3' test/xml/*.xml 2>&1 | grep ERROR | wc -l
>>>
>>>= 0
# Finally, clean up after ourselves.
>>>= 0
# Finally, clean up after ourselves.
--- /dev/null
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Scores 1.0/EN" "jfilexml.dtd">\r<message>\r<XML_File_ID>21933332</XML_File_ID>\r<heading>BC-AAJ</heading>\r<category>JFILE</category>\r<sport>MLB</sport>\r<gamelist>\r<game>\r<game_id>44542</game_id>\r<schedule_id>44542</schedule_id>\r<Odds_Info>\r<ListDate></ListDate>\r<HomeTeamID></HomeTeamID>\r<AwayTeamID></AwayTeamID>\r<HomeAbbr></HomeAbbr>\r<AwayAbbr></AwayAbbr>\r<HomeTeamName></HomeTeamName>\r<AwayTeamName></AwayTeamName>\r<HStarter></HStarter>\r<AStarter></AStarter>\r<GameDate></GameDate>\r<HGameKey></HGameKey>\r<AGameKey></AGameKey>\r<CurrentTimeStamp></CurrentTimeStamp>\r<Live></Live>\r<Notes1></Notes1>\r<Notes2></Notes2>\r<Notes3></Notes3>\r<Notes4></Notes4>\r<Notes5></Notes5>\r</Odds_Info>\r<seasontype>PostSeason</seasontype>\r<Game_Date>10/06/2014</Game_Date>\r<Game_Time>TBA</Game_Time>\r<vteam teamid="005" abbr="LOS">Los Angeles</vteam>\r<vleague>NL</vleague>\r<hteam teamid="012" abbr="STL">St. Louis</hteam>\r<hleague>NL</hleague>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="0">3:00 AM</status>\r</game>\r<game>\r<game_id>44543</game_id>\r<schedule_id>44543</schedule_id>\r<Odds_Info>\r<ListDate></ListDate>\r<HomeTeamID></HomeTeamID>\r<AwayTeamID></AwayTeamID>\r<HomeAbbr></HomeAbbr>\r<AwayAbbr></AwayAbbr>\r<HomeTeamName></HomeTeamName>\r<AwayTeamName></AwayTeamName>\r<HStarter></HStarter>\r<AStarter></AStarter>\r<GameDate></GameDate>\r<HGameKey></HGameKey>\r<AGameKey></AGameKey>\r<CurrentTimeStamp></CurrentTimeStamp>\r<Live></Live>\r<Notes1></Notes1>\r<Notes2></Notes2>\r<Notes3></Notes3>\r<Notes4></Notes4>\r<Notes5></Notes5>\r</Odds_Info>\r<seasontype>PostSeason</seasontype>\r<Game_Date>10/06/2014</Game_Date>\r<Game_Time>TBA</Game_Time>\r<vteam teamid="006" abbr="WAS">Washington</vteam>\r<vleague>NL</vleague>\r<hteam teamid="011" abbr="SFG">San Francisco</hteam>\r<hleague>NL</hleague>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="0">3:00 AM</status>\r</game>\r<game>\r<game_id>44533</game_id>\r<schedule_id>44533</schedule_id>\r<Odds_Info>\r<ListDate>10/5/2014</ListDate>\r<HomeTeamID>032</HomeTeamID>\r<AwayTeamID>027</AwayTeamID>\r<HomeAbbr>DET</HomeAbbr>\r<AwayAbbr>BAL</AwayAbbr>\r<HomeTeamName>Detroit</HomeTeamName>\r<AwayTeamName>Baltimore</AwayTeamName>\r<HStarter>D.Price</HStarter>\r<AStarter>B.Norris</AStarter>\r<GameDate>10/5/2014 3:45:00 PM</GameDate>\r<HGameKey>918</HGameKey>\r<AGameKey>917</AGameKey>\r<CurrentTimeStamp>3:30 P.M.</CurrentTimeStamp>\r<Live>True</Live>\r<Notes1>ALDS - Baltimore leads 2-0</Notes1>\r<Notes2></Notes2>\r<Notes3></Notes3>\r<Notes4></Notes4>\r<Notes5></Notes5>\r</Odds_Info>\r<seasontype>PostSeason</seasontype>\r<Game_Date>10/05/2014</Game_Date>\r<Game_Time>03:45 PM</Game_Time>\r<vteam teamid="027" abbr="BAL">Baltimore</vteam>\r<vleague>AL</vleague>\r<hteam teamid="032" abbr="DET">Detroit</hteam>\r<hleague>AL</hleague>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="3">3:00 AM</status>\r</game>\r<game>\r<game_id>44532</game_id>\r<schedule_id>44532</schedule_id>\r<Odds_Info>\r<ListDate>10/5/2014</ListDate>\r<HomeTeamID>033</HomeTeamID>\r<AwayTeamID>029</AwayTeamID>\r<HomeAbbr>KAN</HomeAbbr>\r<AwayAbbr>ANA</AwayAbbr>\r<HomeTeamName>Kansas City</HomeTeamName>\r<AwayTeamName>LA Angels</AwayTeamName>\r<HStarter>J.Shields</HStarter>\r<AStarter>C.Wilson</AStarter>\r<GameDate>10/5/2014 7:37:00 PM</GameDate>\r<HGameKey>920</HGameKey>\r<AGameKey>919</AGameKey>\r<CurrentTimeStamp>3:30 P.M.</CurrentTimeStamp>\r<Live>True</Live>\r<Notes1>ALDS - Kansas City leads 2-0</Notes1>\r<Notes2></Notes2>\r<Notes3></Notes3>\r<Notes4></Notes4>\r<Notes5></Notes5>\r</Odds_Info>\r<seasontype>PostSeason</seasontype>\r<Game_Date>10/05/2014</Game_Date>\r<Game_Time>07:37 PM</Game_Time>\r<vteam teamid="029" abbr="ANA">LA Angels</vteam>\r<vleague>AL</vleague>\r<hteam teamid="033" abbr="KAN">Kansas City</hteam>\r<hleague>AL</hleague>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="0">7:37 PM</status>\r</game>\r</gamelist>\r<time_stamp>October 5, 2014, at 04:10 PM ET </time_stamp>\r</message>\r
\ No newline at end of file