def test_list(self, expired, query): self.app.cache = Cache(self.app, config={'CACHE_TYPE': 'null'}) service = 'foo' query.return_value = [] expired.return_value = False host = self._new_host_service() hosts = host.list(service) expected = [] assert hosts == expected host1 = type('lamdbaobject', (object,), {})() host1.service = service host1.ip_address = '10.10.10.10' host1.service_repo_name = 'bar' host1.port = 80 host1.revision = 'abc123' host1.last_check_in = datetime.utcnow() host1.tags = self._generate_valid_tags() host2 = type('lamdbaobject', (object,), {})() host2.service = service host2.ip_address = '10.10.10.11' host2.service_repo_name = 'bar' host2.port = 80 host2.revision = 'abc123' host2.last_check_in = datetime.utcnow() host2.tags = self._generate_valid_tags() query.return_value = [ host1, host2 ] host = self._new_host_service() hosts = host.list(service) expected = [ { 'service': host1.service, 'last_check_in': host1.last_check_in, 'ip_address': host1.ip_address, 'service_repo_name': host1.service_repo_name, 'port': host1.port, 'revision': host1.revision, 'tags': host1.tags }, { 'service': host2.service, 'last_check_in': host2.last_check_in, 'ip_address': host2.ip_address, 'service_repo_name': host2.service_repo_name, 'port': host2.port, 'revision': host2.revision, 'tags': host2.tags } ] assert hosts == expected
def test_sweeper(self, query): # have query return hosts, some of which are expired # verify that the expired hosts are not returned service = 'foo' host = self._new_host_service() host1 = type('lamdbaobject', (object,), {})() host1.service = service host1.ip_address = '10.10.10.10' host1.service_repo_name = 'bar' host1.port = 80 host1.revision = 'abc123' host1.last_check_in = datetime.today() - timedelta(days=365) # this host is expired host1.tags = self._generate_valid_tags() host1.delete = self.noop host2 = type('lamdbaobject', (object,), {})() host2.service = service host2.ip_address = '10.10.10.11' host2.service_repo_name = 'bar' host2.port = 80 host2.revision = 'abc123' host2.last_check_in = datetime.utcnow() host2.tags = self._generate_valid_tags() host2.delete = self.noop query.return_value = [ host1, host2 ] hosts = host.list(service) expected = [ { 'service': host2.service, 'last_check_in': host2.last_check_in, 'ip_address': host2.ip_address, 'service_repo_name': host2.service_repo_name, 'port': host2.port, 'revision': host2.revision, 'tags': host2.tags } ] assert hosts == expected