def test_update_new_token(self): initial_count = Token.select().count() count = {"token": "dummy", "frequency": 5} Token.update_count(count, self.enc) final_count = Token.select().count() assert initial_count + 1 == final_count entry = Token.get(Token.hash == self.enc.salted_hash("dummy")) entry.frequency == 5
def test_updating_existing_token(self): Token.update_count({"token": "existing", "frequency": 2}, self.enc) initial_count = Token.select().count() count = {"token": "existing", "frequency": 5} Token.update_count(count, self.enc) final_count = Token.select().count() assert initial_count == final_count entry = Token.get(Token.hash == self.enc.salted_hash("existing")) assert entry.frequency == 7
def test_decrypt(self): count = {"token": "Sparta", "frequency": 5} token = Token.update_count(count, self.enc) decrypted = token.decrypt(self.enc) assert token.encrypted != decrypted["token"] assert self.enc.decrypt(token.encrypted) == decrypted["token"] assert token.frequency == decrypted["frequency"]