Skip to content

Commit

Permalink
Refs #79. Added test_type_uuid and capabilities fields in database st…
Browse files Browse the repository at this point in the history
…ructure.
  • Loading branch information
SBriere committed Mar 29, 2022
1 parent dec5f80 commit 1c87f26
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ def upgrade():
sa.Column('id_test_type', sa.Integer, sa.Sequence('id_test_type_sequence'),
primary_key=True, autoincrement=True),
sa.Column('id_service', sa.Integer, sa.ForeignKey('t_services.id_service'), nullable=False),
sa.Column('test_type_uuid', sa.String(36), nullable=False, unique=True),
sa.Column('test_type_name', sa.String, nullable=False, unique=False),
sa.Column('test_type_description', sa.String, nullable=True)
sa.Column('test_type_description', sa.String, nullable=True),
sa.Column('test_type_has_json_format', sa.Boolean, nullable=False, default=False),
sa.Column('test_type_has_web_format', sa.Boolean, nullable=False, default=False),
sa.Column('test_type_has_web_editor', sa.Boolean, nullable=False, default=False)
)
op.execute(CreateSequence(sa.Sequence('id_test_type_sequence')))

Expand Down
21 changes: 21 additions & 0 deletions teraserver/python/opentera/db/models/TeraTestType.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from opentera.db.Base import db, BaseModel
import uuid


class TeraTestType(db.Model, BaseModel):
__tablename__ = 't_tests_types'
id_test_type = db.Column(db.Integer, db.Sequence('id_test_type_sequence'), primary_key=True, autoincrement=True)
id_service = db.Column(db.Integer, db.ForeignKey("t_services.id_service"), nullable=False)
test_type_uuid = db.Column(db.String(36), nullable=False, unique=True)
test_type_name = db.Column(db.String, nullable=False, unique=False)
test_type_description = db.Column(db.String, nullable=True)
# Test type service provides TeraForm style json format?
test_type_has_json_format = db.Column(db.Boolean, nullable=False, default=False)
# Test type service provides a generated HTML form?
test_type_has_web_format = db.Column(db.Boolean, nullable=False, default=False)
# Test type service provides a web based editor?
test_type_has_web_editor = db.Column(db.Boolean, nullable=False, default=False)

test_type_service = db.relationship("TeraService", cascade='delete')

Expand Down Expand Up @@ -34,18 +42,26 @@ def create_defaults(test=False):
test.test_type_name = 'Pre-session evaluation'
test.test_type_description = 'Evaluation shown before a session'
test.id_service = TeraService.get_service_by_key('VideoRehabService').id_service
test.test_type_uuid = str(uuid.uuid4())
test.test_type_has_json_format = True
db.session.add(test)

test = TeraTestType()
test.test_type_name = 'Post-session evaluation'
test.test_type_description = 'Evaluation shown after a session'
test.id_service = TeraService.get_service_by_key('VideoRehabService').id_service
test.test_type_uuid = str(uuid.uuid4())
test.test_type_has_json_format = True
test.test_type_has_web_format = True
db.session.add(test)

test = TeraTestType()
test.test_type_name = 'General survey'
test.test_type_description = 'General satisfaction survey'
test.id_service = TeraService.get_service_by_key('BureauActif').id_service
test.test_type_uuid = str(uuid.uuid4())
test.test_type_has_web_format = True
test.test_type_has_web_editor = True
db.session.add(test)

db.session.commit()
Expand All @@ -58,4 +74,9 @@ def get_test_type_by_id(test_type_id: int):
def get_test_types_for_service(id_service: int):
return TeraTestType.query.filter_by(id_service=id_service).all()

@classmethod
def insert(cls, test_type):
# Generate UUID
test_type.test_type_uuid = str(uuid.uuid4())

super().insert(test_type)
6 changes: 4 additions & 2 deletions teraserver/python/opentera/db/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .TeraSessionTypeProject import TeraSessionTypeProject
from .TeraSessionUsers import TeraSessionUsers
from .TeraSite import TeraSite
from .TeraTest import TeraTest
# from .TeraTest import TeraTest
from .TeraTestType import TeraTestType
from .TeraUser import TeraUser
from .TeraUserGroup import TeraUserGroup
Expand Down Expand Up @@ -76,8 +76,10 @@
'TeraSessionTypeSite',
'TeraSessionUsers',
'TeraSite',
'TeraTest',
# 'TeraTest',
'TeraTestType',
'TeraTestTypeSite',
'TeraTestTypeProject',
'TeraUser',
'TeraUserGroup',
'TeraUserPreference',
Expand Down

0 comments on commit 1c87f26

Please sign in to comment.