本文整理汇总了Python中tests.support.test_helpers.d_tz函数的典型用法代码示例。如果您正苦于以下问题:Python d_tz函数的具体用法?Python d_tz怎么用?Python d_tz使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了d_tz函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_month_and_group_query_with_start_and_end_at
def test_month_and_group_query_with_start_and_end_at(self):
self.mock_storage.execute_query.return_value = [
{'some_group': 'val1', '_month_start_at': d(2013, 1, 1), '_count': 1},
{'some_group': 'val1', '_month_start_at': d(2013, 2, 1), '_count': 5},
{'some_group': 'val2', '_month_start_at': d(2013, 3, 1), '_count': 2},
{'some_group': 'val2', '_month_start_at': d(2013, 4, 1), '_count': 6},
{'some_group': 'val2', '_month_start_at': d(2013, 7, 1), '_count': 6},
]
data = self.data_set.execute_query(
Query.create(period=MONTH,
group_by=['some_group'],
start_at=d(2013, 1, 1),
end_at=d(2013, 4, 2)))
assert_that(data,
has_item(has_entries({"values": has_length(4)})))
assert_that(data,
has_item(has_entries({"values": has_length(4)})))
first_group = data[0]["values"]
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 3, 1)})))
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 4, 1)})))
first_group = data[1]["values"]
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 1, 1)})))
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 2, 1)})))
示例2: test_basic_query_with_time_limits
def test_basic_query_with_time_limits(self):
self._save_all('foo_bar',
{'_timestamp': d_tz(2012, 12, 12)},
{'_timestamp': d_tz(2012, 12, 14)},
{'_timestamp': d_tz(2012, 12, 11)})
# start at
results = self.engine.execute_query('foo_bar', Query.create(
start_at=d_tz(2012, 12, 12, 13)))
assert_that(results,
contains(
has_entry('_timestamp', d_tz(2012, 12, 14))))
# end at
results = self.engine.execute_query('foo_bar', Query.create(
end_at=d_tz(2012, 12, 11, 13)))
assert_that(results,
contains(
has_entry('_timestamp', d_tz(2012, 12, 11))))
# both
results = self.engine.execute_query('foo_bar', Query.create(
start_at=d_tz(2012, 12, 11, 12),
end_at=d_tz(2012, 12, 12, 12)))
assert_that(results,
contains(
has_entry('_timestamp', d_tz(2012, 12, 12))))
示例3: test_period_group_query_adds_missing_periods_in_correct_order
def test_period_group_query_adds_missing_periods_in_correct_order(self):
self.mock_storage.execute_query.return_value = [
{'some_group': 'val1', '_week_start_at': d(2013, 1, 14), '_count': 23},
{'some_group': 'val1', '_week_start_at': d(2013, 1, 21), '_count': 41},
{'some_group': 'val2', '_week_start_at': d(2013, 1, 14), '_count': 31},
{'some_group': 'val2', '_week_start_at': d(2013, 1, 28), '_count': 12},
]
data = self.data_set.execute_query(
Query.create(period=WEEK, group_by=['some_group'],
start_at=d_tz(2013, 1, 7, 0, 0, 0),
end_at=d_tz(2013, 2, 4, 0, 0, 0)))
assert_that(data, has_item(has_entries({
"some_group": "val1",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 23}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 41}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 0}),
),
})))
assert_that(data, has_item(has_entries({
"some_group": "val2",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 31}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 12}),
),
})))
示例4: test_month_and_group_query_with_start_and_end_at
def test_month_and_group_query_with_start_and_end_at(self):
self.mock_repository.multi_group.return_value = [
{
"some_group": "val1",
"_count": 6,
"_group_count": 2,
"_subgroup": [
{
"_month_start_at": d(2013, 1, 1, 0, 0, 0),
"_count": 1
},
{
"_month_start_at": d(2013, 2, 1, 0, 0, 0),
"_count": 5
}
]
},
{
"some_group": "val2",
"_count": 8,
"_group_count": 2,
"_subgroup": [
{
"_month_start_at": d(2013, 3, 1, 0, 0, 0),
"_count": 2
},
{
"_month_start_at": d(2013, 4, 1, 0, 0, 0),
"_count": 6
},
{
"_month_start_at": d(2013, 7, 1, 0, 0, 0),
"_count": 6
}
]
}
]
query_result = self.bucket.query(Query.create(period=MONTH,
group_by="some_group",
start_at=d(2013, 1, 1),
end_at=d(2013, 4, 2)))
data = query_result.data()
assert_that(data,
has_item(has_entries({"values": has_length(4)})))
assert_that(data,
has_item(has_entries({"values": has_length(4)})))
first_group = data[0]["values"]
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 3, 1)})))
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 4, 1)})))
first_group = data[1]["values"]
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 1, 1)})))
assert_that(first_group, has_item(has_entries({
"_start_at": d_tz(2013, 2, 1)})))
示例5: test_period_group_query_adds_missing_periods_in_correct_order
def test_period_group_query_adds_missing_periods_in_correct_order(self):
self.mock_repository.multi_group.return_value = [
{
"some_group": "val1",
"_count": 6,
"_group_count": 2,
"_subgroup": [
{
"_week_start_at": d(2013, 1, 14, 0, 0, 0),
"_count": 23
},
{
"_week_start_at": d(2013, 1, 21, 0, 0, 0),
"_count": 41
}
]
},
{
"some_group": "val2",
"_count": 8,
"_group_count": 2,
"_subgroup": [
{
"_week_start_at": d(2013, 1, 14, 0, 0, 0),
"_count": 31
},
{
"_week_start_at": d(2013, 1, 28, 0, 0, 0),
"_count": 12
}
]
}
]
query_result = self.bucket.query(
Query.create(period="week", group_by="some_group",
start_at=d_tz(2013, 1, 7, 0, 0, 0),
end_at=d_tz(2013, 2, 4, 0, 0, 0))).data()
assert_that(query_result, has_item(has_entries({
"some_group": "val1",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 23}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 41}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 0}),
),
})))
assert_that(query_result, has_item(has_entries({
"some_group": "val2",
"values": contains(
has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 31}),
has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 0}),
has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 12}),
),
})))
示例6: test_period_queries_get_sorted_by__week_start_at
def test_period_queries_get_sorted_by__week_start_at(self):
self.setup__timestamp_data()
query = Query.create(period="week")
result = query.execute(self.bucket.repository)
assert_that(result.data(), contains(
has_entry('_start_at', d_tz(2012, 12, 31)),
has_entry('_start_at', d_tz(2013, 1, 28)),
has_entry('_start_at', d_tz(2013, 2, 25))
))
示例7: test_save_document_adding_timestamps
def test_save_document_adding_timestamps(self, now):
now.return_value = d_tz(2013, 4, 9, 13, 32, 5)
self.repo.save({"name": "Gummo"})
self.mongo.save.assert_called_once_with({
"name": "Gummo",
"_updated_at": d_tz(2013, 4, 9, 13, 32, 5)
})
示例8: test_period_queries_get_sorted_by__week_start_at
def test_period_queries_get_sorted_by__week_start_at(self):
self.setup__timestamp_data()
query = Query.create(period=WEEK)
result = self.data_set.execute_query(query)
assert_that(result, contains(
has_entry('_start_at', d_tz(2012, 12, 31)),
has_entry('_start_at', d_tz(2013, 1, 28)),
has_entry('_start_at', d_tz(2013, 2, 25))
))
示例9: test_build_query_with_start_and_end_at
def test_build_query_with_start_and_end_at(self):
query = Query.create(
start_at = d_tz(2012, 3, 17, 17, 10, 6),
end_at = d_tz(2012, 3, 19, 17, 10, 6))
assert_that(query.to_mongo_query(), is_({
"_timestamp": {
"$gte": d_tz(2012, 3, 17, 17, 10, 6),
"$lt": d_tz(2012, 3, 19, 17, 10, 6)
}
}))
示例10: test_period_query_is_executed
def test_period_query_is_executed(self, mock_query):
mock_query.return_value = NoneData()
self.app.get(
'/data/some-group/some-type?period=week&' +
'start_at=' + urllib.quote("2012-11-05T00:00:00Z") + '&' +
'end_at=' + urllib.quote("2012-12-03T00:00:00Z"))
mock_query.assert_called_with(
Query.create(period=WEEK,
start_at=d_tz(2012, 11, 5),
end_at=d_tz(2012, 12, 3)))
示例11: test_basic_query_with_inclusive_time_limits
def test_basic_query_with_inclusive_time_limits(self):
self._save_all('foo_bar',
{'_timestamp': d_tz(2014, 12, 01)},
{'_timestamp': d_tz(2014, 12, 02)},
{'_timestamp': d_tz(2014, 12, 03)})
# start at
results = self.engine.execute_query('foo_bar', Query.create(
start_at=d_tz(2014, 12, 01),
end_at=d_tz(2014, 12, 03),
inclusive=True))
assert_that(len(results), is_(3))
示例12: test_adding_mongo_document_to_collection_expands_week_start_at
def test_adding_mongo_document_to_collection_expands_week_start_at(self):
stub_doc = {
"_week_start_at": d(2013, 5, 6),
"_count": 42
}
period_data = PeriodData([stub_doc], period="week")
assert_that(len(period_data.data()), is_(1))
assert_that(period_data.data()[0], has_entry("_count", 42))
assert_that(period_data.data()[0], has_entry("_start_at",
d_tz(2013, 5, 6)))
assert_that(period_data.data()[0], has_entry("_end_at",
d_tz(2013, 5, 13)))
示例13: test_week_start_at_gets_expanded_in_subgroups_when_added
def test_week_start_at_gets_expanded_in_subgroups_when_added(self):
stub_document = {
"_subgroup": [
{
"_week_start_at": d(2013, 4, 1),
"_count": 5
}
]
}
data = PeriodGroupedData([stub_document], WEEK)
values = data.data()[0]['values']
assert_that(values, has_item(has_entry("_start_at", d_tz(2013, 4, 1))))
assert_that(values, has_item(has_entry("_end_at", d_tz(2013, 4, 8))))
assert_that(values, has_item(has_entry("_count", 5)))
示例14: test_adding_mongo_doc_to_collection_expands_month_start_at
def test_adding_mongo_doc_to_collection_expands_month_start_at(self):
stub_doc = {
"_month_start_at": d(2013, 4, 1),
"_count": 5
}
period_data = PeriodData([stub_doc], period="month")
assert_that(len(period_data.data()), is_(1))
assert_that(period_data.data()[0], has_entry("_count", 5))
assert_that(period_data.data()[0], has_entry("_start_at",
d_tz(2013, 4, 1)))
assert_that(period_data.data()[0], has_entry("_end_at",
d_tz(2013, 5, 1)))
示例15: test_batch_last_updated
def test_batch_last_updated(self):
records = {
# timestamps in ascending order
'some_data': [
{'_timestamp': d_tz(2018, 1, 1)},
{'_timestamp': d_tz(2019, 1, 1)},
{'_timestamp': d_tz(2020, 1, 1)},
],
# timestamps in descending order
'some_other_data': [
{'_timestamp': d_tz(2017, 1, 1)},
{'_timestamp': d_tz(2016, 1, 1)},
{'_timestamp': d_tz(2015, 1, 1)},
]
}
for key, items in records.iteritems():
self.engine.create_data_set(key, 0)
for item in items:
self.engine.save_record(key, item)
some_data_set = DataSet(self.engine, {'name': 'some_data'})
some_other_data_set = DataSet(self.engine, {'name': 'some_other_data'})
yet_another_data_set = DataSet(self.engine, {'name': 'yet_another_data'})
self.engine.batch_last_updated([some_data_set, some_other_data_set, yet_another_data_set])
some_data_set_last_updated = some_data_set.get_last_updated()
some_other_data_set_last_updated = some_other_data_set.get_last_updated()
yet_another_data_set_last_updated = yet_another_data_set.get_last_updated()
assert_that(some_data_set_last_updated, is_(d_tz(2020, 1, 1, 0, 0, 0)))
assert_that(some_other_data_set_last_updated, is_(d_tz(2017, 1, 1, 0, 0, 0)))
assert_that(yet_another_data_set_last_updated, is_(none()))