diff --git a/monkey/monkey_island/cc/models/monkey_test.py b/monkey/monkey_island/cc/models/test_monkey.py similarity index 81% rename from monkey/monkey_island/cc/models/monkey_test.py rename to monkey/monkey_island/cc/models/test_monkey.py index 6115386ea..d0b5efd71 100644 --- a/monkey/monkey_island/cc/models/monkey_test.py +++ b/monkey/monkey_island/cc/models/test_monkey.py @@ -112,3 +112,30 @@ class TestMonkey(IslandTestCase): and linux_monkey not in tunneled_monkeys and len(tunneled_monkeys) == 2) self.assertTrue(test, "Tunneling test") + + def test_get_label_by_id(self): + self.fail_if_not_testing_env() + self.clean_monkey_db() + + hostname_example = "a_hostname" + ip_example = "1.1.1.1" + linux_monkey = Monkey(guid=str(uuid.uuid4()), + description="Linux shay-Virtual-Machine", + hostname=hostname_example, + ip_addresses=[ip_example]) + linux_monkey.save() + + cache_info_before_query = Monkey.get_label_by_id.storage.backend.cache_info() + self.assertEquals(cache_info_before_query.hits, 0) + + # not cached + label = Monkey.get_label_by_id(linux_monkey.id) + + self.assertIsNotNone(label) + self.assertIn(hostname_example, label) + self.assertIn(ip_example, label) + + # should be cached + _ = Monkey.get_label_by_id(linux_monkey.id) + cache_info_after_query = Monkey.get_label_by_id.storage.backend.cache_info() + self.assertEquals(cache_info_after_query.hits, 1)