Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions firestore/google/cloud/firestore_v1beta1/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ def __eq__(self, other):
return self.parts == other.parts
return NotImplemented

def __add__(self, other):
"""Adds `other` field path to end of this field path.

Args:
other (~google.cloud.firestore_v1beta1._helpers.FieldPath, str):
The field path to add to the end of this `FieldPath`.
"""
if isinstance(other, FieldPath):
parts = self.parts + other.parts
return FieldPath(*parts)
elif isinstance(other, six.string_types):
parts = self.parts + FieldPath.from_string(other).parts
return FieldPath(*parts)
else:
return NotImplemented


class FieldPathHelper(object):
"""Helper to convert field names and paths for usage in a request.
Expand Down
17 changes: 17 additions & 0 deletions firestore/tests/unit/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,23 @@ def test_key(self):
else:
self.assertEqual(key, field_path)

def test___add__(self):
path1 = 'a123', 'b456'
path2 = 'c789', 'd012'
path3 = 'c789.d012'
field_path1 = self._make_one(*path1)
field_path1_string = self._make_one(*path1)
field_path2 = self._make_one(*path2)
field_path1 += field_path2
field_path1_string += path3
field_path2 = field_path2 + self._make_one(*path1)
self.assertEqual(field_path1, self._make_one(*(path1 + path2)))
self.assertEqual(field_path2, self._make_one(*(path2 + path1)))
self.assertEqual(field_path1_string, field_path1)
self.assertNotEqual(field_path1, field_path2)
with self.assertRaises(TypeError):
field_path1 + 305


class TestFieldPathHelper(unittest.TestCase):

Expand Down