def testCreate(self):

        xmlfile = self.mktemp()
        db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)

        db.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))
        self.assertTrue(db.dtstamp is not None)
        self.assertTrue(len(db.timezones) > 0)
    def testGetNone(self):

        xmlfile = self.mktemp()
        db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)
        db.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))

        tz = db.getTimezone("Bogus")
        self.assertEqual(tz, None)
    def testListChangedSince(self):

        xmlfile = self.mktemp()
        db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)
        db.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))

        tzids = set([tz.tzid for tz in db.listTimezones(db.dtstamp)])
        self.assertTrue(len(tzids) == 0)
    def testList(self):

        xmlfile = self.mktemp()
        db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)
        db.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))

        tzids = set([tz.tzid for tz in db.listTimezones(None)])
        self.assertTrue("America/New_York" in tzids)
        self.assertTrue("US/Eastern" not in tzids)
    def testUpdate(self):

        xmlfile = self.mktemp()
        db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)

        db.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))

        db.updateDatabase()
        self.assertTrue(db.changeCount == 0)
        self.assertTrue(len(db.changed) == 0)
    def testGetOne(self):

        xmlfile = self.mktemp()
        db = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)
        db.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))

        # Original
        tz1 = db.getTimezone("America/New_York")
        self.assertTrue(str(tz1).find("VTIMEZONE") != -1)
        self.assertTrue(str(tz1).find("TZID:America/New_York") != -1)

        # Alias
        tz1 = db.getTimezone("US/Eastern")
        self.assertTrue(str(tz1).find("VTIMEZONE") != -1)
        self.assertTrue(str(tz1).find("TZID:US/Eastern") != -1)
    def testRead(self):

        xmlfile = self.mktemp()
        db1 = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)
        db1.createNewDatabase()
        self.assertTrue(os.path.exists(xmlfile))

        db2 = PrimaryTimezoneDatabase(TimezoneCache.getDBPath(), xmlfile)
        db2.readDatabase()
        self.assertEqual(db1.dtstamp, db2.dtstamp)
        self.assertEqual(len(db1.timezones), len(db2.timezones))