def test_get_last_granule(self, mock_bb, dsm_cli, dsm): mock_bb().sync_rdt_with_coverage = Mock() mock_bb().to_granule.return_value = {'test':True} dsm_cli().read_dataset = Mock() dataset = DotDict() dataset.datastore_name = 'test' dataset.view_name = 'bogus/view' dsm._get_coverage = Mock() dsm._get_coverage.return_value = {} datastore = DotDict() datastore.query_view = Mock() datastore.query_view.return_value = [{'doc':{'ts_create':0}}] container = DotDict() container.datastore_manager.get_datastore = Mock() container.datastore_manager.get_datastore.return_value = datastore retval = self.replay.get_last_granule(container,'dataset_id') self.assertEquals(retval,{'test':True})
def test_execute_replay(self): datastore = DotDict() container = DotDict() datastore.query_view = Mock() container.datastore_manager.get_datastore = Mock() container.datastore_manager.get_datastore.return_value = datastore mock_data = msgpack.packb({'test':'test'},default=encode_ion) self.received_packet = False self.end_stream = False def output_test(packet): self.assertIsInstance(packet,dict) if packet == {'test':'test'}: self.received_packet = True if packet == {}: self.end_stream = True self.replay.output.publish.side_effect = output_test result = DotDict() result.doc.sha1 = 'sha1' result.doc.encoding = 'test' datastore.query_view.return_value = [result] self.replay.container = container self.replay.read_persisted_cache = Mock() self.replay.read_persisted_cache.return_value = mock_data retval = self.replay.execute_replay() self.assertTrue(retval) self.assertTrue(self.received_packet) self.assertTrue(self.end_stream)