From 25a35f470f597eba8479cc0178193ac963ee6350 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Sat, 30 Sep 2017 01:59:44 -0300 Subject: [bug] set as PROCESSING during processing flow It was previously setting to PROCESSED. Also added some tests to check if the underlying wrapped calls matches the intent. -- Resolves: #8955 --- src/leap/soledad/client/incoming.py | 2 +- tests/client/test_incoming_processing_flow.py | 52 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/leap/soledad/client/incoming.py b/src/leap/soledad/client/incoming.py index 42522303..aa7065e8 100644 --- a/src/leap/soledad/client/incoming.py +++ b/src/leap/soledad/client/incoming.py @@ -131,7 +131,7 @@ class IncomingBox: :rtype: Deferred """ try: - yield self.blob_manager.set_flags(blob_id, [Flags.PROCESSED], + yield self.blob_manager.set_flags(blob_id, [Flags.PROCESSING], namespace=self.namespace) except: defer.returnValue(None) diff --git a/tests/client/test_incoming_processing_flow.py b/tests/client/test_incoming_processing_flow.py index 7bc1e3c6..ec5bd717 100644 --- a/tests/client/test_incoming_processing_flow.py +++ b/tests/client/test_incoming_processing_flow.py @@ -20,6 +20,8 @@ Unit tests for incoming box processing flow. from mock import Mock, call from leap.soledad.client import interfaces from leap.soledad.client.incoming import IncomingBoxProcessingLoop +from leap.soledad.client.incoming import IncomingBox +from leap.soledad.common.blobs import Flags from twisted.internet import defer from twisted.trial import unittest from zope.interface import implementer @@ -195,3 +197,53 @@ class IncomingBoxProcessingTestCase(unittest.TestCase): self.loop.add_consumer(consumer) yield self.loop() self.box.set_failed.assert_has_calls([call(x) for x in items]) + + +class IncomingBoxCase(unittest.TestCase): + """ + IncomingBox is just a wrapper for some operations on blob manager. This + test case checks if the underlying operations are implemented as intended. + """ + + def setUp(self): + self.manager = Mock() + self.namespace = 'mynamespace' + self.box = IncomingBox(self.manager, 'mynamespace') + + @defer.inlineCallbacks + def test_fetch_for_processing_marks_as_processing(self): + self.manager.set_flags.return_value = defer.succeed(None) + some_blob = Mock() + self.manager.get.return_value = defer.succeed(some_blob) + yield self.box.fetch_for_processing('some_blob') + + self.manager.set_flags.assert_called_with( + 'some_blob', [Flags.PROCESSING], namespace=self.namespace) + + @defer.inlineCallbacks + def test_fetch_for_processing_returns_blob_when_set_flag_succeeds(self): + self.manager.set_flags.return_value = defer.succeed(None) + some_blob = Mock() + self.manager.get.return_value = defer.succeed(some_blob) + + result = yield self.box.fetch_for_processing('some_blob') + self.assertEquals(result, some_blob) + self.manager.get.assert_called_with( + 'some_blob', namespace=self.namespace) + + @defer.inlineCallbacks + def test_fetch_for_processing_returns_None_when_flag_fails(self): + self.manager.set_flags.return_value = defer.fail(Exception()) + some_blob = Mock() + self.manager.get.return_value = defer.succeed(some_blob) + + result = yield self.box.fetch_for_processing('some_blob') + self.assertEquals(result, None) + + @defer.inlineCallbacks + def test_list_pending_asks_for_oldest_pending_flagged_blobs_by_date(self): + yield self.box.list_pending() + self.manager.remote_list.assert_called_with( + namespace=self.namespace, + order_by='+date', + filter_flag=Flags.PENDING) -- cgit v1.2.3