def search(search_type, term, value): data = search_data(search_type, term, value) map_search_type = { SearchType.USER.value: 'users', SearchType.ORGANIZATION.value: 'organizations', SearchType.TICKET.value: 'tickets' } click.echo('Searching %s for "%s" with a value of "%s"\n' % (map_search_type.get(search_type), term, value)) for item in data: click.echo(item) if not data: click.echo('No results found')
def test_search_organizations_tags(self): result = search_data(SearchType.ORGANIZATION.value, 'tags', '["Erickson", "Mccoy", "Wiggins", "Brooks"]', pretty_print=False) self.assertEqual(len(result), 1)
def test_search_organizations_string(self): result = search_data(SearchType.ORGANIZATION.value, 'name', "Qualitern", pretty_print=False) self.assertEqual(len(result), 1)
def test_search_organizations_boolean(self): result = search_data(SearchType.ORGANIZATION.value, 'shared_tickets', False, pretty_print=False) self.assertEqual(len(result), 2)
def test_search_organizations_not_found(self): result = search_data(SearchType.ORGANIZATION.value, '_id', 1000) self.assertEqual(len(result), 0)
def test_search_organizations_exist(self): result = search_data(SearchType.ORGANIZATION.value, '_id', 106) self.assertEqual(len(result), 1)
def test_search_tickets_empty_string(self): result = search_data(SearchType.TICKET.value, 'description', "") self.assertEqual(len(result), 1)
def test_search_users_not_found(self): result = search_data(SearchType.USER.value, '_id', 2000) self.assertEqual(len(result), 0)
def test_search_tickets_boolean(self): result = search_data(SearchType.TICKET.value, 'has_incidents', True) self.assertEqual(len(result), 1)
def test_search_tickets_not_found(self): result = search_data(SearchType.TICKET.value, '_id', "abc") self.assertEqual(len(result), 0)
def test_search_tickets_exist(self): result = search_data(SearchType.TICKET.value, '_id', "fc5a8a70-3814-4b17-a6e9-583936fca909") self.assertEqual(len(result), 1)
def test_search_users_empty_string(self): result = search_data(SearchType.USER.value, 'alias', "") self.assertEqual(len(result), 1)
def test_search_users_string(self): result = search_data(SearchType.USER.value, 'locale', "en-AU") self.assertEqual(len(result), 1)
def test_search_users_boolean(self): result = search_data(SearchType.USER.value, 'suspended', False) self.assertEqual(len(result), 3)
def test_search_organizations_empty_string(self): result = search_data(SearchType.ORGANIZATION.value, 'details', '', pretty_print=False) self.assertEqual(len(result), 1)
def test_search_tickets_string(self): result = search_data(SearchType.TICKET.value, 'type', "problem") self.assertEqual(len(result), 1)
def test_search_users_exist(self): result = search_data(SearchType.USER.value, '_id', 75) self.assertEqual(len(result), 0)