51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import unittest
|
|
import re
|
|
from datetime import datetime
|
|
from datetime import timedelta
|
|
from pony.orm import db_session
|
|
from ITPlanning import db
|
|
from tests.assets.filldb import filldatabase
|
|
|
|
DATE_REGEX = r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$"
|
|
|
|
|
|
class DbTestCase(unittest.TestCase):
|
|
def setUp(self):
|
|
db.init_database("sqlite:")
|
|
|
|
def tearDown(self):
|
|
db.release_database()
|
|
|
|
@db_session
|
|
def test_appointement(self):
|
|
current_date = datetime.now()
|
|
customer = filldatabase.create_Customer()
|
|
service = filldatabase.create_service()
|
|
planning = filldatabase.create_planning()
|
|
planning.services.add(service)
|
|
|
|
end_datetime = current_date + timedelta(
|
|
minutes=service.service_category.duration
|
|
)
|
|
|
|
appointment = db.Appointment(
|
|
book_datetime=current_date,
|
|
start_datetime=current_date,
|
|
end_datetime=end_datetime,
|
|
is_unavaillable=False,
|
|
service=service,
|
|
planning=planning,
|
|
customer=customer,
|
|
)
|
|
self.assertIsInstance(appointment, db.Appointment)
|
|
self.assertIsInstance(appointment.book_datetime, datetime)
|
|
self.assertIsInstance(appointment.start_datetime, datetime)
|
|
self.assertIsInstance(appointment.end_datetime, datetime)
|
|
self.assertIsInstance(appointment.service, db.Service)
|
|
self.assertIsInstance(appointment.planning, db.Planning)
|
|
self.assertIsInstance(appointment.customer, db.Customer)
|
|
|
|
|
|
if __name__ == "main":
|
|
unittest.main()
|