def test_read_pod_retries_fails(self):
     self.mock_kube_client.read_namespaced_pod.side_effect = [
         BaseHTTPError('Boom'),
         BaseHTTPError('Boom'),
         BaseHTTPError('Boom')
     ]
     self.assertRaises(AirflowException, self.pod_launcher.read_pod,
                       mock.sentinel)
 def test_read_pod_logs_retries_fails(self):
     mock.sentinel.metadata = mock.MagicMock()
     self.mock_kube_client.read_namespaced_pod_log.side_effect = [
         BaseHTTPError('Boom'),
         BaseHTTPError('Boom'),
         BaseHTTPError('Boom'),
     ]
     self.assertRaises(AirflowException, self.pod_launcher.read_pod_logs, mock.sentinel)
예제 #3
0
 def test_read_pod_retries_fails(self):
     mock.sentinel.metadata = mock.MagicMock()
     self.mock_kube_client.read_namespaced_pod.side_effect = [
         BaseHTTPError('Boom'),
         BaseHTTPError('Boom'),
         BaseHTTPError('Boom'),
     ]
     with pytest.raises(AirflowException):
         self.pod_launcher.read_pod(mock.sentinel)
예제 #4
0
 def test_read_pod_logs_retries_successfully(self):
     self.mock_kube_client.read_namespaced_pod_log.side_effect = [
         BaseHTTPError('Boom'),
         mock.sentinel.logs
     ]
     logs = self.pod_launcher.read_pod_logs(mock.sentinel)
     self.assertEqual(mock.sentinel.logs, logs)
     self.mock_kube_client.read_namespaced_pod_log.assert_has_calls([
         mock.call(
             _preload_content=False,
             container='base',
             follow=True,
             name=mock.sentinel.name,
             namespace=mock.sentinel.namespace,
             tail_lines=10
         ),
         mock.call(
             _preload_content=False,
             container='base',
             follow=True,
             name=mock.sentinel.name,
             namespace=mock.sentinel.namespace,
             tail_lines=10
         )
     ])
예제 #5
0
 def test_read_pod_logs_retries_successfully(self):
     mock.sentinel.metadata = mock.MagicMock()
     self.mock_kube_client.read_namespaced_pod_log.side_effect = [
         BaseHTTPError('Boom'),
         mock.sentinel.logs,
     ]
     logs = self.pod_launcher.read_pod_logs(mock.sentinel)
     assert mock.sentinel.logs == logs
     self.mock_kube_client.read_namespaced_pod_log.assert_has_calls([
         mock.call(
             _preload_content=False,
             container='base',
             follow=True,
             timestamps=False,
             name=mock.sentinel.metadata.name,
             namespace=mock.sentinel.metadata.namespace,
         ),
         mock.call(
             _preload_content=False,
             container='base',
             follow=True,
             timestamps=False,
             name=mock.sentinel.metadata.name,
             namespace=mock.sentinel.metadata.namespace,
         ),
     ])
예제 #6
0
def test_network(url):
    with requests.get(url, timeout=10, allow_redirects=False) as test:
        if 300 > test.status_code >= 200:
            return None
        elif test.status_code == 302:
            return test.headers['Location']
        else:
            raise BaseHTTPError("Invalid status code {code}".format(code=test.status_code))
 def test_read_pod_retries_successfully(self):
     self.mock_kube_client.read_namespaced_pod.side_effect = [
         BaseHTTPError('Boom'), mock.sentinel.pod_info
     ]
     pod_info = self.pod_launcher.read_pod(mock.sentinel)
     self.assertEqual(mock.sentinel.pod_info, pod_info)
     self.mock_kube_client.read_namespaced_pod.assert_has_calls([
         mock.call(mock.sentinel.name, mock.sentinel.namespace),
         mock.call(mock.sentinel.name, mock.sentinel.namespace)
     ])
예제 #8
0
 def test_read_pod_status_retries_successfully(self):
     mock.sentinel.metadata = mock.MagicMock()
     self.mock_kube_client.read_namespaced_pod_status.side_effect = [
         BaseHTTPError('Boom'), mock.sentinel.statuses
     ]
     statuses = self.pod_launcher.read_pod_status(mock.sentinel)
     self.assertEqual(mock.sentinel.statuses, statuses)
     self.mock_kube_client.read_namespaced_pod_status.assert_has_calls([
         mock.call(namespace=mock.sentinel.metadata.namespace,
                   name=mock.sentinel.metadata.name),
         mock.call(namespace=mock.sentinel.metadata.namespace,
                   name=mock.sentinel.metadata.name)
     ])
예제 #9
0
 def test_read_pod_retries_successfully(self):
     mock.sentinel.metadata = mock.MagicMock()
     self.mock_kube_client.read_namespaced_pod.side_effect = [
         BaseHTTPError('Boom'),
         mock.sentinel.pod_info,
     ]
     pod_info = self.pod_launcher.read_pod(mock.sentinel)
     assert mock.sentinel.pod_info == pod_info
     self.mock_kube_client.read_namespaced_pod.assert_has_calls([
         mock.call(mock.sentinel.metadata.name,
                   mock.sentinel.metadata.namespace),
         mock.call(mock.sentinel.metadata.name,
                   mock.sentinel.metadata.namespace),
     ])
 def test_read_pod_events_retries_successfully(self):
     mock.sentinel.metadata = mock.MagicMock()
     self.mock_kube_client.list_namespaced_event.side_effect = [
         BaseHTTPError('Boom'), mock.sentinel.events
     ]
     events = self.pod_launcher.read_pod_events(mock.sentinel)
     self.assertEqual(mock.sentinel.events, events)
     self.mock_kube_client.list_namespaced_event.assert_has_calls([
         mock.call(namespace=mock.sentinel.metadata.namespace,
                   field_selector="involvedObject.name={}".format(
                       mock.sentinel.metadata.name)),
         mock.call(namespace=mock.sentinel.metadata.namespace,
                   field_selector="involvedObject.name={}".format(
                       mock.sentinel.metadata.name))
     ])
def accept_tos_and_store_session_id(phone_number: str):
    """
    Helper function that:
    1) Requests a session ID from Endless MEdical
    2) Accepts the Endless Medical TOS
    3) Adds the first Feature to the session
    """
    endless_medical_session_id = endless_medical_api.get_session_token()
    if not endless_medical_api.accept_tos(endless_medical_session_id):
        raise BaseHTTPError("Error accepting Endless Medical TOS")
    user = UserDocument.get_by_phone(phone_number)
    user.endless_medical_token = endless_medical_session_id
    logger.debug("Adding {feature} with value {value}".format(
        feature=features_mapping.get("lives-in-area"), value=5))
    # 5 is the endless medical api value for "lives in a covid 19 affected area" we assume so because
    # to get into this step the user must have answered yes to this question in a previous step
    # the options was not added to the mapping since overlaps with the "severe" answer mapping
    endless_medical_api.add_feature(endless_medical_session_id,
                                    features_mapping.get("lives-in-area"), 5)
    user.update()