How to use the cloudant.result.ResultByKey function in cloudant

To help you get started, we’ve selected a few cloudant examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
self.assertEqual(result['julia097': 'ruby'], expected)
        self.assertEqual(
            result['julia098': 'julia098'],
            [{'key': 'julia098', 'id': 'julia098', 'value': 1}]
        )
        self.assertEqual(result['bar': 'foo'], [])

        result = Result(self.view003)
        expected = [{'key': 47, 'id': 'julia094', 'value': 1},
                    {'key': 47, 'id': 'julia095', 'value': 1},
                    {'key': 48, 'id': 'julia096', 'value': 1},
                    {'key': 48, 'id': 'julia097', 'value': 1},
                    {'key': 49, 'id': 'julia098', 'value': 1},
                    {'key': 49, 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[ResultByKey(47): ResultByKey(49)], expected)
        self.assertEqual(result[ResultByKey(47): ResultByKey(52)], expected)
        self.assertEqual(
            result[ResultByKey(48): ResultByKey(48)],
            [{'key': 48, 'id': 'julia096', 'value': 1}, {'key': 48, 'id': 'julia097', 'value': 1}]
        )
        self.assertEqual(result[ResultByKey(52): ResultByKey(54)], [])

        result = Result(self.view005)
        expected = [{'key': ['julia', 97], 'id': 'julia097', 'value': 1},
                    {'key': ['julia', 98], 'id': 'julia098', 'value': 1},
                    {'key': ['julia', 99], 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[['julia', 97]: ['julia', 99]], expected)
        self.assertEqual(
            result[ResultByKey(['julia', 97]): ResultByKey(['julia', 99])],
            expected
        )
        self.assertEqual(result[['julia', 97]: ['ruby', 97]], expected)
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
)
        self.assertEqual(result['julia097': 'ruby'], expected)
        self.assertEqual(
            result['julia098': 'julia098'],
            [{'key': 'julia098', 'id': 'julia098', 'value': 1}]
        )
        self.assertEqual(result['bar': 'foo'], [])

        result = Result(self.view003)
        expected = [{'key': 47, 'id': 'julia094', 'value': 1},
                    {'key': 47, 'id': 'julia095', 'value': 1},
                    {'key': 48, 'id': 'julia096', 'value': 1},
                    {'key': 48, 'id': 'julia097', 'value': 1},
                    {'key': 49, 'id': 'julia098', 'value': 1},
                    {'key': 49, 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[ResultByKey(47): ResultByKey(49)], expected)
        self.assertEqual(result[ResultByKey(47): ResultByKey(52)], expected)
        self.assertEqual(
            result[ResultByKey(48): ResultByKey(48)],
            [{'key': 48, 'id': 'julia096', 'value': 1}, {'key': 48, 'id': 'julia097', 'value': 1}]
        )
        self.assertEqual(result[ResultByKey(52): ResultByKey(54)], [])

        result = Result(self.view005)
        expected = [{'key': ['julia', 97], 'id': 'julia097', 'value': 1},
                    {'key': ['julia', 98], 'id': 'julia098', 'value': 1},
                    {'key': ['julia', 99], 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[['julia', 97]: ['julia', 99]], expected)
        self.assertEqual(
            result[ResultByKey(['julia', 97]): ResultByKey(['julia', 99])],
            expected
        )
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
def test_get_item_by_missing_integer_key(self):
        """
        Test retrieving a result using an integer value that refers to a key
        that does not exist in the result.
        """
        result = Result(self.view003)
        self.assertEqual(result[ResultByKey(99)], [])
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
def test_get_item_by_key(self):
        """
        Test retrieving a result using value that refers to a key of the
        result.
        """
        result = Result(self.view001)
        expected = [{'key': 'julia010', 'id': 'julia010', 'value': 1}]
        self.assertEqual(result['julia010'], expected)
        self.assertEqual(result[ResultByKey('julia010')], expected)
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
expected = [{'key': 'julia097', 'id': 'julia097', 'value': 1},
                    {'key': 'julia098', 'id': 'julia098', 'value': 1},
                    {'key': 'julia099', 'id': 'julia099', 'value': 1}]
        self.assertEqual(result['julia097':], expected)
        self.assertEqual(result[ResultByKey('julia097'):], expected)
        self.assertEqual(result['ruby':], [])

        result = Result(self.view003)
        expected = [{'key': 47, 'id': 'julia094', 'value': 1},
                    {'key': 47, 'id': 'julia095', 'value': 1},
                    {'key': 48, 'id': 'julia096', 'value': 1},
                    {'key': 48, 'id': 'julia097', 'value': 1},
                    {'key': 49, 'id': 'julia098', 'value': 1},
                    {'key': 49, 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[ResultByKey(47):], expected)
        self.assertEqual(result[ResultByKey(52):], [])

        result = Result(self.view005)
        expected = [{'key': ['julia', 97], 'id': 'julia097', 'value': 1},
                    {'key': ['julia', 98], 'id': 'julia098', 'value': 1},
                    {'key': ['julia', 99], 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[['julia', 97]:], expected)
        self.assertEqual(result[ResultByKey(['julia', 97]):], expected)
        self.assertEqual(result[ResultByKey(['ruby', 'foo']):], [])
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
result['julia098': 'julia098'],
            [{'key': 'julia098', 'id': 'julia098', 'value': 1}]
        )
        self.assertEqual(result['bar': 'foo'], [])

        result = Result(self.view003)
        expected = [{'key': 47, 'id': 'julia094', 'value': 1},
                    {'key': 47, 'id': 'julia095', 'value': 1},
                    {'key': 48, 'id': 'julia096', 'value': 1},
                    {'key': 48, 'id': 'julia097', 'value': 1},
                    {'key': 49, 'id': 'julia098', 'value': 1},
                    {'key': 49, 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[ResultByKey(47): ResultByKey(49)], expected)
        self.assertEqual(result[ResultByKey(47): ResultByKey(52)], expected)
        self.assertEqual(
            result[ResultByKey(48): ResultByKey(48)],
            [{'key': 48, 'id': 'julia096', 'value': 1}, {'key': 48, 'id': 'julia097', 'value': 1}]
        )
        self.assertEqual(result[ResultByKey(52): ResultByKey(54)], [])

        result = Result(self.view005)
        expected = [{'key': ['julia', 97], 'id': 'julia097', 'value': 1},
                    {'key': ['julia', 98], 'id': 'julia098', 'value': 1},
                    {'key': ['julia', 99], 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[['julia', 97]: ['julia', 99]], expected)
        self.assertEqual(
            result[ResultByKey(['julia', 97]): ResultByKey(['julia', 99])],
            expected
        )
        self.assertEqual(result[['julia', 97]: ['ruby', 97]], expected)
        self.assertEqual(
            result[['julia', 98]: ['julia', 98]],
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
def test_get_item_by_integer_key(self):
        """
        Test retrieving a result using an integer value that refers to a key of
        the result.
        """
        result = Result(self.view003)
        expected = [{'key': 10, 'id': 'julia020', 'value': 1},
                    {'key': 10, 'id': 'julia021', 'value': 1}]
        self.assertEqual(result[ResultByKey(10)], expected)
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
def test_get_item_by_missing_key(self):
        """
        Test retrieving a result using value that refers to a key that does not
        exist in the result.
        """
        result = Result(self.view001)
        self.assertEqual(result['ruby010'], [])
        self.assertEqual(result[ResultByKey('ruby010')], [])
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
self.assertEqual(result['bar': 'foo'], [])

        result = Result(self.view003)
        expected = [{'key': 47, 'id': 'julia094', 'value': 1},
                    {'key': 47, 'id': 'julia095', 'value': 1},
                    {'key': 48, 'id': 'julia096', 'value': 1},
                    {'key': 48, 'id': 'julia097', 'value': 1},
                    {'key': 49, 'id': 'julia098', 'value': 1},
                    {'key': 49, 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[ResultByKey(47): ResultByKey(49)], expected)
        self.assertEqual(result[ResultByKey(47): ResultByKey(52)], expected)
        self.assertEqual(
            result[ResultByKey(48): ResultByKey(48)],
            [{'key': 48, 'id': 'julia096', 'value': 1}, {'key': 48, 'id': 'julia097', 'value': 1}]
        )
        self.assertEqual(result[ResultByKey(52): ResultByKey(54)], [])

        result = Result(self.view005)
        expected = [{'key': ['julia', 97], 'id': 'julia097', 'value': 1},
                    {'key': ['julia', 98], 'id': 'julia098', 'value': 1},
                    {'key': ['julia', 99], 'id': 'julia099', 'value': 1}]
        self.assertEqual(result[['julia', 97]: ['julia', 99]], expected)
        self.assertEqual(
            result[ResultByKey(['julia', 97]): ResultByKey(['julia', 99])],
            expected
        )
        self.assertEqual(result[['julia', 97]: ['ruby', 97]], expected)
        self.assertEqual(
            result[['julia', 98]: ['julia', 98]],
            [{'key': ['julia', 98], 'id': 'julia098', 'value': 1}]
        )
        self.assertEqual(result[['ruby', 'bar']: ['ruby', 'foo']], [])
github cloudant / python-cloudant / tests / unit / result_tests.py View on Github external
def test_get_item_key_slice_using_start_stop(self):
        """
        Test getting a key slice by using start and stop slice values.
        """
        result = Result(self.view001)
        expected = [{'key': 'julia097', 'id': 'julia097', 'value': 1},
                    {'key': 'julia098', 'id': 'julia098', 'value': 1},
                    {'key': 'julia099', 'id': 'julia099', 'value': 1}]
        self.assertEqual(result['julia097': 'julia099'], expected)
        self.assertEqual(
            result[ResultByKey('julia097'): ResultByKey('julia099')],
            expected
        )
        self.assertEqual(result['julia097': 'ruby'], expected)
        self.assertEqual(
            result['julia098': 'julia098'],
            [{'key': 'julia098', 'id': 'julia098', 'value': 1}]
        )
        self.assertEqual(result['bar': 'foo'], [])

        result = Result(self.view003)
        expected = [{'key': 47, 'id': 'julia094', 'value': 1},
                    {'key': 47, 'id': 'julia095', 'value': 1},
                    {'key': 48, 'id': 'julia096', 'value': 1},
                    {'key': 48, 'id': 'julia097', 'value': 1},
                    {'key': 49, 'id': 'julia098', 'value': 1},
                    {'key': 49, 'id': 'julia099', 'value': 1}]