8000 Temporarily removing the get_if_changed() method from db public API by hiranya911 · Pull Request #67 · firebase/firebase-admin-python · GitHub
[go: up one dir, main page]

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
30 changes: 15 additions & 15 deletions firebase_admin/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def get(self, etag=False):

Returns:
object: If etag is False returns the decoded JSON value of the current database location.
If etag is True, returns a 2-tuple consisting of the decoded JSON value and the Etag
associated with the current database location.
If etag is True, returns a 2-tuple consisting of the decoded JSON value and the Etag
associated with the current database location.

Raises:
ApiCallError: If an error occurs while communicating with the remote database server.
Expand All @@ -147,7 +147,7 @@ def get(self, etag=False):
else:
return self._client.body('get', self._add_suffix())

def get_if_changed(self, etag):
def _get_if_changed(self, etag):
"""Gets data in this location only if the specified ETag does not match.

Args:
Expand Down Expand Up @@ -193,17 +193,17 @@ def set(self, value):
def set_if_unchanged(self, expected_etag, value):
"""Conditonally sets the data at this location to the given value.

Sets the data at this location to the given value, only if expected_etag is same as the
Sets the data at this location to the given value only if ``expected_etag`` is same as the
ETag value in the database.

Args:
expected_etag: Value of ETag we want to check.
value: JSON-serializable value to be set at this location.

Returns:
object: A 3-tuple consisting of a boolean, a decoded JSON value and an ETag. The boolean
indicates whether the set operation was successful or not. The decoded JSON and the
ETag corresponds to the latest value in this database location.
tuple: A 3-tuple consisting of a boolean, a decoded JSON value and an ETag. The boolean
indicates whether the set operation was successful or not. The decoded JSON and the
ETag corresponds to the latest value in this database location.

Raises:
ValueError: If the value is None, or if expected_etag is not a string.
Expand Down Expand Up @@ -291,18 +291,18 @@ def transaction(self, transaction_update):
returning a value.

Args:
transaction_update: A function which will be passed the current data stored at this
location. The function should return the new value it would like written. If
an exception is raised, the transaction will be aborted, and the data at this
location will not be modified. The exceptions raised by this function are
propagated to the caller of the transaction method.
transaction_update: A function which will be passed the current data stored at this
location. The function should return the new value it would like written. If
an exception is raised, the transaction will be aborted, and the data at this
location will not be modified. The exceptions raised by this function are
propagated to the caller of the transaction method.

Returns:
object: New value of the current database Reference (only if the transaction commits).
object: New value of the current database Reference (only if the transaction commits).

Raises:
TransactionError: If the transaction aborts after exhausting all retry attempts.
ValueError: If transaction_update is not a function.
TransactionError: If the transaction aborts after exhausting all retry attempts.
ValueError: If transaction_update is not a function.
"""
if not callable(transaction_update):
raise ValueError('transaction_update must be a function.')
Expand Down
2 changes: 1 addition & 1 deletion integration/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_get_value_and_etag(self, testref, testdata):
assert isinstance(etag, six.string_types)

def test_get_if_changed(self, testref, testdata):
success, data, etag = testref.get_if_changed('wrong_etag')
success, data, etag = testref._get_if_changed('wrong_etag')
assert success is True
assert data == testdata
assert isinstance(etag, six.string_types)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ def test_get_if_changed(self, data):
ref = db.reference('/test')
recorder = self.instrument(ref, json.dumps(data))

assert ref.get_if_changed('invalid-etag') == (True, data, MockAdapter.ETAG)
assert ref._get_if_changed('invalid-etag') == (True, data, MockAdapter.ETAG)
assert len(recorder) == 1
assert recorder[0].method == 'GET'
assert recorder[0].url == 'https://test.firebaseio.com/test.json'
assert recorder[0].headers['if-none-match'] == 'invalid-etag'

assert ref.get_if_changed(MockAdapter.ETAG) == (False, None, None)
assert ref._get_if_changed(MockAdapter.ETAG) == (False, None, None)
assert len(recorder) == 2
assert recorder[1].method == 'GET'
assert recorder[1].url == 'https://test.firebaseio.com/test.json'
Expand All @@ -176,7 +176,7 @@ def test_get_if_changed(self, data):
def test_get_if_changed_invalid_etag(self, etag):
ref = db.reference('/test')
with pytest.raises(ValueError):
ref.get_if_changed(etag)
ref._get_if_changed(etag)

@pytest.mark.parametrize('data', valid_values)
def test_order_by_query(self, data):
Expand Down
0