コード例 #1
0
ファイル: test_published.py プロジェクト: marrow/mongo
	def test_within_publication_period(self):
		inst = self.Sample(
				published = utcnow() - timedelta(days=1),
				retracted = utcnow() + timedelta(days=1)
			)
		
		assert inst.is_published
コード例 #2
0
    def test_cast_integer(self, Sample):
        v = timedelta(days=7)
        r = (utcnow() + v)
        inst = Sample(7)

        assert isinstance(inst.__data__['field'], datetime)
        assert inst.field == r
コード例 #3
0
ファイル: test_ttl.py プロジェクト: marrow/mongo
	def test_cast_integer(self, Sample):
		v = timedelta(days=7)
		r = (utcnow() + v)
		inst = Sample(7)
		
		assert isinstance(inst.__data__['field'], datetime)
		assert inst.field == r
コード例 #4
0
ファイル: test_objectid.py プロジェクト: bb78657/mongo
	def test_cast_timedelta(self, Sample):
		v = -timedelta(days=7)
		r = (utcnow() + v)
		inst = Sample(v)
		
		assert isinstance(inst.__data__['field'], oid)
		assert inst.field.generation_time == r
コード例 #5
0
ファイル: test_expires.py プロジェクト: marrow/mongo
	def test_deserialize_expired(self):
		now = utcnow()
		inst = self.Sample.from_mongo({'expires': now})
		assert inst is None
		
		inst = self.Sample.from_mongo({'expires': now + timedelta(hours=1)})
		assert isinstance(inst, self.Sample)
		assert not inst.is_expired
コード例 #6
0
ファイル: test_expires.py プロジェクト: bb78657/mongo
    def test_deserialize_expired(self):
        now = utcnow()
        inst = self.Sample.from_mongo({'expires': now})
        assert inst is None

        inst = self.Sample.from_mongo({'expires': now + timedelta(hours=1)})
        assert isinstance(inst, self.Sample)
        assert not inst.is_expired
コード例 #7
0
ファイル: test_lockable.py プロジェクト: marrow/mongo
	def test_acquire_expired(self, sample):
		then = utcnow() - timedelta(days=30)
		sample.update_one(set__lock=sample.Lock(then, 'xyzzy'))
		
		sample.acquire()
		sample.reload('lock')
		
		assert sample.lock.instance == us()
		assert sample.did_expire
コード例 #8
0
ファイル: test_lockable.py プロジェクト: bb78657/mongo
    def test_acquire_expired(self, sample):
        then = utcnow() - timedelta(days=30)
        sample.update_one(set__lock=sample.Lock(then, 'xyzzy'))

        sample.acquire()
        sample.reload('lock')

        assert sample.lock.instance == us()
        assert sample.did_expire
コード例 #9
0
ファイル: test_lockable.py プロジェクト: bb78657/mongo
    def test_release_expired(self, sample):
        then = utcnow() - timedelta(days=30)
        lock = sample.Lock(then)
        sample.update_one(set__lock=lock)

        try:
            sample.release()
        except sample.Locked as e:
            assert e.lock == lock
            assert sample.did_expire
コード例 #10
0
ファイル: test_lockable.py プロジェクト: marrow/mongo
	def test_release_expired(self, sample):
		then = utcnow() - timedelta(days=30)
		lock = sample.Lock(then)
		sample.update_one(set__lock=lock)
		
		try:
			sample.release()
		except sample.Locked as e:
			assert e.lock == lock
			assert sample.did_expire
コード例 #11
0
ファイル: test_published.py プロジェクト: marrow/mongo
	def test_query_exact(self):
		now = utcnow()
		
		query = self.Sample.only_published(now)
		
		assert len(query) == 1
		assert '$and' in query
		assert len(query['$and']) == 2
		assert '$or' in query['$and'][0]
		assert '$or' in query['$and'][1]
		assert query['$and'][1]['$or'][2]['published']['$lte'] == query['$and'][0]['$or'][2]['retracted']['$gt'] == now
