# Path: hakoblog/db.py
# class DB:
#     def __init__(self):
#         self.conn = MySQLdb.connect(
#             db=CONFIG.DATABASE,
#             host=CONFIG.DATABASE_HOST,
#             user=CONFIG.DATABASE_USER,
#             password=CONFIG.DATABASE_PASS,
#             cursorclass=MySQLdb.cursors.DictCursor,
#             charset="utf8",
#         )
#         self.conn.autocommit(True)
# 
#     def cursor(self):
#         return self.conn.cursor()
# 
#     def close(self):
#         self.conn.close()
# 
#     def uuid_short(self):
#         with self.conn.cursor() as cursor:
#             cursor.execute("SELECT UUID_SHORT() as uuid")
#             return cursor.fetchone().get("uuid")
# 
# Path: hakoblog/loader/blog.py
# class BlogLoader:
#     @classmethod
#     def find_by_id(cls, db, blog_id):
#         with db.cursor() as cursor:
#             cursor.execute(
#                 """
#                 SELECT id, owner_id, title
#                 FROM blog
#                 WHERE id = %s
#                 LIMIT 1
#                 """,
#                 (blog_id,),
#             )
#             row = cursor.fetchone()
# 
#             if row is None:
#                 return None
# 
#         return Blog(**row)
# 
#     @classmethod
#     def find_by_owner_id(cls, db, owner_id):
#         with db.cursor() as cursor:
#             cursor.execute(
#                 """
#                 SELECT id, owner_id, title
#                 FROM blog
#                 WHERE owner_id = %s
#                 LIMIT 1
#                 """,
#                 (owner_id,),
#             )
#             row = cursor.fetchone()
# 
#             if row is None:
#                 return None
# 
#         return Blog(**row)
# 
# Path: tests/util.py
# def create_user():
#     db = DB()
#     name = random_string(10)
#     UserAction.create(db, name)
#     return UserLoader.find_by_name(db, name)
# 
# def create_blog(user=None):
#     db = DB()
# 
#     if user is None:
#         user = create_user()
# 
#     new_blog_id = BlogAction.create(
#         db,
#         owner_id=user.id,
#         title=random_string(10),
#     )
#     return BlogLoader.find_by_id(db, new_blog_id)


import tests.hakoblog  # noqa: F401
from hakoblog.db import DB
from hakoblog.loader.blog import BlogLoader
from tests.util import create_user, create_blog




def test_find_by_id():
    db = DB()

    user = create_user()

# Path: hakoblog/db.py
# class DB:
#     def __init__(self):
#         self.conn = MySQLdb.connect(
#             db=CONFIG.DATABASE,
#             host=CONFIG.DATABASE_HOST,
#             user=CONFIG.DATABASE_USER,
#             password=CONFIG.DATABASE_PASS,
#             cursorclass=MySQLdb.cursors.DictCursor,
#             charset="utf8",
#         )
#         self.conn.autocommit(True)
# 
#     def cursor(self):
#         return self.conn.cursor()
# 
#     def close(self):
#         self.conn.close()
# 
#     def uuid_short(self):
#         with self.conn.cursor() as cursor:
#             cursor.execute("SELECT UUID_SHORT() as uuid")
#             return cursor.fetchone().get("uuid")
# 
# Path: hakoblog/loader/blog.py
# class BlogLoader:
#     @classmethod
#     def find_by_id(cls, db, blog_id):
#         with db.cursor() as cursor:
#             cursor.execute(
#                 """
#                 SELECT id, owner_id, title
#                 FROM blog
#                 WHERE id = %s
#                 LIMIT 1
#                 """,
#                 (blog_id,),
#             )
#             row = cursor.fetchone()
# 
#             if row is None:
#                 return None
# 
#         return Blog(**row)
# 
#     @classmethod
#     def find_by_owner_id(cls, db, owner_id):
#         with db.cursor() as cursor:
#             cursor.execute(
#                 """
#                 SELECT id, owner_id, title
#                 FROM blog
#                 WHERE owner_id = %s
#                 LIMIT 1
#                 """,
#                 (owner_id,),
#             )
#             row = cursor.fetchone()
# 
#             if row is None:
#                 return None
# 
#         return Blog(**row)
# 
# Path: tests/util.py
# def create_user():
#     db = DB()
#     name = random_string(10)
#     UserAction.create(db, name)
#     return UserLoader.find_by_name(db, name)
# 
# def create_blog(user=None):
#     db = DB()
# 
#     if user is None:
#         user = create_user()
# 
#     new_blog_id = BlogAction.create(
#         db,
#         owner_id=user.id,
#         title=random_string(10),
#     )
#     return BlogLoader.find_by_id(db, new_blog_id)


# Path: tests/loader/test_blog.py
import tests.hakoblog  # noqa: F401
from hakoblog.db import DB
from hakoblog.loader.blog import BlogLoader
from tests.util import create_user, create_blog





def test_find_by_id():
    db = DB()

    user = create_user()

    blog = create_blog(user=user)