2021-06-01 12:16:05 +00:00
|
|
|
import unittest
|
|
|
|
import re
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
|
|
|
from pony.orm import db_session
|
|
|
|
from ITPlanning import db
|
2021-06-13 19:03:17 +00:00
|
|
|
from tests.assets.filldb import filldatabase
|
2021-06-01 12:16:05 +00:00
|
|
|
|
|
|
|
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()
|
2021-06-13 19:03:17 +00:00
|
|
|
customer = filldatabase.create_Customer()
|
|
|
|
service = filldatabase.create_service()
|
|
|
|
planning = filldatabase.create_planning()
|
2021-06-01 12:16:05 +00:00
|
|
|
planning.services.add(service)
|
2021-06-13 19:03:17 +00:00
|
|
|
|
2021-06-01 12:16:05 +00:00
|
|
|
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()
|