]> gitweb.michael.orlitzky.com - dead/htsn-import.git/commitdiff
Make the News SMS field optional.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 3 Oct 2014 16:06:07 +0000 (12:06 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 3 Oct 2014 16:06:07 +0000 (12:06 -0400)
Add a News test case with an empty SMS element.

src/TSN/XML/News.hs
test/shell/import-duplicates.test
test/xml/newsxml-empty-sms.xml [new file with mode: 0644]

index 513bf5c5764a1839c0140fff8344dbad08af28fe..f401d41cb2dbb67d139395a6089c36f09ac9a23d 100644 (file)
@@ -120,7 +120,7 @@ data Message =
     xml_url :: Maybe String,
     xml_teams :: [NewsTeam],
     xml_locations :: [Location],
-    xml_sms :: String,
+    xml_sms :: Maybe String,
     xml_editor :: Maybe String,
     xml_text :: Maybe String,     -- Text and continue seem to show up in pairs,
     xml_continue :: Maybe String, -- either both present or both missing.
@@ -138,7 +138,7 @@ data News =
     db_mid :: MsgId,
     db_sport :: String,
     db_url :: Maybe String,
-    db_sms :: String,
+    db_sms :: Maybe String,
     db_editor :: Maybe String,
     db_text :: Maybe String,
     db_continue :: Maybe String,
@@ -397,7 +397,7 @@ pickle_message =
               (xpElem "url" $ xpOption xpText)
               (xpList pickle_news_team)
               (xpList pickle_location)
-              (xpElem "SMS" xpText)
+              (xpElem "SMS" $ xpOption xpText)
               (xpOption (xpElem "Editor" xpText))
               (xpOption (xpElem "text" xpText))
               pickle_continue
@@ -492,7 +492,10 @@ test_pickle_of_unpickle_is_identity = testGroup "pickle-unpickle tests"
           "test/xml/newsxml.xml",
 
     check "pickle composed with unpickle is the identity (with Editor)"
-          "test/xml/newsxml-with-editor.xml" ]
+          "test/xml/newsxml-with-editor.xml",
+
+    check "pickle composed with unpickle is the identity (empty SMS)"
+          "test/xml/newsxml-empty-sms.xml" ]
   where
     check desc path = testCase desc $ do
       (expected, actual) <- pickle_unpickle pickle_message path
@@ -507,7 +510,10 @@ test_unpickle_succeeds = testGroup "unpickle tests"
           "test/xml/newsxml.xml",
 
     check "unpickling succeeds (with Editor)"
-          "test/xml/newsxml-with-editor.xml" ]
+          "test/xml/newsxml-with-editor.xml",
+
+    check "unpickling succeeds (empty SMS)"
+          "test/xml/newsxml-empty-sms.xml" ]
   where
     check desc path = testCase desc $ do
       actual <- unpickleable path pickle_message
@@ -523,6 +529,10 @@ test_on_delete_cascade = testGroup "cascading delete tests"
   [ check "deleting news deletes its children"
           "test/xml/newsxml.xml"
           4 -- 2 news_teams and 2 news_locations that should remain.
+    ,
+    check "deleting news deletes its children (empty SMS)"
+          "test/xml/newsxml-empty-sms.xml"
+          4 -- 2 news_teams and 2 news_locations
   ]
   where
     check desc path expected = testCase desc $ do
index 183b684183f1cb7756686161c988edca36ec0a27..a81bd046c7f1cd723ccb835fc0dd3c3332c96bc3 100644 (file)
@@ -16,7 +16,7 @@ rm -f shelltest.sqlite3
 # and a newsxml that aren't really supposed to import.
 find ./test/xml -maxdepth 1 -name '*.xml' | wc -l
 >>>
-33
+34
 >>>= 0
 
 # Run the imports again; we should get complaints about the duplicate
@@ -24,7 +24,7 @@ find ./test/xml -maxdepth 1 -name '*.xml' | 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
 >>>
-58
+60
 >>>= 0
 
 # Finally, clean up after ourselves.
diff --git a/test/xml/newsxml-empty-sms.xml b/test/xml/newsxml-empty-sms.xml
new file mode 100644 (file)
index 0000000..d08cff4
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD News 1.0/EN" "newsxml.dtd">\r<message>\r<XML_File_ID>21904559</XML_File_ID>\r<heading>AFN;UTAH-UCLA</heading>\r<msg_id EventId="">0</msg_id>\r<category>News</category>\r<sport>CFOOT</sport>\r<url></url>\r<team>UCLA</team>\r<team>UTAH</team>\r<location>\r<city>U-C-L-A</city>\r<state>CA</state>\r<country>USA</country>\r</location>\r<location>\r<city>Utah</city>\r<state>UT</state>\r<country>USA</country>\r</location>\r<SMS></SMS>\r<text>\r Pasadena, CA (SportsNetwork.com) -\r</text>\r<continue>\r</continue>\r<time_stamp> October 1, 2014, at 11:11 AM ET </time_stamp>\r</message>\r
\ No newline at end of file