Browse Source

[MNT] modift config token method in test client

tags/v0.3.2
bxdd 1 year ago
parent
commit
0a12b24452
2 changed files with 35 additions and 18 deletions
  1. +17
    -9
      tests/test_learnware_client/test_all_learnware.py
  2. +18
    -9
      tests/test_learnware_client/test_upload.py

+ 17
- 9
tests/test_learnware_client/test_all_learnware.py View File

@@ -12,15 +12,24 @@ from learnware.market import BaseUserInfo
class TestAllLearnware(unittest.TestCase):
client = LearnwareClient()
def __init__(self, method_name='runTest', email=None, token=None):
super(TestAllLearnware, self).__init__(method_name)
self.email = email
self.token = token
@classmethod
def setUpClass(cls) -> None:
config_path = os.path.join(os.path.dirname(__file__), "config.json")
if not os.path.exists(config_path):
data = {"email": None, "token": None}
with open(config_path, "w") as file:
json.dump(data, file)

with open(config_path, "r") as file:
data = json.load(file)
email = data.get("email")
token = data.get("token")
if self.email is not None and self.token is not None:
self.client.login(self.email, self.token)
if email is None or token is None:
print("Please set email and token in config.json.")
else:
print("Client doest not login, all tests will be ignored!")
cls.client.login(email, token)

@unittest.skipIf(not client.is_login(), "Client doest not login!")
def test_all_learnware(self):
@@ -52,10 +61,9 @@ class TestAllLearnware(unittest.TestCase):
print(f"The currently failed learnware ids: {failed_ids}")



def suite():
_suite = unittest.TestSuite()
_suite.addTest(TestAllLearnware("test_all_learnware", email=None, token=None))
_suite.addTest(TestAllLearnware("test_all_learnware"))
return _suite

if __name__ == "__main__":


+ 18
- 9
tests/test_learnware_client/test_upload.py View File

@@ -1,5 +1,5 @@
import os
import argparse
import json
import unittest
import tempfile

@@ -9,15 +9,24 @@ from learnware.specification import generate_semantic_spec
class TestUpload(unittest.TestCase):
client = LearnwareClient()
def __init__(self, method_name='runTest', email=None, token=None):
super(TestUpload, self).__init__(method_name)
self.email = email
self.token = token
@classmethod
def setUpClass(cls) -> None:
config_path = os.path.join(os.path.dirname(__file__), "config.json")
if not os.path.exists(config_path):
data = {"email": None, "token": None}
with open(config_path, "w") as file:
json.dump(data, file)

with open(config_path, "r") as file:
data = json.load(file)
email = data.get("email")
token = data.get("token")
if self.email is not None and self.token is not None:
self.client.login(self.email, self.token)
if email is None or token is None:
print("Please set email and token in config.json.")
else:
print("Client doest not login, all tests will be ignored!")
cls.client.login(email, token)

@unittest.skipIf(not client.is_login(), "Client doest not login!")
def test_upload(self):
@@ -61,7 +70,7 @@ class TestUpload(unittest.TestCase):

def suite():
_suite = unittest.TestSuite()
_suite.addTest(TestUpload("test_upload", email=None, token=None))
_suite.addTest(TestUpload("test_upload"))
return _suite

if __name__ == "__main__":


Loading…
Cancel
Save