39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from app.clients.modelhub import ModelHubClient
|
|
from app.settings import Settings
|
|
|
|
|
|
class FakeResponse:
|
|
def __init__(self, body):
|
|
self.body = body
|
|
def json(self):
|
|
return self.body
|
|
|
|
|
|
class FakeSession:
|
|
def __init__(self, body):
|
|
self.body = body
|
|
def post(self, *args, **kwargs):
|
|
return FakeResponse(self.body)
|
|
|
|
|
|
def make_client(body):
|
|
settings = Settings(
|
|
auth_token="a", hf_token="h", contest_api_token="c", email="e", user_id="1",
|
|
contributors="u", strategy_id="s", submit_dry_run=False
|
|
)
|
|
client = ModelHubClient(settings)
|
|
client.session = FakeSession(body)
|
|
return client
|
|
|
|
|
|
def test_submit_success_mapping():
|
|
assert make_client({"code": 0, "message": "ok"}).create_contest_task("m", "hygon_k100-ai", "cfg").result == "success"
|
|
|
|
|
|
def test_submit_queue_full_mapping():
|
|
assert make_client({"code": 60007, "message": "full"}).create_contest_task("m", "hygon_k100-ai", "cfg").result == "queue_full"
|
|
|
|
|
|
def test_submit_conflict_mapping():
|
|
assert make_client({"code": 40000, "message": "正在验证中"}).create_contest_task("m", "hygon_k100-ai", "cfg").result == "conflict"
|