Skip to content

Commit

Permalink
Fix integration test set up (#104)
Browse files Browse the repository at this point in the history
* Fix integration test set up

* Fix lint error
  • Loading branch information
rushabhvaria authored Apr 4, 2023
1 parent 4a72e82 commit e28141d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/integrationtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Run all integration tests
env:
PINTEREST_REFRESH_ACCESS_TOKEN: ${{ secrets.CI_REFRESH_ACCESS_TOKEN }}
PINTEREST_APP_SECRET: ${{ secrets.CI_APP_SECRET }}
PINTEREST_APP_ID: ${{ secrets.CI_APP_ID }}
PINTEREST_API_URI: ${{ secrets.CI_HOST_URI }}
CONVERSION_ACCESS_TOKEN: ${{ secrets.CI_CONVERSION_ACCESS_TOKEN }}
DEFAULT_BOARD_ID: ${{ secrets.CI_DEFAULT_BOARD_ID }}
DEFAULT_BOARD_NAME: ${{ secrets.CI_DEFAULT_BOARD_NAME }}
DEFAULT_PIN_ID: ${{ secrets.CI_DEFAULT_PIN_ID }}
DEFAULT_BOARD_SECTION_ID: ${{ secrets.CI_DEFAULT_BOARD_SECTION_ID }}
OWNER_USER_ID: ${{ secrets.CI_OWNER_USER_ID }}
DEFAULT_AD_ACCOUNT_ID: ${{ secrets.CI_DEFAULT_AD_ACCOUNT_ID }}
PINTEREST_JSON_ENV_VARIABLES: ${{ secrets.CI_INTEG_TEST_JSON }}
run: |
python -m pip install --upgrade pip
make install_dev
Expand Down
5 changes: 3 additions & 2 deletions pinterest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import os as _os
from dotenv import load_dotenv as _load_env_vars
from pinterest.version import __version__
from pinterest.utils.load_json_config import load_json_config as _load_json
from pinterest.utils.load_json_config import load_json_config as _load_json,\
load_json_config_from_single_env_var as _load_json_single_variable

_load_env_vars()
_load_json()

_load_json_single_variable()

PINTEREST_DEBUG = _os.environ.get('PINTEREST_DEBUG', "False").lower() == "true"
PINTEREST_PORT = _os.environ.get('PINTEREST_PORT', 0)
Expand Down
16 changes: 15 additions & 1 deletion pinterest/utils/load_json_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
import os

__all__ = ['load_json_config']
__all__ = ['load_json_config', 'load_json_config_from_single_env_var']

_PREFIX = 'PINTEREST_'

Expand All @@ -23,6 +23,20 @@ def load_json_config():
for attribute, value in config_json.items():
_set_as_environment_variables(f'{_PREFIX}{attribute.upper()}', str(value))

def load_json_config_from_single_env_var():
"""
Parse PINTEREST_JSON_ENV_VARIABLES environment variable to split long JSON string into
individual environment variables.
"""
config_json = os.environ.get('PINTEREST_JSON_ENV_VARIABLES')
if not config_json:
return

config_json = json.loads(config_json)

for attribute, value in config_json.items():
os.environ[attribute] = str(value)


def _get_current_dir():
return os.path.abspath(os.path.join(os.getcwd(), os.path.pardir))
Expand Down
15 changes: 11 additions & 4 deletions pinterest/utils/refresh_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ def get_new_access_token(
body=data,
timeout=5
)
if not response.status == 200:
raise SdkException(reason="Authentication error. \
Kindly check if the following variables are correct: [PINTEREST_ACCESS_TOKEN] or \
[PINTEREST_APP_ID, PINTEREST_APP_SECRET, PINTEREST_REFRESH_ACCESS_TOKEN]")
if response.status == 401:
raise SdkException(
status=response.status,
reason=response.reason,
body="Authentication error. " +
"Kindly check if the following variables are correct: [PINTEREST_ACCESS_TOKEN] or " +
"[PINTEREST_APP_ID, PINTEREST_APP_SECRET, PINTEREST_REFRESH_ACCESS_TOKEN]. " +
f"Response from server: {response.body}"
)
if response.status != 200:
raise SdkException(http_resp=response)

data = json.loads(response.data)

Expand Down
4 changes: 2 additions & 2 deletions pinterest/utils/sdk_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class SdkException(Exception):
"""Raises an exception for Model's Errors"""
def __init__(self, status=None, reason=None, http_resp=None):
def __init__(self, status=None, reason=None, http_resp=None, body=None):
if http_resp:
self.status = http_resp.status
self.reason = http_resp.reason
Expand All @@ -13,7 +13,7 @@ def __init__(self, status=None, reason=None, http_resp=None):
else:
self.status = status
self.reason = reason
self.body = None
self.body = body
self.headers = None

def __str__(self):
Expand Down

0 comments on commit e28141d

Please sign in to comment.