Skip to content

Commit

Permalink
Fix Cloud-CV#72: Avoid auth token reset while running tests in dev en…
Browse files Browse the repository at this point in the history
…vironment(Cloud-CV#92)

* Fix token reset while running tests

* Fix os path impor
  • Loading branch information
guyandtheworld authored and RishabhJain2018 committed Aug 19, 2018
1 parent 2e4f66e commit 39d5611
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 3 additions & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import random
import string

import os.path as osp

from evalai.utils.config import AUTH_TOKEN_FILE_NAME, AUTH_TOKEN_DIR

random.seed(10)
Expand All @@ -14,9 +12,10 @@ class BaseTestClass:

@classmethod
def setup_class(cls):
if not os.path.exists(AUTH_TOKEN_DIR):
token_file = os.path.join(AUTH_TOKEN_DIR, AUTH_TOKEN_FILE_NAME)
if not os.path.exists(token_file):
os.makedirs(AUTH_TOKEN_DIR)
with open(osp.join(AUTH_TOKEN_DIR, AUTH_TOKEN_FILE_NAME), 'w') as fw:
with open(token_file, 'w') as fw:
token = ''.join(random.choice(string.ascii_lowercase) for _ in range(40))
data = {"token": "{}".format(token)}
fw.write(json.dumps(data))
14 changes: 11 additions & 3 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import responses
import shutil

from beautifultable import BeautifulTable
from click.testing import CliRunner

Expand All @@ -10,6 +10,7 @@
from evalai.utils.urls import URLS
from evalai.utils.config import (API_HOST_URL,
AUTH_TOKEN_DIR,
AUTH_TOKEN_FILE_NAME,
HOST_URL_FILE_PATH)
from evalai.utils.common import convert_UTC_date_to_local

Expand All @@ -19,9 +20,16 @@

class TestGetUserAuthToken(BaseTestClass):

token_file = os.path.join(AUTH_TOKEN_DIR, AUTH_TOKEN_FILE_NAME)

def setup(self):
if os.path.exists(AUTH_TOKEN_DIR):
shutil.rmtree(AUTH_TOKEN_DIR)
with open(self.token_file) as fo:
self.token = fo.read()
os.remove(self.token_file)

def teardown(self):
with open(self.token_file, 'w') as f:
f.write(self.token)

def test_get_user_auth_token_when_file_does_not_exist(self):
expected = ("\nThe authentication token json file doesn't exists at the required path. "
Expand Down

0 comments on commit 39d5611

Please sign in to comment.