diff --git a/api/main.py b/api/main.py index 238419cd..b1344633 100644 --- a/api/main.py +++ b/api/main.py @@ -35,10 +35,11 @@ Regression, UserGroup, PublishEvent, + Subscription, get_model_from_kind ) from .paginator_models import PageModel -from .pubsub import PubSub, Subscription +from .pubsub import PubSub from .user_manager import get_user_manager, create_user_manager from .user_models import ( User, diff --git a/api/models.py b/api/models.py index 8d9f3bec..dbb42966 100644 --- a/api/models.py +++ b/api/models.py @@ -383,3 +383,17 @@ class PublishEvent(BaseModel): attributes: Optional[Dict] = Field( description="Extra Cloudevents Extension Context Attributes" ) + + +class Subscription(BaseModel): + """Pub/Sub subscription object model""" + id: int = Field( + description='Subscription ID' + ) + channel: str = Field( + description='Subscription channel name' + ) + user: str = Field( + description=("Username of the user that created the " + "subscription (owner)") + ) diff --git a/api/pubsub.py b/api/pubsub.py index 93365789..54967c31 100644 --- a/api/pubsub.py +++ b/api/pubsub.py @@ -10,22 +10,8 @@ import json from redis import asyncio as aioredis from cloudevents.http import CloudEvent, to_json -from pydantic import BaseModel, Field from .config import PubSubSettings - - -class Subscription(BaseModel): - """Pub/Sub subscription object model""" - id: int = Field( - description='Subscription ID' - ) - channel: str = Field( - description='Subscription channel name' - ) - user: str = Field( - description=("Username of the user that created the " - "subscription (owner)") - ) +from .models import Subscription class PubSub: diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index 7a97ec2d..59d9519b 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -26,9 +26,9 @@ get_current_user, get_current_superuser, ) -from api.models import UserGroup +from api.models import UserGroup, Subscription from api.user_models import User -from api.pubsub import PubSub, Subscription +from api.pubsub import PubSub BEARER_TOKEN = "Bearer \ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJib2IifQ.\ diff --git a/tests/unit_tests/test_subscribe_handler.py b/tests/unit_tests/test_subscribe_handler.py index aaf2614d..f9fd2655 100644 --- a/tests/unit_tests/test_subscribe_handler.py +++ b/tests/unit_tests/test_subscribe_handler.py @@ -8,7 +8,7 @@ """Unit test function for KernelCI API subscribe handler""" from tests.unit_tests.conftest import BEARER_TOKEN -from api.pubsub import Subscription +from api.models import Subscription def test_subscribe_endpoint(mock_subscribe, test_client):