Skip to content

Commit

Permalink
Simplify room login code
Browse files Browse the repository at this point in the history
  • Loading branch information
Moutix committed Feb 17, 2017
1 parent 112f44d commit 6f34b9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 2 additions & 5 deletions smserver/models/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,8 @@ def login(cls, name, password, session):
.filter_by(name=name)
.filter(or_(
cls.password.is_(None),
and_(
cls.password.isnot(None),
cls.password == password
)))
.one_or_none()
cls.password == password
)).one_or_none()
)

@classmethod
Expand Down
6 changes: 6 additions & 0 deletions test/test_models/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,19 @@ def test_login(self):
models.Room.login("name", "pass", self.session)
)

# Room without password
room = RoomFactory(name="Room 1")

self.assertEqual(
models.Room.login("Room 1", None, self.session),
room
)
self.assertEqual(
models.Room.login("Room 1", "password", self.session),
room
)

# Room with password
password = hashlib.sha256("pass".encode('utf-8')).hexdigest()
room = RoomFactory(name="Room 2", password=password)

Expand Down

0 comments on commit 6f34b9f

Please sign in to comment.