Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ jobs:
strategy:
max-parallel: 1
matrix:
python-version: [3.6, 3.7]
python-version: [3.7, 3.8]

steps:

- name: Cancel previous workflow
uses: styfle/cancel-workflow-action@0.4.0
with:
access_token: ${{ github.token }}

- name: set environment for branch
run: |
if [[ "${{github.base_ref}}" == "master" || "${{github.ref}}" == "refs/heads/master" ]]; then
echo "::set-env name=LABELBOX_TEST_ENVIRON::prod"
else
echo "::set-env name=LABELBOX_TEST_ENVIRON::staging"
fi

- uses: actions/checkout@v2
with:
token: ${{ secrets.ACTIONS_ACCESS_TOKEN }}
Expand Down Expand Up @@ -51,16 +65,11 @@ jobs:
- name: Test with tox
env:
# make sure to tell tox to use these environs in tox.ini
LABELBOX_TEST_API_KEY: ${{ secrets.LABELBOX_API_KEY }}
LABELBOX_TEST_ENDPOINT: "https://api.labelbox.com/graphql"
# TODO: create a staging environment (develop)
# we only test against prod right now because the merges are right into
# the main branch which is develop right now
LABELBOX_TEST_ENVIRON: "prod"
#
# randall@labelbox.com
LABELBOX_TEST_API_KEY_PROD: ${{ secrets.LABELBOX_API_KEY }}

# randall+staging-python@labelbox.com
#LABELBOX_TEST_API_KEY: ${{ secrets.STAGING_LABELBOX_API_KEY }}
#LABELBOX_TEST_ENDPOINT: "https://staging-api.labelbox.com/graphql"
#LABELBOX_TEST_ENVIRON: "staging"
LABELBOX_TEST_API_KEY_STAGING: ${{ secrets.STAGING_LABELBOX_API_KEY }}
run: |
tox -- -svv
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ build:
test-staging: build
docker run -it -v ${PWD}:/usr/src -w /usr/src \
-e LABELBOX_TEST_ENVIRON="staging" \
-e LABELBOX_TEST_ENDPOINT="https://staging-api.labelbox.com/graphql" \
-e LABELBOX_TEST_API_KEY="<REPLACE>" \
local/labelbox-python:test pytest $(PATH_TO_TEST)
-e LABELBOX_TEST_API_KEY_STAGING="<REPLACE>" \
local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx

test-prod: build
docker run -it -v ${PWD}:/usr/src -w /usr/src \
-e LABELBOX_TEST_ENVIRON="prod" \
-e LABELBOX_TEST_ENDPOINT="https://api.labelbox.com/graphql" \
-e LABELBOX_TEST_API_KEY="<REPLACE>" \
local/labelbox-python:test pytest $(PATH_TO_TEST)
-e LABELBOX_TEST_API_KEY_PROD="<REPLACE>" \
local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx
5 changes: 3 additions & 2 deletions labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ def labeler_performance(self):

def create_labeler_performance(client, result):
result["user"] = Entity.User(client, result["user"])
result["lastActivityTime"] = datetime.fromtimestamp(
result["lastActivityTime"] / 1000, timezone.utc)
# python isoformat doesn't accept Z as utc timezone
result["lastActivityTime"] = datetime.fromisoformat(
result["lastActivityTime"].replace('Z', '+00:00'))
return LabelerPerformance(
**
{utils.snake_case(key): value for key, value in result.items()})
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
python_requires='>=3.7',
keywords=["labelbox"],
)
33 changes: 20 additions & 13 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,27 @@ def environ() -> Environ:
"""
try:
return Environ(os.environ['LABELBOX_TEST_ENVIRON'])
# TODO: for some reason all other environs can be set but
# this one cannot in github actions
#return Environ.PROD
except KeyError:
raise Exception(f'Missing LABELBOX_TEST_ENVIRON in: {os.environ}')


def graphql_url(environ: str) -> str:
if environ == Environ.PROD:
return 'https://api.labelbox.com/graphql'
return 'https://staging-api.labelbox.com/graphql'


def testing_api_key(environ: str) -> str:
if environ == Environ.PROD:
return os.environ["LABELBOX_TEST_API_KEY_PROD"]
return os.environ["LABELBOX_TEST_API_KEY_STAGING"]


class IntegrationClient(Client):

def __init__(self):
api_url = os.environ["LABELBOX_TEST_ENDPOINT"]
api_key = os.environ["LABELBOX_TEST_API_KEY"]
#"https://staging-api.labelbox.com/graphql")
def __init__(self, environ: str) -> None:
api_url = graphql_url(environ)
api_key = testing_api_key(environ)
super().__init__(api_key, api_url)

self.queries = []
Expand All @@ -54,8 +62,8 @@ def execute(self, query, params=None, check_naming=True, **kwargs):


@pytest.fixture
def client():
return IntegrationClient()
def client(environ: str):
return IntegrationClient(environ)


@pytest.fixture
Expand Down Expand Up @@ -105,10 +113,9 @@ def label_pack(project, rand_gen):

@pytest.fixture
def iframe_url(environ) -> str:
return {
Environ.PROD: 'https://editor.labelbox.com',
Environ.STAGING: 'https://staging-editor.labelbox.com',
}[environ]
if environ == Environ.PROD:
return 'https://editor.labelbox.com'
return 'https://staging.labelbox.dev/editor'


@pytest.fixture
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_project_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def simple_ontology():


def test_project_setup(project, iframe_url) -> None:

client = project.client
labeling_frontends = list(
client.get_labeling_frontends(
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py36, py37
envlist = py37, py38

[gh-actions]
python =
3.6: py36
3.7: py37
3.8: py38

[testenv]
# install pytest in the virtualenv where commands will be executed
deps =
-rrequirements.txt
pytest
passenv = LABELBOX_TEST_ENDPOINT LABELBOX_TEST_API_KEY LABELBOX_TEST_ENVIRON
passenv = LABELBOX_TEST_API_KEY_PROD LABELBOX_TEST_API_KEY_STAGING LABELBOX_TEST_ENVIRON
commands = pytest {posargs}