Skip to content

Commit

Permalink
Addding a displayname to a user object (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vucis authored Apr 18, 2024
1 parent 12120eb commit f2de32a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
1 change: 1 addition & 0 deletions backend/db_construct.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CREATE TYPE runner AS ENUM ('PYTHON', 'GENERAL', 'CUSTOM');

CREATE TABLE users (
uid VARCHAR(255),
display_name VARCHAR(255),
role role NOT NULL,
PRIMARY KEY(uid)
);
Expand Down
11 changes: 8 additions & 3 deletions backend/project/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ class Role(Enum):

@dataclass
class User(db.Model):
"""This class defines the users table,
a user has a uid and a role, a user
can be either a student,admin or teacher"""
"""
This class defines the users table
a user has a uid,
a display_name and a role,
this role can be either student, admin or teacher
"""

__tablename__ = "users"
uid: str = Column(String(255), primary_key=True)
display_name: str = Column(String(255))
role: Role = Column(EnumField(Role), nullable=False)
def to_dict(self):
"""
Expand All @@ -27,4 +31,5 @@ def to_dict(self):
return {
'uid': self.uid,
'role': self.role.name, # Convert the enum to a string
'display_name': self.display_name
}
22 changes: 11 additions & 11 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ def auth_tokens(session: Session) -> None:
"""Add the authenticated users to the database"""

session.add_all([
User(uid="login", role=Role.STUDENT),
User(uid="student", role=Role.STUDENT),
User(uid="student_other", role=Role.STUDENT),
User(uid="teacher", role=Role.TEACHER),
User(uid="teacher_other", role=Role.TEACHER),
User(uid="admin", role=Role.ADMIN),
User(uid="admin_other", role=Role.ADMIN)
User(uid="login", role=Role.STUDENT, display_name="Login User"),
User(uid="student", role=Role.STUDENT, display_name="Student Person"),
User(uid="student_other", role=Role.STUDENT, display_name="Student Other Person"),
User(uid="teacher", role=Role.TEACHER, display_name="Teacher Person"),
User(uid="teacher_other", role=Role.TEACHER, display_name="Teacher Other"),
User(uid="admin", role=Role.ADMIN, display_name="Admin Man"),
User(uid="admin_other", role=Role.ADMIN, display_name="Admin Woman")
])
session.commit()

Expand Down Expand Up @@ -117,10 +117,10 @@ def db_session():
def users():
"""Return a list of users to populate the database"""
return [
User(uid="brinkmann", role=Role.ADMIN),
User(uid="laermans", role=Role.ADMIN),
User(uid="student01", role=Role.STUDENT),
User(uid="student02", role=Role.STUDENT)
User(uid="brinkmann", role=Role.ADMIN, display_name="Gunnar Brinkmann"),
User(uid="laermans", role=Role.ADMIN, display_name="Eric Laermans"),
User(uid="student01", role=Role.STUDENT, display_name="Student Zero One"),
User(uid="student02", role=Role.STUDENT, display_name="Student Zero Two")
]

def courses():
Expand Down
13 changes: 7 additions & 6 deletions backend/tests/endpoints/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def valid_user():
"""
return {
"uid": "w_student",
"role": Role.STUDENT.name
"role": Role.STUDENT.name,
"display_name": "Valid User"
}

@pytest.fixture
Expand All @@ -180,10 +181,10 @@ def valid_user_entries(session):
Returns a list of users that are in the database
"""
users = [
User(uid="del", role=Role.TEACHER),
User(uid="pat", role=Role.TEACHER),
User(uid="u_get", role=Role.TEACHER),
User(uid="query_user", role=Role.ADMIN)]
User(uid="del", role=Role.TEACHER, display_name="Peter Deleter"),
User(uid="pat", role=Role.TEACHER, display_name="Patrick Patcher"),
User(uid="u_get", role=Role.TEACHER, display_name="User Getter"),
User(uid="query_user", role=Role.ADMIN, display_name="Quentin Query")]

session.add_all(users)
session.commit()
Expand Down Expand Up @@ -222,7 +223,7 @@ def files():
@pytest.fixture
def course_teacher_ad():
"""A user that's a teacher for testing"""
ad_teacher = User(uid="Gunnar", role=Role.TEACHER)
ad_teacher = User(uid="Gunnar", role=Role.TEACHER, display_name="Gunnar Brinckmann")
return ad_teacher

@pytest.fixture
Expand Down

0 comments on commit f2de32a

Please sign in to comment.