How to use freezegun - 10 common examples

To help you get started, we’ve selected a few freezegun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mmadil / tweepy / tests / test_tweets.py View on Github external
self.register('foobar', 'foobar@example.com','barfoo', 'barfoo')
        self.login('foobar', 'barfoo')
        db.session.add(
            Tweet(
                'Test tweet',
                test_time,
                1
            )
        )
        db.session.commit()
        tweet = db.session.query(Tweet).first()
        with freeze_time(test_time) as frozen_time:
            self.assertEqual('few seconds ago', Tweet.delta_time(tweet.posted))
        with freeze_time(few_minutes_ahead) as frozen_time:
            self.assertEqual('3m', Tweet.delta_time(tweet.posted))
        with freeze_time(few_hours_ahead) as frozen_time:
            self.assertEqual('2h', Tweet.delta_time(tweet.posted))
        with freeze_time(few_days_ahead) as frozen_time:
            self.assertEqual('07 July, 2016', Tweet.delta_time(tweet.posted))
github tsuru / varnishapi / tests / test_storage.py View on Github external
    @freezegun.freeze_time("2014-02-16 12:00:01")
    def test_retrieve_binds_query(self):
        instance = storage.Instance(name="years")
        bind1 = storage.Bind(app_host="something.where.com", instance=instance)
        self.storage.store_bind(bind1)
        bind2 = storage.Bind(app_host="belong.where.com", instance=instance)
        self.storage.store_bind(bind2)
        self.addCleanup(self.client.feaas_test.binds.remove,
                        {"instance_name": "years"})
        binds = self.storage.retrieve_binds(app_host="belong.where.com")
        binds = [b.to_dict() for b in binds]
        self.assertEqual([bind2.to_dict()], binds)
github vikingco / django-db-locking / locking / tests.py View on Github external
def test_implicit_cleaning_disabled(self):
        """If no max_age parameter is given and locks aren't configured to autoexpire, don't clean them up."""
        assert hasattr(settings, 'LOCK_MAX_AGE') is False
        initial_timestamp = datetime(2017, 1, 1)

        with freeze_time(initial_timestamp):
            lock_to_remain = NonBlockingLock.objects.acquire_lock(self.user)
        with freeze_time(initial_timestamp + timedelta(days=9600)):
            clean_expired_locks()
            assert NonBlockingLock.objects.get() == lock_to_remain
github totalgood / openchat / openspaces / bot_utils / tests.py View on Github external
    @freeze_time("2017-08-05T11:00")
    def setUp(self):
        self.now = datetime.now(timezone.utc)
        self.loc = "B123"
        fake_user = User.objects.create(id_str=12345)
        OpenspacesEvent.objects.create(
                            description="a fake description",
                            start=self.now, 
                            location=self.loc,
                            creator=fake_user
                            )
github tsuru / varnishapi / tests / test_storage.py View on Github external
    @freezegun.freeze_time("2014-02-16 12:00:01")
    def test_retrieve_binds(self):
        instance = storage.Instance(name="years")
        bind1 = storage.Bind(app_host="something.where.com", instance=instance)
        self.storage.store_bind(bind1)
        bind2 = storage.Bind(app_host="belong.where.com", instance=instance)
        self.storage.store_bind(bind2)
        self.addCleanup(self.client.feaas_test.binds.remove,
                        {"instance_name": "years"})
        binds = self.storage.retrieve_binds(instance_name="years")
        binds = [b.to_dict() for b in binds]
        self.assertEqual([bind1.to_dict(), bind2.to_dict()], binds)
github pimutils / todoman / tests / test_cli.py View on Github external
@freeze_time('2017, 3, 20')
def test_list_startable(tmpdir, runner, todo_factory):
    todo_factory(summary='started', start=datetime.datetime(2017, 3, 15))
    todo_factory(summary='nostart')
    todo_factory(summary='unstarted', start=datetime.datetime(2017, 3, 24))

    result = runner.invoke(
        cli,
        ['list', '--startable'],
        catch_exceptions=False,
    )

    assert not result.exception
    assert 'started' in result.output
    assert 'nostart' in result.output
    assert 'unstarted' not in result.output
github spulec / freezegun / tests / test_class_import.py View on Github external
def test_none_as_initial():
    with freeze_time() as ft:
        ft.move_to('2012-01-14')
        assert fake_strftime_function() == '2012'
github pypa / pip / tests / unit / test_unit_outdated.py View on Github external
monkeypatch.setattr(outdated.logger, 'warning',
                        pretend.call_recorder(lambda *a, **kw: None))
    monkeypatch.setattr(outdated.logger, 'debug',
                        pretend.call_recorder(lambda s, exc_info=None: None))
    monkeypatch.setattr(pkg_resources, 'get_distribution',
                        lambda name: MockDistribution(installer))

    fake_state = pretend.stub(
        state={"last_check": stored_time, 'pypi_version': installed_ver},
        save=pretend.call_recorder(lambda v, t: None),
    )
    monkeypatch.setattr(
        outdated, 'SelfCheckState', lambda **kw: fake_state
    )

    with freezegun.freeze_time(
        "1970-01-09 10:00:00",
        ignore=[
            "six.moves",
            "pip._vendor.six.moves",
            "pip._vendor.requests.packages.urllib3.packages.six.moves",
        ]
    ):
        latest_pypi_version = outdated.pip_version_check(None, _options())

    # See we return None if not installed_version
    if not installed_ver:
        assert not latest_pypi_version
    # See that we saved the correct version
    elif check_if_upgrade_required:
        assert fake_state.save.calls == [
            pretend.call(new_ver, datetime.datetime(1970, 1, 9, 10, 00, 00)),
github CTFd / CTFd / tests / api / v1 / user / test_challenges.py View on Github external
def test_api_challenge_solves_user_visibility():
    """Can the user load /api/v1/challenges//solves if challenge_visibility is private/public"""
    app = create_ctfd()
    with app.app_context(), freeze_time("2017-10-5"):
        set_config(
            "start", "1507089600"
        )  # Wednesday, October 4, 2017 12:00:00 AM GMT-04:00 DST
        set_config(
            "end", "1507262400"
        )  # Friday, October 6, 2017 12:00:00 AM GMT-04:00 DST
        gen_challenge(app.db)
        register_user(app)
        client = login_as_user(app)
        r = client.get("/api/v1/challenges/1/solves")
        assert r.status_code == 200
        set_config("challenge_visibility", "public")
        r = client.get("/api/v1/challenges/1/solves")
        assert r.status_code == 200
    destroy_ctfd(app)