コード例 #12
0
ファイル: test_published.py プロジェクト: bb78657/mongo
    def test_query_exact(self):
        now = utcnow()

        query = self.Sample.only_published(now)

        assert len(query) == 1
        assert '$and' in query
        assert len(query['$and']) == 2
        assert '$or' in query['$and'][0]
        assert '$or' in query['$and'][1]
        assert query['$and'][1]['$or'][2]['published']['$lte'] == query[
            '$and'][0]['$or'][2]['retracted']['$gt'] == now
コード例 #13
0
ファイル: test_published.py プロジェクト: marrow/mongo
	def test_query_delta(self):
		when = utcnow() + timedelta(days=1)
		
		query = self.Sample.only_published(timedelta(days=1))
		
		assert len(query) == 1
		assert '$and' in query
		assert len(query['$and']) == 2
		assert '$or' in query['$and'][0]
		assert '$or' in query['$and'][1]
		assert query['$and'][1]['$or'][2]['published']['$lte'] == query['$and'][0]['$or'][2]['retracted']['$gt']
		
		v = query['$and'][1]['$or'][2]['published']['$lte']
		assert abs(when - v) < timedelta(minutes=1)
コード例 #14
0
ファイル: test_published.py プロジェクト: bb78657/mongo
    def test_query_delta(self):
        when = utcnow() + timedelta(days=1)

        query = self.Sample.only_published(timedelta(days=1))

        assert len(query) == 1
        assert '$and' in query
        assert len(query['$and']) == 2
        assert '$or' in query['$and'][0]
        assert '$or' in query['$and'][1]
        assert query['$and'][1]['$or'][2]['published']['$lte'] == query[
            '$and'][0]['$or'][2]['retracted']['$gt']

        v = query['$and'][1]['$or'][2]['published']['$lte']
        assert abs(when - v) < timedelta(minutes=1)
コード例 #15
0
ファイル: test_lockable.py プロジェクト: bb78657/mongo
 def test_failures_now(self):
     now = utcnow()
     inst = self.Sample.Lock(now)
     assert inst.failures == 0
コード例 #16
0
ファイル: test_util.py プロジェクト: marrow/mongo
def test_utcnow():
	now = utcnow()
	assert now.tzinfo
コード例 #17
0
ファイル: test_lockable.py プロジェクト: bb78657/mongo
 def test_expires(self):
     now = utcnow()
     inst = self.Sample.Lock(now)
     assert inst.expires == now + inst.__period__
コード例 #18
0
ファイル: test_published.py プロジェクト: bb78657/mongo
    def test_past_retraction(self):
        inst = self.Sample(retracted=utcnow() - timedelta(days=1))

        assert not inst.is_published
コード例 #19
0
ファイル: test_lockable.py プロジェクト: marrow/mongo
	def test_failures_now(self):
		now = utcnow()
		inst = self.Sample.Lock(now)
		assert inst.failures == 0
コード例 #20
0
ファイル: test_ttl.py プロジェクト: marrow/mongo
	def test_cast_datetime(self, Sample):
		v = utcnow()
		inst = Sample(v)
		
		assert isinstance(inst.__data__['field'], datetime)
		assert inst.field is v
コード例 #21
0
ファイル: test_published.py プロジェクト: bb78657/mongo
    def test_creation_modification_init(self):
        now = utcnow()
        inst = self.Sample()

        assert abs(inst.created - now) < timedelta(seconds=1)
        assert inst.modified is None
コード例 #22
0
ファイル: test_expires.py プロジェクト: bb78657/mongo
 def test_timedelta_assignment(self):
     now = utcnow()
     inst = self.Sample(expires=timedelta(days=1))
     assert timedelta(hours=23) < (inst.expires - now) < timedelta(hours=25)
コード例 #23
0
ファイル: test_expires.py プロジェクト: bb78657/mongo
 def test_explicit_date(self):
     then = utcnow() - timedelta(days=1)
     inst = self.Sample(expires=then)
     assert inst.expires == then
     assert inst.is_expired
