def test_find_or_create(self): # Secret creation command=FindOrCreateSecrets() command.execute() sign_secrets= SignSecret.query().order(-SignSecret.creation).fetch() self.assertEqual(1,len(sign_secrets)) # Last secret reuse command2=FindOrCreateSecrets() command2.execute() sign_secrets= SignSecret.query().order(-SignSecret.creation).fetch() self.assertEqual(1,len(sign_secrets)) self.assertIsNotNone(command.result) self.assertEqual(command.result,command2.result)
def test_find_or_create(self): # Secret creation command = FindOrCreateSecrets() command.execute() sign_secrets = SignSecret.query().order(-SignSecret.creation).fetch() self.assertEqual(1, len(sign_secrets)) # Last secret reuse command2 = FindOrCreateSecrets() command2.execute() sign_secrets = SignSecret.query().order(-SignSecret.creation).fetch() self.assertEqual(1, len(sign_secrets)) self.assertIsNotNone(command.result) self.assertEqual(command.result, command2.result)
def set_up(self): try: self.result = memcache.get(_SIGN_CACHE_KEY) except Exception: pass # If memcache fails, do nothing if self.result is None: self._future = SignSecret.find_last().fetch_async(2)
def do_business(self, stop_on_error=False): if self._future: secrets = self._future.get_result() if secrets: self.result = [sign.secret for sign in secrets] else: secret = _generate_secret() self.result = [secret] self._to_commit = [SignSecret(secret=secret)] memcache.set(_SIGN_CACHE_KEY, self.result)
def commit(self): return [SignSecret(secret=s) for s in self._secrets]
def commit(self): secret = _generate_secret() memcache.set(_SIGN_CACHE_KEY, [secret, self._find_secret.result[0]]) to_commit = super(RenewSecrets, self).commit() to_commit.append(SignSecret(secret=secret)) return to_commit