class WorkingAreasTest(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.api_key = os.environ.get("API_KEY", "sample_api_key") self.api_secret = os.environ.get("API_SECRET", "sample_api_secret") self.version = __version__ self.client = Client(self.api_key, self.api_secret) self.working_area = WorkingArea(client=self.client) if bool(os.environ.get("TEST", False)): self.client.enable_test_mode() def test_working_area_attribute_type(self): working_area = getattr(self.client, "working_area", None) assert isinstance(working_area, WorkingArea) def test_working_area_client(self): working_area = getattr(self.client, "working_area", None) assert working_area.client == self.client @pytest.mark.vcr() def test_working_area_response_status_code(self): response = self.working_area.list() assert response["status"] == 200
class WorkingAreasTest(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.api_key = os.environ.get('API_KEY', 'sample_api_key') self.api_secret = os.environ.get('API_SECRET', 'sample_api_secret') self.version = __version__ self.client = Client(self.api_key, self.api_secret) if bool(os.environ.get('TEST', False)): self.client.enable_test_mode() def test_working_area_attribute_type(self): working_area = getattr(self.client, 'working_area', None) assert isinstance(working_area, WorkingArea) def test_working_area_client(self): working_area = getattr(self.client, 'working_area', None) assert working_area.client == self.client def test_working_area_response_status_code(self): response = self.client.working_area.list() assert response['status'] == 200
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.api_key = os.environ.get('API_KEY', 'sample_api_key') self.api_secret = os.environ.get('API_SECRET', 'sample_api_secret') self.version = __version__ self.client = Client(self.api_key, self.api_secret) if bool(os.environ.get('TEST', False)): self.client.enable_test_mode()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.api_key = os.environ.get("API_KEY", "sample_api_key") self.api_secret = os.environ.get("API_SECRET", "sample_api_secret") self.version = __version__ self.client = Client(self.api_key, self.api_secret) self.working_area = WorkingArea(client=self.client) if bool(os.environ.get("TEST", False)): self.client.enable_test_mode()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.version = __version__ self.api_key = os.environ.get("API_KEY", "sample_api_key") self.api_secret = os.environ.get("API_SECRET", "sample_api_secret") self.order_id = os.environ.get("ORDER_ID", "sample_order_id") self.order_to_estimate = os.environ.get("ORDER_TO_ESTIMATE", "{}") self.order_to_estimate = json.loads(self.order_to_estimate) self.client = Client(self.api_key, self.api_secret) self.order = Order(client=self.client) if bool(os.environ.get("TEST", False)): self.client.enable_test_mode()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.version = __version__ self.api_key = os.environ.get('API_KEY', 'sample_api_key') self.api_secret = os.environ.get('API_SECRET', 'sample_api_secret') self.order_id = os.environ.get('ORDER_ID', 'sample_order_id') self.order_to_estimate = os.environ.get('ORDER_TO_ESTIMATE', '{}') self.order_to_estimate = json.loads(self.order_to_estimate) self.client = Client(self.api_key, self.api_secret) if bool(os.environ.get('TEST', False)): self.client.enable_test_mode()
def test_client_auth_string(self): client = Client(self.api_key, self.api_secret, stage=Stage.TEST) raw_auth_string = f'{self.api_key}:{self.api_secret}'.encode('utf-8') auth_string = b64encode(raw_auth_string).decode('utf-8') assert client.auth_string == auth_string
class OrdersTest(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.version = __version__ self.api_key = os.environ.get("API_KEY", "sample_api_key") self.api_secret = os.environ.get("API_SECRET", "sample_api_secret") self.order_id = os.environ.get("ORDER_ID", "sample_order_id") self.order_to_estimate = os.environ.get("ORDER_TO_ESTIMATE", "{}") self.order_to_estimate = json.loads(self.order_to_estimate) self.client = Client(self.api_key, self.api_secret) self.order = Order(client=self.client) if bool(os.environ.get("TEST", False)): self.client.enable_test_mode() def test_order_attribute_type(self): order = getattr(self.client, "order", None) assert isinstance(order, Order) def test_order_client(self): order = getattr(self.client, "order", None) assert order.client == self.client @pytest.mark.vcr() def test_order_list_status_code(self): response = self.order.list() assert response["status"] == 200 @pytest.mark.vcr() def test_order_read_status_code(self): response = self.order.read(self.order_id) assert response["status"] == 200 @pytest.mark.vcr() def test_order_estimate_status_code(self): response = self.order.estimate(self.order_to_estimate) assert response["status"] == 200
class OrdersTest(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) load_dotenv() self.version = __version__ self.api_key = os.environ.get('API_KEY', 'sample_api_key') self.api_secret = os.environ.get('API_SECRET', 'sample_api_secret') self.order_id = os.environ.get('ORDER_ID', 'sample_order_id') self.order_to_estimate = os.environ.get('ORDER_TO_ESTIMATE', '{}') self.order_to_estimate = json.loads(self.order_to_estimate) self.client = Client(self.api_key, self.api_secret) if bool(os.environ.get('TEST', False)): self.client.enable_test_mode() def test_order_attribute_type(self): order = getattr(self.client, 'order', None) assert isinstance(order, Order) def test_order_client(self): order = getattr(self.client, 'order', None) assert order.client == self.client def test_order_list_status_code(self): response = self.client.order.list() assert response['status'] == 200 def test_order_read_status_code(self): response = self.client.order.read(self.order_id) assert response['status'] == 200 def test_order_estimate_status_code(self): response = self.client.order.estimate(self.order_to_estimate) assert response['status'] == 200
def test_client_headers(self): client = Client(self.api_key, self.api_secret, stage=Stage.TEST) raw_auth_string = f'{self.api_key}:{self.api_secret}'.encode('utf-8') auth_string = b64encode(raw_auth_string).decode('utf-8') headers = { 'User-Agent': f'Globo-API-Python/{self.version}', 'Authorization': f'Basic {auth_string}', 'Content-type': 'application/json', 'Accept': 'application/json' } assert headers['User-Agent'] == client.session.headers['User-Agent'] assert headers['Authorization'] == client.session.headers['Authorization'] assert headers['Content-type'] == client.session.headers['Content-type'] assert headers['Accept'] == client.session.headers['Accept']
def test_client_headers(self): client = Client(self.api_key, self.api_secret, stage=Stage.TEST) auth_string = self._get_auth_string() headers = { "User-Agent": "Globo-API-Python/{}".format(self.version), "Authorization": "Basic {}".format(auth_string), "Content-type": "application/json", "Accept": "application/json", } assert headers["User-Agent"] == client.session.headers["User-Agent"] assert headers["Authorization"] == client.session.headers[ "Authorization"] assert headers["Content-type"] == client.session.headers[ "Content-type"] assert headers["Accept"] == client.session.headers["Accept"]
def test_client_stage_updates(self): client = Client(self.api_key, self.api_secret, stage=Stage.PRODUCTION) assert client.stage == Stage.PRODUCTION assert client.base_url == 'https://api.glovoapp.com' client.enable_test_mode() assert client.stage == Stage.TEST assert client.base_url == 'https://stageapi.glovoapp.com' client.disable_test_mode() assert client.stage == Stage.PRODUCTION assert client.base_url == 'https://api.glovoapp.com'
def test_client_test_stage(self): client = Client(self.api_key, self.api_secret, stage=Stage.TEST) assert client.stage == Stage.TEST assert client.base_url == 'https://stageapi.glovoapp.com'
def test_client_production_stage(self): client = Client(self.api_key, self.api_secret, stage=Stage.PRODUCTION) assert client.stage == Stage.PRODUCTION assert client.base_url == 'https://api.glovoapp.com'
def get_client(): return Client(api_key=settings.API_KEY, api_secret=settings.API_SECRET)
def test_client_auth_string(self): client = Client(self.api_key, self.api_secret, stage=Stage.TEST) auth_string = self._get_auth_string() assert client.auth_string == auth_string