コード例 #24
0
ファイル: test_expires.py プロジェクト: marrow/mongo
	def test_explicit_date(self):
		then = utcnow() - timedelta(days=1)
		inst = self.Sample(expires=then)
		assert inst.expires == then
		assert inst.is_expired
コード例 #25
0
ファイル: test_published.py プロジェクト: marrow/mongo
	def test_future_public(self):
		inst = self.Sample(published=utcnow() + timedelta(days=1))
		
		assert not inst.is_published
コード例 #26
0
ファイル: test_objectid.py プロジェクト: bb78657/mongo
	def test_cast_datetime(self, Sample):
		v = utcnow()
		inst = Sample(v)
		
		assert isinstance(inst.__data__['field'], oid)
		assert inst.field.generation_time == v
コード例 #27
0
ファイル: test_lockable.py プロジェクト: marrow/mongo
	def test_failures_chain(self):
		then = utcnow() - timedelta(days=30)
		inst = self.Sample.Lock(then, timeouts=41)
		
		assert inst.failures == 42
コード例 #28
0
ファイル: test_lockable.py プロジェクト: marrow/mongo
	def test_failures_then(self):
		then = utcnow() - timedelta(days=30)
		inst = self.Sample.Lock(then)
		
		assert inst.failures == 1
コード例 #29
0
ファイル: test_lockable.py プロジェクト: bb78657/mongo
    def test_failures_then(self):
        then = utcnow() - timedelta(days=30)
        inst = self.Sample.Lock(then)

        assert inst.failures == 1
コード例 #30
0
ファイル: test_expires.py プロジェクト: marrow/mongo
	def test_timedelta_assignment(self):
		now = utcnow()
		inst = self.Sample(expires=timedelta(days=1))
		assert timedelta(hours=23) < (inst.expires - now) < timedelta(hours=25)
コード例 #31
0
ファイル: test_lockable.py プロジェクト: bb78657/mongo
    def test_failures_chain(self):
        then = utcnow() - timedelta(days=30)
        inst = self.Sample.Lock(then, timeouts=41)

        assert inst.failures == 42
コード例 #32
0
    def test_cast_datetime(self, Sample):
        v = utcnow()
        inst = Sample(v)

        assert isinstance(inst.__data__['field'], datetime)
        assert inst.field is v
コード例 #33
0
ファイル: test_published.py プロジェクト: marrow/mongo
	def test_past_retraction(self):
		inst = self.Sample(retracted=utcnow() - timedelta(days=1))
		
		assert not inst.is_published
コード例 #34
0
ファイル: test_expires.py プロジェクト: marrow/mongo
	def test_integer_assignment(self):
		now = utcnow()
		inst = self.Sample(expires=0)
		assert inst.expires - now < timedelta(seconds=1)
		assert inst.is_expired
コード例 #35
0
ファイル: test_published.py プロジェクト: bb78657/mongo
    def test_future_public(self):
        inst = self.Sample(published=utcnow() + timedelta(days=1))

        assert not inst.is_published
コード例 #36
0
def test_utcnow():
    now = utcnow()
    assert now.tzinfo
コード例 #37
0
ファイル: test_published.py プロジェクト: bb78657/mongo
    def test_within_publication_period(self):
        inst = self.Sample(published=utcnow() - timedelta(days=1),
                           retracted=utcnow() + timedelta(days=1))

        assert inst.is_published
コード例 #38
0
ファイル: test_lockable.py プロジェクト: marrow/mongo
	def test_expires(self):
		now = utcnow()
		inst = self.Sample.Lock(now)
		assert inst.expires == now + inst.__period__
コード例 #39
0
ファイル: test_expires.py プロジェクト: bb78657/mongo
 def test_integer_assignment(self):
     now = utcnow()
     inst = self.Sample(expires=0)
     assert inst.expires - now < timedelta(seconds=1)
     assert inst.is_expired
コード例 #40
0
ファイル: test_published.py プロジェクト: marrow/mongo
	def test_creation_modification_init(self):
		now = utcnow()
		inst = self.Sample()
		
		assert abs(inst.created - now) < timedelta(seconds=1)
		assert inst.modified is None