Skip to content

Re-enabling the get_if_changed() method #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 8, 2017
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
2 changes: 1 addition & 1 deletion firebase_admin/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions integration/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ 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)
# TODO: Server API seems to be misbehaving in the following case.
# TODO: Re-enable once fixed.
#assert testref.get_if_changed(etag) == (False, None, None)
assert testref.get_if_changed(etag) == (False, None, None)

def test_get_child_value(self, testref, testdata):
child = testref.child('dinosaurs')
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