class TestSiteListFetchHandling(unittest.TestCase):
    goodxml = """
        <SiteList xmlns="http://isdcf.com/2010/04/SiteList" xmlns:xlink="http://www.w3.org/1999/xlink">
            <Originator>orig</Originator>
            <SystemName>sysName</SystemName>
            <DateTimeCreated>2001-01-01T15:49:40.220</DateTimeCreated>
            <FacilityList>
                <Facility id="A" modified="2011-04-07T12:10:01-00:00" xlink:href="linkA" xlink:type="simple"/>
                <Facility id="B" modified="2012-05-08T12:11:02-01:20" xlink:href="linkB" xlink:type="simple"/>
                <Facility id="C" modified="2013-06-09T12:12:03+03:40" xlink:href="linkC" xlink:type="simple"/>
            </FacilityList>
        </SiteList>
        """

    datetimeA = helper.get_datetime(u'2011-04-07T12:10:01-00:00')
    datetimeB = helper.get_datetime(u'2012-05-08T12:11:02-01:20')
    datetimeC = helper.get_datetime(u'2013-06-09T12:12:03+03:40')

    def setUp(self):
        self.sites = SiteListParser(self.goodxml)

    def test_no_date(self):
        dict = self.sites.get_sites()
        self.assertEqual(len(dict), 3)
        #datetimes should be correct, given that TestSiteListDateHandling worked
        self.assertEqual(dict[u'linkA'], self.datetimeA)
        self.assertEqual(dict[u'linkB'], self.datetimeB)
        self.assertEqual(dict[u'linkC'], self.datetimeC)

    def test_middle_date(self):
        #beginning of 2012, should only return B and C
        dict = self.sites.get_sites(datetime(2012,01,01,12,0,0))
        self.assertEqual(len(dict), 2)
        self.assertFalse(u'linkA' in dict)
        self.assertEqual(dict[u'linkB'], self.datetimeB)
        self.assertEqual(dict[u'linkC'], self.datetimeC)

    def test_before_date(self):
        #beginning of 2011, should return all
        dict = self.sites.get_sites(datetime(2011,01,01,12,0,0))
        self.assertEqual(len(dict), 3)
        self.assertEqual(dict[u'linkA'], self.datetimeA)
        self.assertEqual(dict[u'linkB'], self.datetimeB)
        self.assertEqual(dict[u'linkC'], self.datetimeC)

    def test_middle_date(self):
        #beginning of 2014, should not return anything
        dict = self.sites.get_sites(datetime(2014,01,01,12,0,0))
        self.assertEqual(len(dict), 0)
 def test_good_xml(self):
     s = SiteListParser(self.good)
     dict = s.get_sites()
     self.assertEqual(len(dict), 3)
 def setUp(self):
     self.sites = SiteListParser(self.goodxml)