def test_ok(self): connection = ConnectionImpl(self.returns(SAMPLE_RESPONSE)) assert connection.experiments(1).fetch() == Experiment(SAMPLE_RESPONSE) assert connection.experiments().create() == Experiment(SAMPLE_RESPONSE) assert connection.experiments(1).update() == Experiment( SAMPLE_RESPONSE) assert connection.experiments(1).delete() is None
def test_connection_error(self): connection = ConnectionImpl( self.returns(ConnectionException('fake connection exception'))) with pytest.raises(ConnectionException) as e: connection.experiments(1).fetch() e = e.value assert str(e) == 'ConnectionException: fake connection exception'
def test_server_error(self): connection = ConnectionImpl(self.returns(ApiException(SAMPLE_EXCEPTION, status_code=500))) with pytest.raises(ApiException) as e: connection.experiments(1).fetch() e = e.value assert str(e) == 'ApiException (500): ' + MESSAGE assert e.status_code == 500 assert e.to_json() == SAMPLE_EXCEPTION
def test_client_error(self): connection = ConnectionImpl(self.returns(ApiException(SAMPLE_RESPONSE, 400))) with pytest.raises(ApiException) as e: connection.experiments(1).fetch() e = e.value assert str(e) == 'ApiException (400): ' assert e.status_code == 400 assert e.to_json() == SAMPLE_RESPONSE
def test_server_error(self): connection = ConnectionImpl( self.returns(ApiException(SAMPLE_EXCEPTION, status_code=500))) with pytest.raises(ApiException) as e: connection.experiments(1).fetch() e = e.value assert str(e) == 'ApiException (500): ' + MESSAGE assert e.status_code == 500 assert e.to_json() == SAMPLE_EXCEPTION
def test_client_error(self): connection = ConnectionImpl( self.returns(ApiException(SAMPLE_RESPONSE, 400))) with pytest.raises(ApiException) as e: connection.experiments(1).fetch() e = e.value assert str(e) == 'ApiException (400): ' assert e.status_code == 400 assert e.to_json() == SAMPLE_RESPONSE
def test_unicode_json(self): connection = ConnectionImpl(self.returns(ApiException(SAMPLE_UNICODE_EXCEPTION, 500))) with pytest.raises(ApiException) as e: connection.experiments(1).fetch() e = e.value if six.PY2: assert unicode(e) == six.u('ApiException (500): ') + UNICODE_MESSAGE assert str(e) == 'ApiException (500): ' + UNICODE_STR_MESSAGE else: assert str(e) == 'ApiException (500): ' + UNICODE_MESSAGE
def test_unicode_json(self): connection = ConnectionImpl( self.returns(ApiException(SAMPLE_UNICODE_EXCEPTION, 500))) with pytest.raises(ApiException) as e: connection.experiments(1).fetch() e = e.value if six.PY2: assert unicode( e) == six.u('ApiException (500): ') + UNICODE_MESSAGE assert str(e) == 'ApiException (500): ' + UNICODE_STR_MESSAGE else: assert str(e) == 'ApiException (500): ' + UNICODE_MESSAGE
def test_no_response(self): connection = ConnectionImpl(self.returns(None)) assert connection.experiments(1).fetch() is None
def test_response(self): connection = ConnectionImpl(self.returns(SAMPLE_RESPONSE)) assert connection.experiments(1).fetch() == Experiment(SAMPLE_RESPONSE)
def connection(self): return ConnectionImpl(requestor=None)
def connection(self, requestor): return ConnectionImpl(requestor)
def test_connection_error(self): connection = ConnectionImpl(self.returns(ConnectionException('fake connection exception'))) with pytest.raises(ConnectionException) as e: connection.experiments(1).fetch() e = e.value assert str(e) == 'ConnectionException: fake connection exception'
def test_ok(self): connection = ConnectionImpl(self.returns(SAMPLE_RESPONSE)) assert connection.experiments(1).fetch() == Experiment(SAMPLE_RESPONSE) assert connection.experiments().create() == Experiment(SAMPLE_RESPONSE) assert connection.experiments(1).update() == Experiment(SAMPLE_RESPONSE) assert connection.experiments(1).delete() is None