From 9750ab54546d707b39b24c81071ae5369b92184f Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Thu, 19 Jan 2023 16:13:10 +0300 Subject: [PATCH] Test state: assertion error --- mirrortea/repository/sqlite_repository.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mirrortea/repository/sqlite_repository.py b/mirrortea/repository/sqlite_repository.py index d66dbb4..8dbf605 100644 --- a/mirrortea/repository/sqlite_repository.py +++ b/mirrortea/repository/sqlite_repository.py @@ -35,10 +35,8 @@ class SQLiteDatabaseRepository(AbstractDatabaseRepository): self.conn = sqlite3.connect(self.path) self.cursor = self.conn.cursor() - def _namedtuple_factory(cursor, row, raw_tuples): - # TODO: fix that. Here causes errors. Or remove namedtyples and use normal index tuple. Also, row - is cursor - # Good luck - fields = [column[0] for column in row.description] + def _namedtuple_factory(row, cursor, raw_tuples): + fields = [column[0] for column in cursor.description] cls = namedtuple("Row", fields) return cls._make(raw_tuples) @@ -52,7 +50,7 @@ class SQLiteDatabaseRepository(AbstractDatabaseRepository): def get_user_by_id(self, user_id: str) -> User: """Get user by user id""" - self.conn.row_factory = self._namedtuple_factory # Error here, not use named + self.conn.row_factory = self._namedtuple_factory self.cur_userdata = self.conn.execute( "SELECT user_id AS user_id, first_name AS first_name, last_name AS last_name, username AS username, avatar_hash AS avatar_hash FROM platforms_users WHERE user_id = (?)", @@ -65,9 +63,9 @@ class SQLiteDatabaseRepository(AbstractDatabaseRepository): return UserNotFoundError("User not found!") return User( - id=user_id, - first_name=self.userdata.user_id, - last_name=self.userdata.first_name, + user_id=self.userdata.user_id, + first_name=self.userdata.first_name, + last_name=self.userdata.last_name, username=self.userdata.username, avatar_hash=self.userdata.avatar_hash, ) @@ -90,7 +88,6 @@ class SQLiteDatabaseRepository(AbstractDatabaseRepository): return UserAlreadyExistError("User already exist!") self.conn.commit() - return self.get_user_by_id(user_id=user.user_id) def update_user(self) -> None: