示例#1
0
    def field_path(*field_names):
        """Create a **field path** from a list of nested field names.

        A **field path** is a ``.``-delimited concatenation of the field
        names. It is used to represent a nested field. For example,
        in the data

        .. code-block:: python

           data = {
              'aa': {
                  'bb': {
                      'cc': 10,
                  },
              },
           }

        the field path ``'aa.bb.cc'`` represents the data stored in
        ``data['aa']['bb']['cc']``.

        Args:
            field_names (Tuple[str, ...]): The list of field names.

        Returns:
            str: The ``.``-delimited field path.
        """
        return _helpers.get_field_path(field_names)
示例#2
0
    def field_path(*field_names):
        """Create a **field path** from a list of nested field names.

        A **field path** is a ``.``-delimited concatenation of the field
        names. It is used to represent a nested field. For example,
        in the data

        .. code-block:: python

           data = {
              'aa': {
                  'bb': {
                      'cc': 10,
                  },
              },
           }

        the field path ``'aa.bb.cc'`` represents the data stored in
        ``data['aa']['bb']['cc']``.

        Args:
            field_names (Tuple[str, ...]): The list of field names.

        Returns:
            str: The ``.``-delimited field path.
        """
        return _helpers.get_field_path(field_names)
    def test_path_end_conflict_one_match(self):
        from google.cloud.firestore_v1beta1 import _helpers

        helper = self._make_one(None)
        key = 'end'
        conflicting_paths = {key: helper.PATH_END}
        field_path = 'start'
        err_val = helper.path_end_conflict(field_path, conflicting_paths)
        self.assertIsInstance(err_val, ValueError)
        conflict = _helpers.get_field_path([field_path, key])
        err_msg = helper.FIELD_PATH_CONFLICT.format(field_path, conflict)
        self.assertEqual(err_val.args, (err_msg,))
    def test_path_end_conflict_multiple_matches(self):
        from google.cloud.firestore_v1beta1 import _helpers

        helper = self._make_one(None)
        # "Cheat" and use OrderedDict-s so that iteritems() is deterministic.
        end_part = 'end'
        sub_paths = collections.OrderedDict((
            (end_part, helper.PATH_END),
        ))
        middle_part = 'middle'
        conflicting_paths = collections.OrderedDict((
            (middle_part, sub_paths),
            ('nope', helper.PATH_END),
        ))

        field_path = 'start'
        err_val = helper.path_end_conflict(field_path, conflicting_paths)
        self.assertIsInstance(err_val, ValueError)
        conflict = _helpers.get_field_path([field_path, middle_part, end_part])
        err_msg = helper.FIELD_PATH_CONFLICT.format(field_path, conflict)
        self.assertEqual(err_val.args, (err_msg,))
    def _call_fut(field_names):
        from google.cloud.firestore_v1beta1._helpers import get_field_path

        return get_field_path(field_names)