Fixed label cache logic and added to UTs

This commit is contained in:
Shay Nehmad 2019-10-02 17:53:43 +03:00
parent 063a136048
commit 70daf4bfbf
2 changed files with 11 additions and 0 deletions

View File

@ -115,6 +115,7 @@ class Monkey(Document):
self.hostname = hostname
self.save()
Monkey.get_hostname_by_id.delete(self.id)
Monkey.get_label_by_id.delete(self.id)
def get_network_info(self):
"""

View File

@ -140,6 +140,16 @@ class TestMonkey(IslandTestCase):
cache_info_after_query = Monkey.get_label_by_id.storage.backend.cache_info()
self.assertEquals(cache_info_after_query.hits, 1)
linux_monkey.set_hostname("Another hostname")
# should be a miss
label = Monkey.get_label_by_id(linux_monkey.id)
cache_info_after_second_query = Monkey.get_label_by_id.storage.backend.cache_info()
# still 1 hit only
self.assertEquals(cache_info_after_second_query.hits, 1)
self.assertEquals(cache_info_after_second_query.misses, 2)
def test_is_monkey(self):
self.fail_if_not_testing_env()
self.clean_monkey_db()