Added database table test

This commit is contained in:
Sven Heidemann 2021-03-29 14:29:17 +02:00
parent 4d5368e5fc
commit d0812bcf5c
3 changed files with 22 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from cpl.console import Console
from cpl.dependency_injection import ServiceProviderABC
from cpl.logging import LoggerABC
from model.user_repo_abc import UserRepoABC
from model.user_repo import UserRepo
class Application(ApplicationABC):
@ -23,4 +24,13 @@ class Application(ApplicationABC):
self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}')
self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}')
self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}')
self._services.get_service(UserRepoABC).add_test_user()
user_repo: UserRepo = self._services.get_service(UserRepoABC)
user_repo.add_test_user()
Console.write_line('Users:')
for user in user_repo.get_users():
Console.write_line(user.Id, user.Name, user.City_Id, user.City.Id, user.City.Name, user.City.ZIP)
Console.write_line('Cities:')
for city in user_repo.get_cities():
Console.write_line(city.Id, city.Name, city.ZIP)

View File

@ -21,3 +21,9 @@ class UserRepo(UserRepoABC):
user = UserModel('TestUser', city)
self._session.add(user)
self._session.commit()
def get_users(self) -> list[UserModel]:
return self._session.query(UserModel).all()
def get_cities(self) -> list[CityModel]:
return self._session.query(CityModel).all()

View File

@ -1,7 +1,12 @@
from abc import ABC, abstractmethod
from .user_model import UserModel
class UserRepoABC(ABC):
@abstractmethod
def __init__(self): pass
@abstractmethod
def get_users(self) -> list[UserModel]: pass