'Test json filter more thoroughly.'

def test_json_filter_happy_day(self):

    filt_cls = self.class_map['JsonFilter']()
    raw = ['and', '$capabilities.enabled', ['=', '$capabilities.opt1', 'match'], ['or', ['and', ['<', '$free_ram_mb', 30], ['<', '$free_disk_mb', 300]], ['and', ['>', '$free_ram_mb', 30], ['>', '$free_disk_mb', 300]]]]
    filter_properties = {'scheduler_hints': {'query': jsonutils.dumps(raw)}, 'request_spec': {'volume_id': fake.VOLUME_ID}}
    capabilities = {'enabled': True, 'opt1': 'match'}
    service = {'disabled': False}
    host = fakes.FakeBackendState('host1', {'free_ram_mb': 10, 'free_disk_mb': 200, 'capabilities': capabilities, 'service': service})
    self.assertTrue(filt_cls.backend_passes(host, filter_properties))
    capabilities = {'enabled': True, 'opt1': 'match'}
    service = {'disabled': False}
    host = fakes.FakeBackendState('host1', {'free_ram_mb': 40, 'free_disk_mb': 400, 'capabilities': capabilities, 'service': service})
    self.assertTrue(filt_cls.backend_passes(host, filter_properties))
    capabilities = {'enabled': False, 'opt1': 'match'}
    service = {'disabled': False}
    host = fakes.FakeBackendState('host1', {'free_ram_mb': 40, 'free_disk_mb': 400, 'capabilities': capabilities, 'service': service})
    self.assertFalse(filt_cls.backend_passes(host, filter_properties))
    capabilities = {'enabled': True, 'opt1': 'match'}
    service = {'disabled': False}
    host = fakes.FakeBackendState('host1', {'free_ram_mb': 30, 'free_disk_mb': 300, 'capabilities': capabilities, 'service': service})
    self.assertFalse(filt_cls.backend_passes(host, filter_properties))
    capabilities = {'enabled': True, 'opt1': 'match'}
    service = {'disabled': False}
    host = fakes.FakeBackendState('host1', {'free_ram_mb': 20, 'free_disk_mb': 400, 'capabilities': capabilities, 'service': service})
    self.assertFalse(filt_cls.backend_passes(host, filter_properties))
    capabilities = {'enabled': True, 'opt1': 'no-match'}
    service = {'enabled': True}
    host = fakes.FakeBackendState('host1', {'free_ram_mb': 20, 'free_disk_mb': 400, 'capabilities': capabilities, 'service': service})
    self.assertFalse(filt_cls.backend_passes(host, filter_properties))
