def test_status_code_401(self, mock_request, _):
     resp = mock.Mock()
     resp.status_code = 401
     mock_request.return_value = resp
     with pytest.raises(NonRetryableException):
         Session().checked_request('method', 'path')
     with pytest.raises(Unauthorized):
         Session().checked_request('method', 'path')
 def test_status_code_409(self, mock_request, _):
     resp = mock.Mock()
     resp.status_code = 409
     mock_request.return_value = resp
     with pytest.raises(NonRetryableException):
         Session().checked_request('method', 'path')
     with pytest.raises(WorkflowConflictException):
         Session().checked_request('method', 'path')
 def test_status_code_425(self, mock_request, _):
     resp = mock.Mock()
     resp.status_code = 425
     mock_request.return_value = resp
     with pytest.raises(RetryableException):
         Session().checked_request('method', 'path')
     with pytest.raises(WorkflowNotReadyException):
         Session().checked_request('method', 'path')
Example #4
0
 def __init__(self,
              name: str,
              description: Optional[str] = None,
              session: Optional[Session] = Session()):
     self.name: str = name
     self.description: Optional[str] = description
     self.session: Session = session
Example #5
0
 def __init__(self,
              api_key: str,
              scheme: str = DEFAULT_SCHEME,
              host: str = DEFAULT_HOST,
              port: Optional[str] = None):
     self.logger = logging.getLogger(__name__)
     self.session: Session = Session(api_key, scheme, host, port)
Example #6
0
 def test_status_code_404(self, mock_request, _):
     resp = mock.Mock()
     resp.status_code = 404
     resp.text = 'Some response text'
     mock_request.return_value = resp
     with pytest.raises(NonRetryableException):
         Session().checked_request('method', 'path')
Example #7
0
 def __init__(self,
              name: str,
              analysis: CrossValidationAnalysisConfiguration,
              project_id: Optional[UUID] = None,
              session: Session = Session()):
     self.name = name
     self.analysis = analysis
     self.project_id = project_id
     self.session = session
 def __init__(self,
              name: str,
              description: str,
              dimensions: List[Dimension],
              session: Session = Session()):
     self.name: str = name
     self.description: str = description
     self.dimensions: List[Dimension] = dimensions
     self.session: Session = session
def session():
    session = Session(refresh_token='12345',
                      scheme='http',
                      host='citrine-testing.fake')
    # Default behavior is to *not* require a refresh - those tests can clear this out
    # As rule of thumb, we should be using freezegun or similar to never rely on the system clock
    # for these scenarios, but I thought this is light enough to postpone that for the time being
    session.access_token_expiration = datetime.utcnow() + timedelta(minutes=3)

    return session
Example #10
0
 def __init__(self,
              name: str,
              description: str,
              descriptors: List[Descriptor],
              data: List[Mapping[str, Any]],
              session: Session = Session()):
     self.name: str = name
     self.description: str = description
     self.descriptors: List[Descriptor] = descriptors
     self.data: List[Mapping[str, Any]] = data
     self.session: Session = session
 def __init__(self,
              *,
              name: str,
              description: str,
              subspaces: Optional[List[Union[UUID, DesignSpace]]] = None,
              dimensions: Optional[List[Dimension]] = None,
              session: Session = Session()):
     self.name: str = name
     self.description: str = description
     self.subspaces: List[Union[UUID, DesignSpace]] = subspaces or []
     self.dimensions: List[Dimension] = dimensions or []
     self.session: Session = session
Example #12
0
 def __init__(self,
              name: str,
              analysis: CrossValidationAnalysisConfiguration,
              project_id: Optional[UUID] = None,
              session: Session = Session()):
     warn("{this_class} is deprecated. Please use {replacement} instead".
          format(this_class=self.__class__.name,
                 replacement=PredictorEvaluationWorkflow.__name__),
          category=DeprecationWarning)
     self.name = name
     self.analysis = analysis
     self.project_id = project_id
     self.session = session
Example #13
0
 def __init__(self,
              name: str,
              design_space_id: UUID,
              processor_id: Optional[UUID],
              predictor_id: UUID,
              project_id: Optional[UUID] = None,
              session: Session = Session()):
     self.name = name
     self.design_space_id = design_space_id
     self.processor_id = processor_id
     self.predictor_id = predictor_id
     self.project_id = project_id
     self.session = session
Example #14
0
 def __init__(self,
              *,
              name: str,
              description: str,
              formulation_descriptor: FormulationDescriptor,
              ingredients: Set[str],
              constraints: Set[Constraint],
              labels: Optional[Mapping[str, Set[str]]] = None,
              resolution: float = 0.0001,
              session: Session = Session()):
     self.name: str = name
     self.description: str = description
     self.formulation_descriptor: FormulationDescriptor = formulation_descriptor
     self.ingredients: Set[str] = ingredients
     self.constraints: Set[Constraint] = constraints
     self.labels: Optional[Mapping[str, Set[str]]] = labels
     self.resolution: float = resolution
     self.session: Session = session
Example #15
0
 def test_status_code_400(self, mock_request, _):
     resp = mock.Mock()
     resp.status_code = 400
     resp_json = {
         'code': 400,
         'message': 'a message',
         'validation_errors': [
             {
                 'failure_message': 'you have failed',
             },
         ],
     }
     resp.json = lambda: resp_json
     resp.text = json.dumps(resp_json)
     mock_request.return_value = resp
     with pytest.raises(BadRequest) as einfo:
         Session().checked_request('method', 'path')
     assert einfo.value.api_error.validation_errors[0].failure_message \
         == resp_json['validation_errors'][0]['failure_message']
Example #16
0
    def test_connection_error(self, mock_request, _):

        data = {'stuff': 'not_used'}
        call_count = 0

        # Simulate a request using a stale session that raises
        # a ConnectionError then works on the second call.
        def request_side_effect(method, uri):
            nonlocal call_count
            if call_count == 0:
                call_count += 1
                raise requests.exceptions.ConnectionError
            else:
                return data

        mock_request.side_effect = request_side_effect
        resp = Session()._request_with_retry('method', 'path')

        assert resp == data
Example #17
0
 def __init__(self, session: Session = Session()):
     self.session = session
 def __init__(self, project_id: UUID, session: Session = Session()):
     self.project_id = project_id
     self.session: Session = session
 def __init__(self,
              api_key: str,
              scheme: str = DEFAULT_SCHEME,
              host: str = DEFAULT_HOST,
              port: Optional[str] = None):
     self.session: Session = Session(api_key, scheme, host, port)