Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Subscription model definition #434

Closed
Closed
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
3 changes: 2 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
)
16 changes: 1 addition & 15 deletions api/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.\
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_subscribe_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading