Exemple #1
0
    def test_save_duplicate(self):
        server_hostname = "simple.example.com"
        sync_info = IdentitySyncInfo(server_hostname=server_hostname)
        sync_info.last_sync = datetime.now(tzutc())
        sync_info.save()
        self.assertEquals(len(IdentitySyncInfo.objects()), 1 )

        dup = IdentitySyncInfo(server_hostname=server_hostname)
        dup.last_sync = datetime.now(tzutc())
        caught = False
        try:
            dup.save()
        except:
            caught = True
        data =  IdentitySyncInfo.objects()
        self.assertEquals(len(data), 1)
        self.assertTrue(caught)
Exemple #2
0
def save_last_sync(server_hostname, timestamp):
    key = sanitize_key_for_mongo(server_hostname)
    sync = IdentitySyncInfo.objects(server_hostname=key).first()
    if not sync:
        sync = IdentitySyncInfo(server_hostname=key)
    sync.last_sync = timestamp
    try:
        sync.save()
        _LOG.info("Last sync saved: %s" % (sync))
    except Exception, e:
        _LOG.exception(e)
        return False
Exemple #3
0
    def test_get_last_sync_timestamp(self):
        server_hostname = "a.b.c.example.com"
        sync_info = IdentitySyncInfo(server_hostname=server_hostname)
        sync_info.last_sync = datetime.now(tzutc())
        sync_info.save()

        found = identity.get_last_sync_timestamp(server_hostname)
        self.assertIsNotNone(found)
        created = sync_info.last_sync
        self.assertEquals(created.year, found.year)
        self.assertEquals(created.month, found.month)
        self.assertEquals(created.day, found.day)
        self.assertEquals(created.hour, found.hour)
        self.assertEquals(created.minute, found.minute)
        self.assertEquals(created.second, found.second)
Exemple #4
0
 def test_save_last_sync(self):
     server_hostname = "a.b.c.example.com"
     sync_info = IdentitySyncInfo(server_hostname=server_hostname)
     sync_info.last_sync = datetime.now(tzutc())
     sync_info.save()
     key = utils.sanitize_key_for_mongo(server_hostname)
     lookup = IdentitySyncInfo.objects(server_hostname=key)
     self.assertIsNotNone(lookup)
     self.assertEquals(len(lookup), 1)
     created = sync_info.last_sync
     found = lookup[0].last_sync
     self.assertEquals(created.year, found.year)
     self.assertEquals(created.month, found.month)
     self.assertEquals(created.day, found.day)
     self.assertEquals(created.hour, found.hour)
     self.assertEquals(created.minute, found.minute)
     self.assertEquals(created.second, found.second)