本文整理汇总了Python中common.utilities.inversion_of_control.Dependency.find方法的典型用法代码示例。如果您正苦于以下问题:Python Dependency.find方法的具体用法?Python Dependency.find怎么用?Python Dependency.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.utilities.inversion_of_control.Dependency
的用法示例。
在下文中一共展示了Dependency.find方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCustomAnalyticsRunner
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find [as 别名]
#.........这里部分代码省略.........
# define an exception method
exception = Exception("yo mama")
def raise_exception():
raise exception
# begin stubbing things out
self.mox.StubOutWithMock(runner, "_update_ca_run")
self.mox.StubOutWithMock(runner, "_query_entity")
self.mox.StubOutWithMock(logging_helper, "log_exception")
self.mox.StubOutWithMock(runner, "_send_error_email")
# begin recording
runner._update_ca_run()
runner._query_entity().WithSideEffects(raise_exception)
logging_helper.log_exception(self.mock_logger, "Error running CustomAnalyticsRunner", exception, IgnoreArg())
runner._update_ca_run("error", error_string = "yo mama", error_stack_trace = IsA(basestring))
runner._send_error_email("yo mama", IsA(basestring), self.custom_analytics_run_id)
# replay all
self.mox.ReplayAll()
# run
with self.assertRaises(Exception):
runner.run()
def test_query_entity(self):
# create mocks
query = { "_id": self.custom_analytics_run_id }
projection = { "client_id": 1, "companies": 1, "demographic_template": 1, "trade_areas": 1, "report_name": 1, "user_id": 1, "run_comp_stores_report": 1, "comp_stores_periods": 1 }
# begin recording
self.mock_retail_access.find("custom_analytics_run", query, projection).AndReturn(["woot"])
# replay all
self.mox.ReplayAll()
# go
self.assertEqual(CustomAnalyticsRunner(self.task_rec)._query_entity(), "woot")
def test_get_client_detail(self):
# create mock ca_run
mock_ca_run = {
"user_id": "51ed900cf3d31bcca5653367",
"client_id": "51ed900cf3d31bcca5653366"
}
# create mock queries
user_query = { "_id": ObjectId("51ed900cf3d31bcca5653367") }
user_projection = { "email": 1 }
client_query = { "_id": ObjectId("51ed900cf3d31bcca5653366") }
client_projection = { "name": 1 }
# create mock documents
mock_user = { "email": "chilly" }
mock_client = { "name": "willy" }
# begin recording
self.mock_retail_access.find("user", user_query, user_projection).AndReturn([mock_user])
self.mock_retail_access.find("client", client_query, client_projection).AndReturn([mock_client])
# replay all
self.mox.ReplayAll()
示例2: GP22TestCollection
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find [as 别名]
class GP22TestCollection(ServiceTestCollection):
def initialize(self):
self.user_id = '[email protected]'
self.source = "gp_16_test_collection.py"
self.context = {"user_id": self.user_id, "source": self.source}
def setUp(self):
# clear dbs
self.mds_access.call_delete_reset_database()
# reset the postgres data
purge_weather_tables()
# get mds access
self.mds_direct_access = Dependency("MDSMongoAccess").value
# in the face
self.test_case.maxDiff = None
def tearDown(self):
# reset the postgres data
purge_weather_tables()
# -------------------------------------- Begin Testing!! -------------------------------------- #
def test_simple_gp_22_run(self):
# insert a source file
source_file_id = insert_test_source_file("bob sagget")
# create three stations (close to each other)
station_1_id = insert_test_weather_station("code1", 40, -80, "station1")
# insert the mongo weather station
insert_test_weather_station_mongo("code1", "station1", station_1_id, 40, -80)
# insert weather vars for precipitation and tmin/tmax
t_min_var_id = insert_test_weather_var("TMIN")
t_max_var_id = insert_test_weather_var("TMAX")
precip_var_id = insert_test_weather_var("PRCP")
# create weather data
insert_test_point_data(t_min_var_id, station_1_id, "2013-11-07", 0, source_file_id)
insert_test_point_data(t_max_var_id, station_1_id, "2013-11-07", 20, source_file_id)
insert_test_point_data(precip_var_id, station_1_id, "2013-11-07", 30, source_file_id)
insert_test_point_data(t_min_var_id, station_1_id, "2013-11-08", 40, source_file_id)
insert_test_point_data(t_max_var_id, station_1_id, "2013-11-08", 60, source_file_id)
insert_test_point_data(precip_var_id, station_1_id, "2013-11-08", 70, source_file_id)
# run gp 22 on this station for weather and precip
gp = GP22GetWeatherStationData()
gp.process_object({ "weather_code": "code1#[email protected]" }, entity_type = "weather")
# query the store weathers and remove the distance, since it's tough to verify
weather_records = self._query_weather_records_and_remove_ids()
# verify structure of store weather
self.test_case.assertEqual(weather_records, [
self._create_weather_structure(datetime.datetime(2013, 11, 7), 0, 2, 1, 32, 35.6, 33.8, "code1", 3, .11811, "code1"),
self._create_weather_structure(datetime.datetime(2013, 11, 8), 4, 6, 5, 39.2, 42.8, 41, "code1", 7, .27559, "code1")
])
# -------------------------------------- Internal -------------------------------------- #
def _create_weather_structure(self, date, temp_c_min, temp_c_max, temp_c_mean, temp_f_min, temp_f_max, temp_f_mean,
station_code, precip_mm, precip_in, precip_station_code):
return {
"d": date,
"tcmin": temp_c_min,
"tcmax": temp_c_max,
"tcmean": temp_c_mean,
"tfmin": temp_f_min,
"tfmax": temp_f_max,
"tfmean": temp_f_mean,
"pmm": precip_mm,
"pin": precip_in,
"code": "%s#[email protected]%s" % (precip_station_code, station_code)
}
def _query_weather_records_and_remove_ids(self):
# query the weather data
records = list(self.mds_direct_access.find("weather"))
# remove ids
for record in records:
del record["_id"]
return records
示例3: GP22Tests
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find [as 别名]
#.........这里部分代码省略.........
self.gp._save_processed_data()
def test_save_processed_data__no_new_data(self):
# mock some gp properties
self.gp.new_weather_data = []
self.gp._weather_code = "MDog"
self.gp.weather_ids_to_delete = []
# begin stubbing
self.mox.StubOutWithMock(weather_helper, "upsert_new_weather_data")
self.mox.StubOutWithMock(weather_helper, "delete_existing_weather_records")
# replay all
self.mox.ReplayAll()
# I love gooooooold
self.gp._save_processed_data()
def test_save_processed_data__data_to_delete(self):
# mock some gp properties
self.gp.new_weather_data = []
self.gp._weather_code = "MDog"
self.gp.weather_ids_to_delete = [1, 2, 3]
# begin stubbing
self.mox.StubOutWithMock(weather_helper, "upsert_new_weather_data")
self.mox.StubOutWithMock(weather_helper, "delete_existing_weather_records")
# record away
weather_helper.delete_existing_weather_records([1, 2, 3])
# replay all
self.mox.ReplayAll()
# I love gooooooold
self.gp._save_processed_data()
def test_get_station_psql_ids(self):
# define mocks/expected data
mock_query = { "data.code": { "$in": ["chicken", "woot"]}}
mock_projection = { "data.code": 1, "data.psql_id": 1 }
mock_stations = [
{
"data": {
"code": "chicken",
"psql_id": 1
}
},
{
"data": {
"code": "woot",
"psql_id": 2
}
}
]
# set mock gp properties
self.gp._temp_station_code, self.gp._precip_station_code = "chicken", "woot"
# begin recording
self.mock_mds_access.find("weather_station", mock_query, mock_projection).AndReturn(mock_stations)
# replay all
self.mox.ReplayAll()
# go!
self.assertEqual(self.gp._get_station_psql_ids(), (1, 2))
def test_get_station_psql_ids__one_empty(self):
# define mocks/expected data
mock_query = { "data.code": { "$in": ["chicken"]}}
mock_projection = { "data.code": 1, "data.psql_id": 1 }
mock_stations = [
{
"data": {
"code": "chicken",
"psql_id": 1
}
}
]
# set mock gp properties
self.gp._temp_station_code, self.gp._precip_station_code = "chicken", ""
# begin recording
self.mock_mds_access.find("weather_station", mock_query, mock_projection).AndReturn(mock_stations)
# replay all
self.mox.ReplayAll()
# go!
self.assertEqual(self.gp._get_station_psql_ids(), (1, -1))
示例4: TestCustomAnalyticsScheduler
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find [as 别名]
#.........这里部分代码省略.........
self.mox.StubOutWithMock(self.scheduler, "_get_in_progress")
self.mox.StubOutWithMock(logging_helper, "log_exception")
self.mox.StubOutWithMock(self.scheduler, "_send_error_email")
# begin recording
self.scheduler._get_in_progress().WithSideEffects(raise_exception)
logging_helper.log_exception(self.mock_logger, "Error running CustomAnalyticsScheduler", exception, IgnoreArg())
self.scheduler._send_error_email("yo mama", IsA(basestring))
# replay all
self.mox.ReplayAll()
# respect!
with self.assertRaises(Exception):
self.scheduler.run()
def test_get_in_progress(self):
# create mock values
mock_date_now = datetime.datetime(2014, 3, 17, 18, 30)
# create expected values
mock_date_expected = datetime.datetime(2014, 3, 17, 18, 20)
expected_in_progress_query = { "internal_status": "in_progress", "heart_beat": { "$gt": mock_date_expected }}
expected_in_progress_but_stuck_query = { "internal_status": "in_progress", "heart_beat": { "$lte": mock_date_expected }}
expected_projection = { "_id": 1 }
# begin stubbing things
self.mox.StubOutWithMock(self.scheduler, "_get_utc_now")
# begin recording
self.scheduler._get_utc_now().AndReturn(mock_date_now)
self.mock_retail_access.find("custom_analytics_run", expected_in_progress_query, expected_projection).AndReturn([{ "_id": "chicken" }])
self.mock_retail_access.find("custom_analytics_run", expected_in_progress_but_stuck_query, expected_projection).AndReturn([{ "_id": "woot" }])
# replay all
self.mox.ReplayAll()
# go!
self.assertEqual(self.scheduler._get_in_progress(), (["chicken"], ["woot"]))
def test_get_next_ca_run_ids(self):
# define some mocks
mock_cursor = self.mox.CreateMockAnything()
mock_results = [
{ "_id": "chicken" },
{ "_id": "woot" }
]
# begin recording
self.mock_retail_access.find("custom_analytics_run", { "status": "queued" }, { "_id": 1 }).AndReturn(mock_cursor)
mock_cursor.sort([["created_at", 1]]).AndReturn(mock_cursor)
mock_cursor.limit(2).AndReturn(mock_results)
# replay all
self.mox.ReplayAll()
# respect!
self.assertEqual(self.scheduler._get_next_ca_run_ids(2), ["chicken", "woot"])
def test_update_statuses(self):
示例5: GP16TestCollection
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find [as 别名]
#.........这里部分代码省略.........
trade_area_id = insert_test_trade_area(store_id, company_id = "company_id_1", city = "city_1", state = "state_1", company_name = "company_name_1", latitude = 40, longitude = -80)
# query the trade area document, and run GP16 on it
trade_area_document = select_trade_area(trade_area_id)
# run gp 16 on on two days worth
GP16GetStoreWeather().process_object(trade_area_document)
# query the store weathers and remove the distance, since it's tough to verify
weather_records = self._query_weather_records_and_remove_ids()
# verify structure of store weather
self.test_case.assertEqual(weather_records, [
self._create_weather_structure(datetime.datetime(2013, 11, 7), 0, 2, 1, 32, 35.6, 33.8, "code_1", 3, .11811, "code_1"),
self._create_weather_structure(datetime.datetime(2013, 11, 8), 4, 6, 5, 39.2, 42.8, 41, "code_1", 7, .27559, "code_1")
])
# query the store
store = select_test_store(store_id)
# verify that it's matched to this station
self.test_case.assertEqual(store["data"]["weather_code"], "code_1#[email protected]_1")
def test_mixed_weather_stations(self):
# insert a source file
source_file_id = insert_test_source_file("bob sagget")
# create several stations (close to each other)
station_1_id = insert_test_weather_station("code_1", 40, -80, "station_name_1")
station_2_id = insert_test_weather_station("code_2", 40.01, -80.01, "station_name_2")
# insert weather vars for precipitation and tmin/tmax
t_min_var_id = insert_test_weather_var("TMIN")
t_max_var_id = insert_test_weather_var("TMAX")
precip_var_id = insert_test_weather_var("PRCP")
# create data for each station
# station 1, no precip
# station 2, no temp
insert_test_point_data(t_min_var_id, station_1_id, "2013-11-07", 0, source_file_id)
insert_test_point_data(t_max_var_id, station_1_id, "2013-11-07", 20, source_file_id)
insert_test_point_data(precip_var_id, station_2_id, "2013-11-07", 30, source_file_id)
# trade area 1, close to station 1 and 2
# trade area 2, close to station 3
# trade area 3, close to station 4
store_id = insert_test_store("company_id_1", None)
trade_area_id_1 = insert_test_trade_area(store_id, company_id = "company_id_1", city = "city_1", state = "state_1", company_name = "company_name_1", latitude = 40, longitude = -80)
# run gp 16 on one day for all three trade areas
GP16GetStoreWeather().process_object(select_trade_area(trade_area_id_1))
# query the store weathers and remove the distance, since it's tough to verify
weather_records = self._query_weather_records_and_remove_ids()
# verify structure of store weather
self.test_case.assertEqual(weather_records, [
self._create_weather_structure(datetime.datetime(2013, 11, 7), 0, 2, 1, 32, 35.6, 33.8, "code_1", 3, .11811, "code_2")
])
# query the store
store = select_test_store(store_id)
# verify that it's matched to this station
self.test_case.assertEqual(store["data"]["weather_code"], "code_2#[email protected]_1")
# ------------------------------------------ Helpers -----------------------------------------
def _create_weather_structure(self, date, temp_c_min, temp_c_max, temp_c_mean, temp_f_min, temp_f_max, temp_f_mean,
station_code, precip_mm, precip_in, precip_station_code):
return {
"d": parse_date(date),
"tcmin": temp_c_min,
"tcmax": temp_c_max,
"tcmean": temp_c_mean,
"tfmin": temp_f_min,
"tfmax": temp_f_max,
"tfmean": temp_f_mean,
"pmm": precip_mm,
"pin": precip_in,
"code": "%s#[email protected]%s" % (precip_station_code, station_code)
}
def _query_weather_records_and_remove_ids(self):
# query the weather data
records = list(self.mds_direct_access.find("weather"))
# remove ids
for record in records:
del record["_id"]
return records
示例6: WeatherHelperTests
# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import find [as 别名]
#.........这里部分代码省略.........
# date date1/2 exist, but date 1 is different
mock_existing_data = [
{
"_id": 1,
"d": "date_1",
"pmm": 5,
"tcmax": 5.5,
"tcmin": 5.55
},
{
"_id": 2,
"d": "date_2",
"pmm": 2,
"tcmax": 2.2,
"tcmin": 2.22
},
{
"_id": 4,
"d": "date_4",
"pmm": 4,
"tcmax": 4.4,
"tcmin": 4.44
},
{
"_id": 5,
"d": "date_5",
"pmm": 5,
"tcmax": 5.5,
"tcmin": 5.55
}
]
# begin stubbing
self.mox.StubOutWithMock(weather_helper, "_find_existing_weather_records")
# begin recording
weather_helper._find_existing_weather_records(mock_weather_code).AndReturn(mock_existing_data)
# replay all
self.mox.ReplayAll()
# taco flavored kisses
new_weather_data, weather_ids_to_delete = weather_helper.sync_existing_and_new_weather_data(mock_weather_data, mock_weather_code)
# verify results
self.assertEqual(new_weather_data, [
{
"date": "date_1",
"precip_mm": 1,
"temp_c_max": 1.1,
"temp_c_min": 1.11
},
{
"date": "date_3",
"precip_mm": 3,
"temp_c_max": 3.3,
"temp_c_min": 3.33
}
])
self.assertEqual(weather_ids_to_delete, [4, 5])
def test_find_existing_weather_matches(self):
# mock some stuff!
mock_results = { 1, 2, 3, 4} # make a set so that we can test that we create a list of out it.