Ejemplo n.º 1
0
def wait_for_local_service_ping(target, service, sleep_time=10, retries=3):
    call_count = 1
    requestor = HttpRequestor()
    print(f'Waiting for {service} ping to succeed...')
    ping_url = f'{target}/{service}/ping/'
    healthy = requestor.get(ping_url).status_code == Constants.SUCCESS_RESPONSE_CODE
    while not healthy:
        sleep(sleep_time)
        call_count += 1
        healthy = requestor.get(ping_url).status_code == Constants.SUCCESS_RESPONSE_CODE
        if call_count > retries:
            return
Ejemplo n.º 2
0
def dump_mongo_data():
    request = HttpRequestor()
    url = get_production_service_url(INFRASTRUCTURE, 0) + '&limit=90'
    result = request.get(url)
    infrastructure_list = result.json()[INFRASTRUCTURE]
    with open('./data/infrastructure.json', 'w+') as infra_file:
        infra_file.write(json.dumps(infrastructure_list, default=str))
Ejemplo n.º 3
0
def get_wu_name(name):
    wu_name = 'Unknown'
    url = f'https://wunameaas.herokuapp.com/wuami/{name}'
    web_client = HttpRequestor()
    result = web_client.get(url)
    soup = BeautifulSoup(result.text, 'html.parser')
    for bold_item in soup.find_all('b'):
        wu_name = bold_item.get_text()
    return wu_name
Ejemplo n.º 4
0
class HttpRequestorTests(TestCase):
    def setUp(self):
        mock = MagicMock()
        mock.get.return_value = mock
        mock.request.return_value = Constants.DUMMY
        self.requestor = HttpRequestor(client=mock)

    def test_get(self):
        result = self.requestor.get(Constants.DUMMY, headers=[])
        self.assertEqual(result, Constants.DUMMY)

    def test_post(self):
        result = self.requestor.post(Constants.DUMMY, data=[], headers=[])
        self.assertEqual(result, Constants.DUMMY)

    def test_put(self):
        result = self.requestor.put(Constants.DUMMY, headers=[])
        self.assertEqual(result, Constants.DUMMY)

    def test_delete(self):
        result = self.requestor.delete(Constants.DUMMY, headers=[])
        self.assertEqual(result, Constants.DUMMY)

    def test_get_items(self):
        mock = MagicMock()
        mock.request.return_value = mock
        mock.json.return_value = {Constants.DUMMY: [1], 'total': 50, 'limit': 1}
        requestor = HttpRequestor(client=mock)
        result = requestor.get_items(Constants.DUMMY, True, Constants.DUMMY)
        self.assertIsNotNone(result)
        result = requestor.get_items(Constants.DUMMY, False, Constants.DUMMY)
        self.assertIsNotNone(result)

    def test_get_all_items(self):
        mock = MagicMock()
        mock.request.return_value = mock
        mock.json.return_value = {Constants.DUMMY: [1], 'total': 50, 'limit': 1}
        requestor = HttpRequestor(client=mock)
        result = requestor.get_all_items(Constants.DUMMY)
        self.assertIsNotNone(result)

    def test_save_items(self):
        mock = MagicMock()
        mock.request.return_value = mock
        mock.json.return_value = {Constants.DUMMY: [1], 'total': 50, 'limit': 1}
        requestor = HttpRequestor(client=mock, save_fn=mock)
        result = requestor.save_data_items(Constants.DUMMY)
        self.assertTrue(result)

    def test_perform_web_request(self):
        mock = MagicMock()
        mock.request.return_value = mock
        mock.json.return_value = {Constants.DUMMY: [1], 'total': 50, 'limit': 1}
        requestor = HttpRequestor(client=mock)
        result = requestor.perform_web_request(Constants.DUMMY, Constants.DUMMY)
        self.assertIsNotNone(result)
        requestor = HttpRequestor(client=mock, circuit_breaker=mock)
        result = requestor.perform_web_request(Constants.DUMMY, Constants.DUMMY)
        self.assertIsNotNone(result)

    def test_get_auth_value(self):
        self.assertIsNotNone(HttpRequestor.get_auth_value(Constants.DUMMY, Constants.DUMMY))

    @skipUnless(Settings.RUN_SKIPPED, Constants.RUN_SKIPPED_MSG)
    def test_real_get(self):
        requestor = HttpRequestor()
        result = requestor.get(GOOGLE_URL)
        self.assertEqual(result.status_code, Constants.SUCCESS_RESPONSE_CODE)
Ejemplo n.º 5
0
 def test_real_get(self):
     requestor = HttpRequestor()
     result = requestor.get(GOOGLE_URL)
     self.assertEqual(result.status_code, Constants.SUCCESS_RESPONSE_CODE)