Skip to content

Commit

Permalink
LITE-27890 Add entity api representation to configurqtion objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatrios committed Jul 7, 2023
1 parent 7fad1ad commit c085cbb
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 19 deletions.
10 changes: 5 additions & 5 deletions connect_ext_ppr/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from connect_ext_ppr.db import Model
from connect_ext_ppr.models.deployment import Deployment
from connect_ext_ppr.models.enums import ConfigurationStateChices
from connect_ext_ppr.models.enums import ConfigurationStateChoices
from connect_ext_ppr.models.file import File


Expand All @@ -17,16 +17,16 @@ class Configuration(Model):
file = db.Column(db.ForeignKey(File.id))
deployment = db.Column(db.ForeignKey(Deployment.id))
state = db.Column(
db.Enum(ConfigurationStateChices, validate_strings=True),
default=ConfigurationStateChices.INACTIVE,
db.Enum(ConfigurationStateChoices, validate_strings=True),
default=ConfigurationStateChoices.INACTIVE,
)
created_at = db.Column(db.DateTime(), default=datetime.utcnow)
created_by = db.Column(db.String(20))
updated_at = db.Column(db.DateTime(), default=datetime.utcnow)
updated_by = db.Column(db.String(20))

def activate(self):
self.state = ConfigurationStateChices.ACTIVE
self.state = ConfigurationStateChoices.ACTIVE

def deleted(self):
self.state = ConfigurationStateChices.DELETED
self.state = ConfigurationStateChoices.DELETED
2 changes: 1 addition & 1 deletion connect_ext_ppr/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MimeTypeChoices(str, enum.Enum):
application_vnd_ms_xslx = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'


class ConfigurationStateChices(str, enum.Enum):
class ConfigurationStateChoices(str, enum.Enum):
ACTIVE = 'active'
INACTIVE = 'inactive'
DELETED = 'deleted'
29 changes: 22 additions & 7 deletions connect_ext_ppr/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@

from pydantic import BaseModel

from connect_ext_ppr.models.enums import DeploymentStatusChoices
from connect_ext_ppr.models.enums import ConfigurationStateChoices, DeploymentStatusChoices


class Vendor(BaseModel):
class VendorSchema(BaseModel):
id: str
name: str
icon: Optional[str]


class Product(BaseModel):
class ProductSchema(BaseModel):
id: str
name: str
icon: Optional[str]


class Hub(BaseModel):
class HubSchema(BaseModel):
id: str
name: str


class DeploymentSchema(BaseModel):
id: str
product: Product
hub: Hub
product: ProductSchema
hub: HubSchema
account_id: str
owner: Vendor
owner: VendorSchema
last_sync_at: datetime
status: DeploymentStatusChoices
events: Dict[str, Dict[str, Union[datetime, str]]]
Expand All @@ -45,3 +45,18 @@ class DeploymentRequestSchema(BaseModel):

class Config:
orm_mode = True


class FileSchema(BaseModel):
id: str
name: str
location: str
size: int


class ConfigurationSchema(BaseModel):
id: str
file: FileSchema
deployment: Dict[str, str]
state: ConfigurationStateChoices
events: Dict[str, Dict[str, Union[datetime, str]]]
54 changes: 54 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/test_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from connect_ext_ppr.db import get_db, get_db_ctx_manager, VerboseBaseSession


def test_get_db(engine):
db = next(get_db(engine))
assert isinstance(db, VerboseBaseSession)
assert db.connection().connect()


def test_get_db_ctx_manager(mocker, engine):
mocker.patch(
'connect_ext_ppr.db.get_engine',
return_value=engine,
)
with get_db_ctx_manager({}) as db:
assert isinstance(db, VerboseBaseSession)
assert db.connection().connect()
66 changes: 61 additions & 5 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@

import pytest

from connect_ext_ppr.models.deployment import DeploymentStatusChoices
from connect_ext_ppr.schemas import DeploymentSchema, Hub, Product, Vendor
from connect_ext_ppr.models.enums import (
ConfigurationStateChoices,
DeploymentStatusChoices,
)
from connect_ext_ppr.schemas import (
ConfigurationSchema,
DeploymentSchema,
FileSchema,
HubSchema,
ProductSchema,
VendorSchema,
)


@pytest.mark.parametrize(
Expand All @@ -16,17 +26,17 @@ def test_deployment_schema(status):
iso = now.isoformat()
serializer = DeploymentSchema(
id='DPL-000-000-000',
product=Product(
product=ProductSchema(
id='PRD-000-000-000',
name='Some',
icon='/media/VA-000-000/PRD-000-000-000/media/PRD-000-000-000-logo_cLqk6Vm.png',
),
hub=Hub(
hub=HubSchema(
id='HB-1111-2222',
name='Hub Hub',
),
account_id='PA-000-000',
owner=Vendor(
owner=VendorSchema(
id='VA-000-000',
name='Vendor',
icon='/media/VA-000-000/media/icon.png',
Expand Down Expand Up @@ -61,3 +71,49 @@ def test_deployment_schema(status):
},
},
})


@pytest.mark.parametrize(
'state',
ConfigurationStateChoices,
)
def test_configuration_schema(state, file):
now = datetime.utcnow()
iso = now.isoformat()
serializer = ConfigurationSchema(
id='CFL-000-000-000',
file=FileSchema(
id=file.id,
name=file.name,
location=file.location,
size=file.size,
),
deployment={'id': 'DPL-000-000-000'},
state=state,
events={
'created': {'at': now, 'by': 'SU-295-689-628'},
'updated': {'at': now, 'by': 'SU-295-689-628'},
},
)
json = serializer.json()
assert json == j.dumps({
"id": "CFL-000-000-000",
"file": {
"id": file.id,
"name": file.name,
"location": file.location,
"size": file.size,
},
"deployment": {"id": "DPL-000-000-000"},
"state": state,
"events": {
"created": {
"at": iso,
"by": "SU-295-689-628",
},
"updated": {
"at": iso,
"by": "SU-295-689-628",
},
},
})
Loading

0 comments on commit c085cbb

Please sign in to comment.