def test_with_producer(self): topic = 'unittest' producer = KafkaProducerWrapper({}, topic=topic, kafka_cls=KafkaProducerStub) r = check('https://www.google.com', producer=producer) self.assertEqual(r['code'], 200) self.assertEqual(len(producer.producer.messages[topic]), 1) self.assertEqual(producer.producer.messages[topic][0]['code'], 200)
def test_run(self): """ Make one check, push to kafka, read from kafka, put to DB """ consumer = KafkaConsumerWrapper(self._kafka_connection, 'unittest') exporter = PGExporter(os.environ.get('PG_URI')) producer = KafkaProducerWrapper(self._kafka_connection, 'unittest') need_message = True while need_message: # parallel testing create many consumers # produce until got one message check('https://www.google.com', producer=producer) time.sleep(1) for message in consumer.messages(): exporter.submit(message) need_message = False
def test_request_timeout(self): r = check( 'http://slowwly.robertomurray.co.uk' '/delay/2000/url/https://www.google.com', timeout=1) self.assertEqual(r['code'], 499) self.assertEqual(r['time'], 1)
def test_200_body_check(self): r = check('https://www.google.com', body_check_re='.*Google.*') self.assertTrue(r['body_check_valid'])
def test_nonexists_domain(self): r = check('https://google1111.com') self.assertEqual(r['code'], 0)
def test_301(self): """test not follow redirects""" r = check('https://google.com') self.assertEqual(r['code'], 301)
def test_200(self): r = check('https://www.google.com') self.assertEqual(r['code'], 200)