Exemple #1
0
 def test_sanitize_key_for_mongo(self):
     bad_dots_in_list_key = ["bad.value.1", [["bad.value.2"]]]
     fixed_bad_key = ["bad_dot_value_dot_1", [["bad_dot_value_dot_2"]]]
     sanitized = utils.sanitize_key_for_mongo(bad_dots_in_list_key)
     self.assertEquals(len(sanitized), len(fixed_bad_key))
     for key in sanitized:
         self.assertIn(key, fixed_bad_key)
     expected_same = utils.sanitize_key_for_mongo(sanitized)
     self.assertEquals(expected_same, sanitized)
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_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)
Exemple #4
0
 def pre_save(cls, sender, document, **kwargs):
     """
     pre_save signal hook.
     """
     # Ensure that the 'server_hostname' has any "." removed so it can be a key in mongo
     document.server_hostname = sanitize_key_for_mongo(document.server_hostname)
Exemple #5
0
def get_last_sync_timestamp(server_hostname):
    key = sanitize_key_for_mongo(server_hostname)
    sync = IdentitySyncInfo.objects(server_hostname=key).first()
    if not sync:
        return None
    return sync.last_sync