Esempio n. 1
0
    def setUp(self):
        super().setUp()
        dt = datetime.now()
        self.news = News(id=None,
                         created_date=dt,
                         modified_date=dt,
                         title='News title',
                         content='News content')
        cur = self.conn.cursor()
        cur.execute(
            'INSERT INTO news (created_date, modified_date, title, content) VALUES(?, ?, ?, ?)',
            (datetime_to_timestamp(self.news.created_date),
             datetime_to_timestamp(
                 self.news.modified_date), self.news.title, self.news.content))
        self.news.id = cur.lastrowid

        self.comment = Comment(id=None,
                               created_date=dt,
                               modified_date=dt,
                               news_id=self.news.id,
                               content='Comment content')
        cur.execute(
            'INSERT INTO comment (created_date, modified_date, news_id, content) VALUES(?, ?, ?, ?)',
            (datetime_to_timestamp(self.comment.created_date),
             datetime_to_timestamp(self.comment.modified_date),
             self.comment.news_id, self.comment.content))
        self.comment.id = cur.lastrowid
        self.comment_repository = CommentRepository(connection=self.conn)
Esempio n. 2
0
 def obj_to_data(self, obj: Comment) -> tuple:
     return (datetime_to_timestamp(obj.created_date),
             datetime_to_timestamp(obj.modified_date), obj.news_id,
             obj.content)
Esempio n. 3
0
 def obj_to_data(self, obj: News) -> tuple:
     return (datetime_to_timestamp(obj.created_date),
             datetime_to_timestamp(obj.modified_date), obj.title,
             obj.content)
Esempio n. 4
0
 def test_datetime_to_timestamp(self):
     self.assertEqual(datetime_to_timestamp(self.datetime), self.ts)