コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
    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()
コード例 #4
0
    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()
コード例 #5
0
    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()
コード例 #6
0
    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()
コード例 #7
0
    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
コード例 #8
0
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
コード例 #9
0
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
コード例 #10
0
    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']
コード例 #11
0
    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"]
コード例 #12
0
    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'
コード例 #13
0
    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'
コード例 #14
0
    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'
コード例 #15
0
def get_client():
    return Client(api_key=settings.API_KEY, api_secret=settings.API_SECRET)
コード例 #16
0
 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