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

Add tags and tickets fields to get cases request #5564

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding tests
kevgliss committed Dec 12, 2024
commit 6dffe77e031b798c4af01db4d4ea71c9ba9d25c0
20 changes: 1 addition & 19 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -17,29 +17,11 @@
"files.trimFinalNewlines": true,
"files.insertFinalNewline": true,
"vetur.format.enable": false,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"100"
],
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--ignore=E24,W504,E501",
"--verbose"
],
"python.testing.pytestEnabled": true,
"python.sortImports.args": [
"--settings-path",
"${workspaceFolder}/setup.cfg"
],
"python.linting.pylintArgs": [
"--rcfile",
"${workspaceFolder}/setup.cfg"
],
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "never"
}
},
"codeQL.githubDatabase.update": "never",
}
2 changes: 2 additions & 0 deletions src/dispatch/case/models.py
Original file line number Diff line number Diff line change
@@ -286,6 +286,8 @@ class CaseReadMinimal(CaseBase):
dedicated_channel: Optional[bool]
name: Optional[NameStr]
project: ProjectRead
tags: Optional[List[TagRead]] = []
ticket: Optional[TicketRead] = None
reporter: Optional[ParticipantReadMinimal]
reported_at: Optional[datetime] = None
total_cost: float | None
42 changes: 37 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from sqlalchemy_utils import drop_database, database_exists
from starlette.config import environ
from starlette.testclient import TestClient
from fastapi.testclient import TestClient

# set test config
environ["DATABASE_CREDENTIALS"] = "postgres:dispatch"
@@ -19,6 +19,7 @@
from dispatch import config
from dispatch.database.core import engine
from dispatch.database.manage import init_database
from dispatch.enums import Visibility, UserRoles

from .database import Session
from .factories import (
@@ -32,6 +33,7 @@
ConversationFactory,
DefinitionFactory,
DispatchUserFactory,
DispatchUserOrganizationFactory,
DocumentFactory,
EmailTemplateFactory,
EntityFactory,
@@ -98,13 +100,13 @@ def pytest_runtest_makereport(item, call):
@pytest.fixture(scope="session")
def testapp():
# we only want to use test plugins so unregister everybody else
from dispatch.main import app
from dispatch.main import api
from dispatch.plugins.base import plugins, unregister

for p in plugins.all():
unregister(p)
unregister(p.__class__)

yield app
yield api


@pytest.fixture(scope="session")
@@ -137,7 +139,7 @@ def session(db):


@pytest.fixture(scope="function")
def client(testapp, session, client):
def client(testapp, session):
yield TestClient(testapp)


@@ -272,6 +274,18 @@ def user(session):
return DispatchUserFactory()


@pytest.fixture
def admin_user(session):
# we need to create a new user with the admin role
user = DispatchUserFactory()
organization = OrganizationFactory()
user_organization = DispatchUserOrganizationFactory(
dispatch_user=user, organization=organization, role=UserRoles.admin
)

return user


@pytest.fixture
def tag(session):
return TagFactory()
@@ -532,6 +546,24 @@ def incident(session):
return IncidentFactory()


@pytest.fixture()
def incidents(session):
return [
IncidentFactory(
title="Test Incident 1",
description="Description 1",
visibility=Visibility.open,
tags=[TagFactory()],
),
IncidentFactory(
title="Test Incident 2", description="Description 2", visibility=Visibility.restricted
),
IncidentFactory(
title="Another Incident", description="Description 3", visibility=Visibility.open
),
]


@pytest.fixture
def participant_activity(session):
return ParticipantActivityFactory()
35 changes: 34 additions & 1 deletion tests/factories.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
from faker.providers import misc
from pytz import UTC

from dispatch.auth.models import DispatchUser, hash_password # noqa
from dispatch.auth.models import DispatchUser, DispatchUserOrganization, hash_password # noqa
from dispatch.case.models import Case, CaseRead
from dispatch.case.priority.models import CasePriority
from dispatch.case.severity.models import CaseSeverity
@@ -64,6 +64,7 @@
from dispatch.term.models import Term
from dispatch.ticket.models import Ticket
from dispatch.workflow.models import Workflow, WorkflowInstance
from dispatch.enums import UserRoles, Visibility

from .database import Session

@@ -126,6 +127,19 @@ def projects(self, create, extracted, **kwargs):
self.projects.append(project)


class DispatchUserOrganizationFactory(BaseFactory):
"""Dispatch User Organization Factory."""

dispatch_user = SubFactory(DispatchUserFactory)
organization = SubFactory(OrganizationFactory)
role = UserRoles.member

class Meta:
"""Factory Configuration."""

model = DispatchUserOrganization


class ProjectFactory(BaseFactory):
"""Project Factory."""

@@ -770,6 +784,15 @@ class Meta:

model = Case

@post_generation
def tags(self, create, extracted, **kwargs):
if not create:
return

if extracted:
for tag in extracted:
self.tags.append(tag)

class Params:
status = "New"

@@ -919,6 +942,7 @@ class IncidentFactory(BaseFactory):
incident_severity = SubFactory(IncidentSeverityFactory)
project = SubFactory(ProjectFactory)
conversation = SubFactory(ConversationFactory)
visibility = Visibility.open

class Meta:
"""Factory Configuration."""
@@ -934,6 +958,15 @@ def participants(self, create, extracted, **kwargs):
for participant in extracted:
self.participants.append(participant)

@post_generation
def tags(self, create, extracted, **kwargs):
if not create:
return

if extracted:
for tag in extracted:
self.tags.append(tag)


class TaskFactory(ResourceBaseFactory):
"""Task Factory."""