def create_pumps(obj): """ """ term = SearchTerm.objects.get(pk=1) obj.query = ReservoirQuery(searchterms=[term]) reservoir = Reservoir.objects.get(name='twitter') obj.stream_pump = Pump(reservoir=reservoir, task=BKGD_SRCH) obj.nonstream_pump = Pump(reservoir=reservoir, task=ADHOC_SRCH)
def setUp(self): term = SearchTerm.objects.get(pk=1) self.query = ReservoirQuery(searchterms=[term]) self.subquery1 = Mock() self.subquery2 = Mock() self.query_list = [self.subquery1, self.subquery2] reservoir = Reservoir.objects.get(name='twitter') self.stream_pump = Pump(reservoir=reservoir, task='BKGD_SRCH') self.nonstream_pump = Pump(reservoir=reservoir, task='ADHOC_SRCH') self.task1 = 'BKGD_SRCH' self.task2 = 'ADHOC_SRCH' self.task3 = 'FAKE_TASK'
def test_with_missing_specsheet(self): """ Tests the _pipe property for a Pipe doesn't exist. """ reservoir = Reservoir.objects.get(name='facebook') pump = Pump(reservoir=reservoir, task=ADHOC_SRCH) msg = 'The Pipe "Facebook GraphAPI" has no Specsheet' with six.assertRaisesRegex(self, SpecsheetDoesNotExist, msg): pump._specsheet
def test_with_missing_pipe(self): """ Tests the _pipe property for a Pipe doesn't exist. """ reservoir = Reservoir.objects.get(name='twitter') pump = Pump(reservoir=reservoir, task=FAKE_TASK) msg = 'The Reservoir "twitter" has no Pipe for the Task "FAKE_TASK"' with six.assertRaisesRegex(self, PipeDoesNotExist, msg): pump._pipe
def _create_pump(self, reservoir): """ Takes a Reservoir and creates a Pump to pull data from that Reservoir, appropriate to the PumpRoom's user and task. """ return Pump( reservoir=reservoir, task=self.task, user=self.user, )
class StartPumpBaseTestCase(TransactionTestCase): """ Tests the start method. """ fixtures = get_fixtures( ['plumbers', 'gateways', 'funnels', 'pipes', 'streams', 'searchterms']) def setUp(self): term = SearchTerm.objects.get(pk=1) self.query = ReservoirQuery(searchterms=[term]) self.subquery1 = Mock() self.subquery2 = Mock() self.query_list = [self.subquery1, self.subquery2] reservoir = Reservoir.objects.get(name='twitter') self.stream_pump = Pump(reservoir=reservoir, task='BKGD_SRCH') self.nonstream_pump = Pump(reservoir=reservoir, task='ADHOC_SRCH') self.task1 = 'BKGD_SRCH' self.task2 = 'ADHOC_SRCH' self.task3 = 'FAKE_TASK' @close_old_connections def test_normal_streaming_query(self): """ Tests the start method for a Pump with a streaming Pipe and a query that doesn't exceed the Pipe's specs. """ with LogCapture() as log_capture: self.stream_pump._factor_query = Mock( return_value=[self.subquery1]) self.stream_pump._process_streaming_query = Mock() self.stream_pump.start(self.subquery1) # check that _factor_query() was called with the value that was # passed to start() self.stream_pump._factor_query.assert_called_once_with( self.subquery1) # check that _process_nonstreaming_queries() was called with the # first element of the query list returned by _factor_query() self.stream_pump._process_streaming_query.assert_called_once_with( self.subquery1) log_capture.check() @close_old_connections def test_large_streaming_query(self): """ Tests the start method for a Pump with a streaming Pipe and a query that exceeds the Pipe's specs. """ with LogCapture() as log_capture: self.stream_pump._factor_query = Mock(return_value=self.query_list) self.stream_pump._process_streaming_query = Mock() self.stream_pump.start(self.query) # check that _factor_query() was called with the value that was # passed to start() self.stream_pump._factor_query.assert_called_once_with(self.query) # check that _process_nonstreaming_queries() was called with the # first element of the query list returned by _factor_query() self.stream_pump._process_streaming_query.assert_called_once_with( self.query_list[0]) # check that a warning was generated msg = 'Query was too large for Pipe "Twitter PublicStreamsAPI." ' \ + 'A smaller version of the query was submitted.' log_capture.check(('aggregator.pumproom.pump', 'WARNING', msg), ) @close_old_connections def test_nonstreaming_query(self): """ Tests the start method for a Pump with a non-streaming Pipe and a query that exceeds the Pipe's specs. """ self.nonstream_pump._factor_query = Mock(return_value=self.query_list) self.nonstream_pump._process_nonstreaming_queries = Mock() self.nonstream_pump.start(self.query) # check that _factor_query() was called with the value passed to start() self.nonstream_pump._factor_query.assert_called_once_with(self.query) # check that _process_nonstreaming_queries() was called with the query # list returned by _factor_query() self.nonstream_pump._process_nonstreaming_queries.assert_called_once_with( self.query_list)