kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.load: bug fix, handle Object.as1 going from non-None to None
fixes https://console.cloud.google.com/errors/detail/CI3L3MzXjPza9gE;time=P30D?project=bridgy-federatedcircle-datastore-transactions
rodzic
d9cd5d14b9
commit
9d1dc652f9
|
@ -423,6 +423,7 @@ class Protocol:
|
|||
|
||||
if obj:
|
||||
obj.clear()
|
||||
obj.new = False
|
||||
else:
|
||||
logger.info(f' not in datastore')
|
||||
obj = Object(id=id)
|
||||
|
@ -430,9 +431,11 @@ class Protocol:
|
|||
obj.changed = False
|
||||
|
||||
cls.fetch(obj, **kwargs)
|
||||
if orig_as1:
|
||||
obj.new = False
|
||||
obj.changed = as1.activity_changed(orig_as1, obj.as1)
|
||||
if not obj.new:
|
||||
if orig_as1 and obj.as1:
|
||||
obj.changed = as1.activity_changed(orig_as1, obj.as1)
|
||||
else:
|
||||
obj.changed = bool(orig_as1) != bool(obj.as1)
|
||||
|
||||
obj.source_protocol = cls.LABEL
|
||||
obj.put()
|
||||
|
|
|
@ -76,7 +76,7 @@ class ProtocolTest(TestCase):
|
|||
self.assertIsNotNone(Object.get_by_id('foo'))
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
||||
def test_load_already_stored(self):
|
||||
def test_load_existing(self):
|
||||
stored = Object(id='foo', our_as1={'x': 'y'})
|
||||
stored.put()
|
||||
|
||||
|
@ -87,8 +87,7 @@ class ProtocolTest(TestCase):
|
|||
|
||||
self.assertEqual([], Fake.fetched)
|
||||
|
||||
@patch('requests.get')
|
||||
def test_load_empty_deleted(self, mock_get):
|
||||
def test_load_existing_empty_deleted(self):
|
||||
stored = Object(id='foo', deleted=True)
|
||||
stored.put()
|
||||
|
||||
|
@ -99,8 +98,27 @@ class ProtocolTest(TestCase):
|
|||
|
||||
self.assertEqual([], Fake.fetched)
|
||||
|
||||
@patch('requests.get')
|
||||
def test_load_refresh_unchanged(self, mock_get):
|
||||
def test_load_refresh_existing_empty(self):
|
||||
Fake.objects['foo'] = {'x': 'y'}
|
||||
Object(id='foo').put()
|
||||
|
||||
loaded = Fake.load('foo', refresh=True)
|
||||
self.assertEqual({'x': 'y'}, loaded.as1)
|
||||
self.assertTrue(loaded.changed)
|
||||
self.assertFalse(loaded.new)
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
||||
def test_load_refresh_new_empty(self):
|
||||
Fake.objects['foo'] = None
|
||||
Object(id='foo', our_as1={'x': 'y'}).put()
|
||||
|
||||
loaded = Fake.load('foo', refresh=True)
|
||||
self.assertIsNone(loaded.as1)
|
||||
self.assertTrue(loaded.changed)
|
||||
self.assertFalse(loaded.new)
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
||||
def test_load_refresh_unchanged(self):
|
||||
obj = Object(id='foo', our_as1={'x': 'stored'})
|
||||
obj.put()
|
||||
Fake.objects['foo'] = {'x': 'stored'}
|
||||
|
@ -111,8 +129,7 @@ class ProtocolTest(TestCase):
|
|||
self.assertFalse(obj.new)
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
||||
@patch('requests.get')
|
||||
def test_load_refresh_changed(self, mock_get):
|
||||
def test_load_refresh_changed(self):
|
||||
Object(id='foo', our_as1={'content': 'stored'}).put()
|
||||
Fake.objects['foo'] = {'content': 'new'}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue