def test_bootstrap_sets_time(self): before_now = datetime.utcnow() - timedelta(microseconds=1) pillow = ConfigurableIndicatorPillow() pillow.bootstrap([]) after_now = datetime.utcnow() + timedelta(microseconds=1) self.assertTrue(pillow.bootstrapped) self.assertTrue(before_now < pillow.last_bootstrapped) self.assertTrue(after_now > pillow.last_bootstrapped) self.assertFalse(pillow.needs_bootstrap())
def test_needs_bootstrap_window(self): before_now = datetime.utcnow() - timedelta(microseconds=1) pillow = ConfigurableIndicatorPillow() pillow.bootstrap([]) pillow.last_bootstrapped = before_now - timedelta( seconds=REBUILD_CHECK_INTERVAL - 5) self.assertFalse(pillow.needs_bootstrap()) pillow.last_bootstrapped = before_now - timedelta( seconds=REBUILD_CHECK_INTERVAL) self.assertTrue(pillow.needs_bootstrap())
def test_pillow_save_to_multiple_databases(self): self.assertNotEqual(self.ds1_adapter.engine.url, self.ds2_adapter.engine.url) pillow = ConfigurableIndicatorPillow() pillow.bootstrap(configs=[self.ds_1, self.ds_2]) self.assertNotEqual(self.ds1_adapter.engine.url, self.ds2_adapter.engine.url) sample_doc, _ = get_sample_doc_and_indicators() pillow.change_transport(sample_doc) self.assertNotEqual(self.ds1_adapter.engine.url, self.ds2_adapter.engine.url) self.assertEqual(1, self.ds1_adapter.get_query_object().count()) self.assertEqual(1, self.ds2_adapter.get_query_object().count())
def test_pillow_save_to_one_database_at_a_time(self): pillow = ConfigurableIndicatorPillow() pillow.bootstrap(configs=[self.ds_1]) sample_doc, _ = get_sample_doc_and_indicators() pillow.change_transport(sample_doc) self.assertEqual(1, self.ds1_adapter.get_query_object().count()) self.assertEqual(0, self.ds2_adapter.get_query_object().count()) # save to the other pillow.bootstrap(configs=[self.ds_2]) sample_doc['_id'] = uuid.uuid4().hex pillow.change_transport(sample_doc) self.assertEqual(1, self.ds1_adapter.get_query_object().count()) self.assertEqual(1, self.ds2_adapter.get_query_object().count()) self.assertEqual( 1, self.ds1_adapter.get_query_object().filter_by( doc_id='some-doc-id').count()) self.assertEqual( 1, self.ds2_adapter.get_query_object().filter_by( doc_id=sample_doc['_id']).count())
def setUp(self): self.config = get_sample_data_source() self.pillow = ConfigurableIndicatorPillow() self.pillow.bootstrap(configs=[self.config]) self.adapter = IndicatorSqlAdapter(self.config) self.fake_time_now = datetime(2015, 4, 24, 12, 30, 8, 24886)
def test_needs_bootstrap_on_initialization(self): pillow = ConfigurableIndicatorPillow() self.assertTrue(pillow.needs_bootstrap())