Пример #1
0
    def test_lowercase_value(self):
        value = "TEST"
        expected_value = "test"
        self.assertEqual(expected_value, lowercase_value(value=value))

        value = ["testA", "TESTb", "TESTC"]
        expected_value = ["testa", "testb", "testc"]
        self.assertEqual(expected_value, lowercase_value(value=value))

        value = {"testA": "testB", "testC": "TESTD", "TESTE": "TESTE"}
        expected_value = {"testa": "testb", "testc": "testd", "teste": "teste"}
        self.assertEqual(expected_value, lowercase_value(value=value))
Пример #2
0
    def test_lowercase_value(self):
        value = 'TEST'
        expected_value = 'test'
        self.assertEqual(expected_value, lowercase_value(value=value))

        value = ['testA', 'TESTb', 'TESTC']
        expected_value = ['testa', 'testb', 'testc']
        self.assertEqual(expected_value, lowercase_value(value=value))

        value = {'testA': 'testB', 'testC': 'TESTD', 'TESTE': 'TESTE'}
        expected_value = {'testa': 'testb', 'testc': 'testd', 'teste': 'teste'}
        self.assertEqual(expected_value, lowercase_value(value=value))
Пример #3
0
def search_pack_index(query, exclude=None, priority=None, case_sensitive=True, proxy_config=None):
    """
    Search the pack index by query.
    Returns a list of matches for a query.
    """
    if not query:
        raise ValueError('Query must be specified.')

    if not exclude:
        exclude = EXCLUDE_FIELDS
    if not priority:
        priority = SEARCH_PRIORITY

    if not case_sensitive:
        query = str(query).lower()

    index, _ = fetch_pack_index(proxy_config=proxy_config)

    matches = [[] for i in range(len(priority) + 1)]
    for pack in six.itervalues(index):
        for key, value in six.iteritems(pack):
            if not hasattr(value, '__contains__'):
                value = str(value)

            if not case_sensitive:
                value = lowercase_value(value=value)

            if key not in exclude and query in value:
                if key in priority:
                    matches[priority.index(key)].append(pack)
                else:
                    matches[-1].append(pack)
                break

    return list(itertools.chain.from_iterable(matches))
Пример #4
0
def search_pack_index(query, exclude=None, priority=None, case_sensitive=True):
    """
    Search the pack index by query.
    Returns a list of matches for a query.
    """
    if not query:
        raise ValueError('Query must be specified.')

    if not exclude:
        exclude = EXCLUDE_FIELDS
    if not priority:
        priority = SEARCH_PRIORITY

    if not case_sensitive:
        query = str(query).lower()

    index, _ = fetch_pack_index()

    matches = [[] for i in range(len(priority) + 1)]
    for pack in six.itervalues(index):
        for key, value in six.iteritems(pack):
            if not hasattr(value, '__contains__'):
                value = str(value)

            if not case_sensitive:
                value = lowercase_value(value=value)

            if key not in exclude and query in value:
                if key in priority:
                    matches[priority.index(key)].append(pack)
                else:
                    matches[-1].append(pack)
                break

    return list(itertools.chain.from_iterable(matches))
Пример #5
0
    def test_lowercase_value(self):
        value = 'TEST'
        expected_value = 'test'
        self.assertEqual(expected_value, lowercase_value(value=value))

        value = ['testA', 'TESTb', 'TESTC']
        expected_value = ['testa', 'testb', 'testc']
        self.assertEqual(expected_value, lowercase_value(value=value))

        value = {
            'testA': 'testB',
            'testC': 'TESTD',
            'TESTE': 'TESTE'
        }
        expected_value = {
            'testa': 'testb',
            'testc': 'testd',
            'teste': 'teste'
        }
        self.assertEqual(expected_value, lowercase_value(value=value))