示例#1
0
文件: storages.py 项目: A03ki/uecbbs
    def _create(self, name, since_id=None, max_id=None):
        """
        Raises
        ------
        ValueError
            既に同一の ``name`` が存在するとき
        """
        session = self.session()
        timelineindex = TimelineIndex.find_by_name(name, session)
        if timelineindex is not None:
            raise ValueError(("`name`: '{name}' exist.").format(name=name))

        row = TimelineIndex(name=name, since_id=since_id, max_id=max_id)
        session.add(row)
        session.commit()
示例#2
0
文件: storages.py 项目: A03ki/uecbbs
    def _update(self, name, since_id, max_id):
        """
        Raises
        ------
        ValueError
            対応する ``name`` が存在しないとき
        """
        session = self.session()
        timelineindex = TimelineIndex.find_by_name(name, session)
        if timelineindex is None:
            raise ValueError(
                ("`name`: '{name}' dosen't exist.").format(name=name))

        row = TimelineIndex.find_by_name(name, session)
        row.since_id = since_id
        row.max_id = max_id
        session.commit()
示例#3
0
 def test_find_by_name_default_none(self):
     names = ["home_timeline", "mentions_timeline", "retweets_of_me"]
     session = create_test_session("sqlite:///:memory:")
     create_test_db(session)
     for name in names:
         with self.subTest(name=name):
             actual = TimelineIndex.find_by_name(name, session)
             self.assertEqual(actual, None)
示例#4
0
 def test_create_ids(self):
     storage = TimelineIndexStorage("sqlite:///:memory:")
     expectation_ids = {"since_id": 100, "max_id": 2000}
     names = ["timeline"]
     tweets = Mock(**expectation_ids)
     storage.create_ids(names[0], tweets)
     timelineindex = TimelineIndex.find_by_name(names[0], storage.session())
     self.assertEqual(timelineindex.since_id, expectation_ids["since_id"])
     self.assertEqual(timelineindex.max_id, expectation_ids["max_id"])
示例#5
0
 def test_find_by_name(self):
     names = ["home_timeline", "mentions_timeline", "retweets_of_me"]
     session = create_test_session("sqlite:///:memory:")
     ids = test_ids(names, 2)  # [(0, 1), (2, 3), (4, 5)]
     create_test_db(session)
     insert_test_db(names, ids, session)
     for name, (since_id, max_id) in zip(names, ids):
         with self.subTest(name=name, since_id=since_id, max_id=max_id):
             actual = TimelineIndex.find_by_name(name, session)
             self.assertEqual(actual.name, name)
             self.assertEqual(actual.since_id, since_id)
             self.assertEqual(actual.max_id, max_id)
示例#6
0
 def test_update_ids(self):
     storage = TimelineIndexStorage("sqlite:///:memory:")
     names = ["timeline"]
     ids = test_ids(names, 2)
     expectation_ids = {"since_id": 100, "max_id": 2000}
     session = storage.session()
     insert_test_db(names, ids, session)
     tweets = Mock(since_id=expectation_ids["since_id"],
                   max_id=expectation_ids["max_id"])
     storage.update_ids(names[0], tweets)
     timelineindex = TimelineIndex.find_by_name(names[0], session)
     self.assertEqual(timelineindex.since_id, expectation_ids["since_id"])
     self.assertEqual(timelineindex.max_id, expectation_ids["max_id"])
示例#7
0
 def test_all(self):
     names = ["home_timeline", "mentions_timeline", "retweets_of_me"]
     session = create_test_session("sqlite:///:memory:")
     ids = test_ids(names, 2)
     create_test_db(session)
     insert_test_db(names, ids, session)
     actuals = TimelineIndex.all(session)
     for name, (since_id, max_id), actual in zip(names, ids,
                                                 actuals):
         with self.subTest(name=name, since_id=since_id, max_id=max_id):
             self.assertEqual(actual.name, name)
             self.assertEqual(actual.since_id, since_id)
             self.assertEqual(actual.max_id, max_id)
示例#8
0
文件: storages.py 项目: A03ki/uecbbs
    def get_ids(self, name):
        """``name`` に対応するレコードを返す

        Parameters
        ----------
        name : str
            名前の文字列

        Returns
        -------
        TimelineIndex
            ``since_id`` と ``max_id`` をフィールドとして持つレコード
        """
        session = self.session()
        return TimelineIndex.find_by_name(name, session)