コード例 #1
0
    def test_default_start_time(self):
        monitor = BibliothecaEventMonitor(
            self._db, self.collection, api_class=MockBibliothecaAPI
        )
        expected = datetime.datetime.utcnow() - monitor.DEFAULT_START_TIME

        # Returns a date long in the past if the monitor has never
        # been run before.
        default_start_time = monitor.create_default_start_time(self._db, [])
        assert abs((expected-default_start_time).total_seconds()) <= 1

        # After Bibliotheca has been initialized, it returns None if no
        # arguments are passed
        Timestamp.stamp(self._db, monitor.service_name, self.collection)
        eq_(None, monitor.create_default_start_time(self._db, []))

        # Returns a date several years ago if args are formatted
        # improperly or the monitor has never been run before
        not_date_args = ['initialize']
        too_many_args = ['2013', '04', '02']
        for args in [not_date_args, too_many_args]:
            actual_default_start_time = monitor.create_default_start_time(self._db, args)
            eq_(True, isinstance(actual_default_start_time, datetime.datetime))
            assert (default_start_time - actual_default_start_time).total_seconds() <= 1

        # Returns an appropriate date if command line arguments are passed
        # as expected
        proper_args = ['2013-04-02']
        default_start_time = monitor.create_default_start_time(self._db, proper_args)
        eq_(datetime.datetime(2013, 4, 2), default_start_time)
コード例 #2
0
    def test_default_start_time(self):
        monitor = BibliothecaEventMonitor(self._db,
                                          self.collection,
                                          api_class=MockBibliothecaAPI)
        expected = datetime.datetime.utcnow() - monitor.DEFAULT_START_TIME

        # When the monitor has never been run before, the default
        # start time is a date long in the past.
        assert abs(
            (expected - monitor.default_start_time).total_seconds()) <= 1
        default_start_time = monitor.create_default_start_time(self._db, [])
        assert abs((expected - default_start_time).total_seconds()) <= 1

        # It's possible to override this by instantiating
        # BibliothecaEventMonitor with a specific date.
        monitor = BibliothecaEventMonitor(self._db,
                                          self.collection,
                                          api_class=MockBibliothecaAPI,
                                          cli_date="2011-01-01")
        expected = datetime.datetime(year=2011, month=1, day=1)
        eq_(expected, monitor.default_start_time)
        for cli_date in ('2011-01-01', ['2011-01-01']):
            default_start_time = monitor.create_default_start_time(
                self._db, cli_date)
            eq_(expected, default_start_time)

        # After Bibliotheca has been initialized,
        # create_default_start_time returns None, rather than a date
        # far in the bast, if no cli_date is passed in.
        Timestamp.stamp(self._db, monitor.service_name, self.collection)
        eq_(None, monitor.create_default_start_time(self._db, []))

        # Returns a date several years ago if args are formatted
        # improperly or the monitor has never been run before
        not_date_args = ['initialize']
        too_many_args = ['2013', '04', '02']
        for args in [not_date_args, too_many_args]:
            actual_default_start_time = monitor.create_default_start_time(
                self._db, args)
            eq_(True, isinstance(actual_default_start_time, datetime.datetime))
            assert (default_start_time -
                    actual_default_start_time).total_seconds() <= 1

        # Returns an appropriate date if command line arguments are passed
        # as expected
        proper_args = ['2013-04-02']
        default_start_time = monitor.create_default_start_time(
            self._db, proper_args)
        eq_(datetime.datetime(2013, 4, 2), default_start_time)