当前位置: 首页>>代码示例>>Python>>正文


Python Dependency.update方法代码示例

本文整理汇总了Python中common.utilities.inversion_of_control.Dependency.update方法的典型用法代码示例。如果您正苦于以下问题:Python Dependency.update方法的具体用法?Python Dependency.update怎么用?Python Dependency.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.utilities.inversion_of_control.Dependency的用法示例。


在下文中一共展示了Dependency.update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCustomAnalyticsRunner

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import update [as 别名]
class TestCustomAnalyticsRunner(mox.MoxTestBase):

    def setUp(self):

        # call parent set up
        super(TestCustomAnalyticsRunner, self).setUp()

        # register mock dependencies
        register_common_mox_dependencies(self.mox)

        # get various mox dependencies
        self.mock_retail_access = Dependency("RetailMongoAccess").value
        self.mock_logger = Dependency("FlaskLogger").value
        self.mock_cloud_provider = Dependency("CloudProvider").value
        self.mock_deployment_provider = Dependency("DeploymentProvider").value
        self.mock_service_config = Dependency("ServiceConfig").value

        # various needed data
        self.context = { "user": "chicken_woot" }
        self.task_id = ObjectId()
        self.custom_analytics_run_id = ObjectId()
        self.as_of_date = datetime.datetime(2013, 12, 1)
        self.task_rec = {
            "context": self.context,
            "custom_analytics_run_id": str(self.custom_analytics_run_id)
        }


    def doCleanups(self):

        # call parent clean up
        super(TestCustomAnalyticsRunner, self).doCleanups()

        # clear dependencies
        dependencies.clear()


    def test_successful_run(self):

        # create the runner
        runner = CustomAnalyticsRunner(self.task_rec)

        # begin stubbing things out
        self.mox.StubOutWithMock(runner, "_update_ca_run")
        self.mox.StubOutWithMock(runner, "_query_entity")
        self.mox.StubOutWithMock(runner, "_get_client_detail")
        self.mox.StubOutWithMock(runner, "_create_new_sql_db")
        self.mox.StubOutWithMock(runner, "_run_loader")
        self.mox.StubOutWithMock(runner, "_create_worker_server")
        self.mox.StubOutWithMock(runner, "_chmod_the_key")
        self.mox.StubOutWithMock(runner, "_deploy_code_to_worker")
        self.mox.StubOutWithMock(runner, "_replace_server_configs")
        self.mox.StubOutWithMock(runner, "_call_executor")

        # begin recording
        runner._update_ca_run()
        runner._query_entity().AndReturn("woot")
        runner._get_client_detail("woot").AndReturn(("test_client", "[email protected]"))
        runner._create_new_sql_db("woot").AndReturn(("chilly", "willy"))
        runner._update_ca_run(target_db_name = "chilly", logging_db_name = "willy")
        runner._run_loader("chilly", "woot").AndReturn("dates_sucka")
        runner._create_worker_server().AndReturn("sucka")
        runner._chmod_the_key()
        runner._deploy_code_to_worker("sucka")
        runner._replace_server_configs("sucka")
        runner._call_executor("woot", "sucka", "chilly", "willy", "test_client", "[email protected]", "dates_sucka")

        # replay all
        self.mox.ReplayAll()

        # run
        runner.run()


    def test_successful_run__multiple_heartbeats(self):

        # create the runner
        runner = CustomAnalyticsRunner(self.task_rec)

        # set the heart beat to be every .2 seconds
        runner._heart_beat_seconds = .2

        # create a side effect method to sleep for .3 seconds
        def sleep_side_effect(*args):
            time.sleep(.3)

        # begin stubbing things out
        self.mox.StubOutWithMock(runner, "_update_ca_run")
        self.mox.StubOutWithMock(runner, "_query_entity")
        self.mox.StubOutWithMock(runner, "_get_client_detail")
        self.mox.StubOutWithMock(runner, "_create_new_sql_db")
        self.mox.StubOutWithMock(runner, "_run_loader")
        self.mox.StubOutWithMock(runner, "_create_worker_server")
        self.mox.StubOutWithMock(runner, "_chmod_the_key")
        self.mox.StubOutWithMock(runner, "_deploy_code_to_worker")
        self.mox.StubOutWithMock(runner, "_replace_server_configs")
        self.mox.StubOutWithMock(runner, "_call_executor")

        # begin recording
        runner._update_ca_run()
#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:test_custom_analytics_runner.py

示例2: GP16GetStoreWeatherLight

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import update [as 别名]
class GP16GetStoreWeatherLight(AbstractGeoProcessor):
    """
    Same as GP16, but doesn't query or save weather data.  Only associates a store with a weather code.
    """
    def __init__(self, gp_start_date=None, gp_end_date=None):

        super(GP16GetStoreWeatherLight, self).__init__()

        # gp-specific dependencies
        self.logger = Dependency("FlaskLogger").value
        self.mds_db_access = Dependency("MDSMongoAccess").value
        self.main_access = Dependency("CoreAPIProvider").value

        # instance variables
        self._context = {'user_id': 42, 'source': 'GP16Light'}
        self._timeout = 9999

        # allows you to pass global start/end dates.
        # for example if you want to process 1 day, not the entire store's lifetime
        # plan B allows these to be set to the default, which is None
        self.date_parser = FastDateParser()
        self._start_date = self.date_parser.parse_date(gp_start_date)
        self._end_date = self.date_parser.parse_date(gp_end_date)

    # ------------------------ GP Template Methods  ------------------------ #

    def _initialize(self):

        # get class member fields from entity, which is expected to be a trade_area
        self._latitude = self._entity["data"]["latitude"]
        self._longitude = self._entity["data"]["longitude"]
        self._store_id = str(self._entity["data"]["store_id"])
        self._company_id = str(self._entity["data"]["company_id"])

        # get opened/closed dates from trade area
        store_opened_date = self.date_parser.parse_date(self._entity['data']['store_opened_date'])
        store_closed_date = self.date_parser.parse_date(self._entity['data']['store_closed_date'])

        # set start/end dates to stores lifecycle, if it's not passed in
        if self._start_date is None:
            self._start_date = store_opened_date
        if self._end_date is None:
            self._end_date = store_closed_date

        # normalize to start/end of world in case everything is null...
        self._start_date = normalize_start_date(self._start_date)
        self._end_date = normalize_end_date(self._end_date)

        # if store has opened after gp16 start date, then only get weather after store opened
        if store_opened_date and store_opened_date > self._start_date:
            self._start_date = store_opened_date

        #if store has closed before gp16 end date, then only get weather until store closed
        if store_closed_date and store_closed_date < self._end_date:
            self._end_date = store_closed_date

    def _do_geoprocessing(self):

        latitude = self._latitude
        longitude = self._longitude

        repository = weather_repository.WeatherRepository()

        # find the closest precip/temp stations
        closest_stations = repository.select_best_temp_and_precip_stations(latitude, longitude, self._start_date, self._end_date)

        # get the data
        existing_store_weather_data = self._get_existing_store_weather_data()

        # set the keys
        self.existing_weather_code = existing_store_weather_data.get("weather_code", None)
        self.existing_temp_distance = existing_store_weather_data.get("temp_station_distance", None)
        self.existing_precip_distance = existing_store_weather_data.get("precip_station_distance", None)

        # get the unique combined codes for these stations
        self.weather_station_unique_combined_code = weather_helper.get_weather_station_code(closest_stations["precip_station_code"], closest_stations["temp_station_code"])
        self.temp_station_distance = closest_stations["temp_station_distance"]
        self.precip_station_distance = closest_stations["precip_station_distance"]

    def _preprocess_data_for_save(self):
        pass

    def _save_processed_data(self):

        # if store doesn't have weather code, or it changed, set it
        if self.existing_weather_code != self.weather_station_unique_combined_code or \
                self.existing_temp_distance != self.temp_station_distance or \
                self.existing_precip_distance != self.precip_station_distance:

            # update the store object and audit the change
            self._update_store_weather_code()

    # ------------------------ Internal Methods  ------------------------ #

    def _update_store_weather_code(self):

        # run update on store
        query = { "_id": ObjectId(self._store_id) }
        update = {
            "$set": {
#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:gp16_get_store_weather_light.py

示例3: GP16Tests

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import update [as 别名]

#.........这里部分代码省略.........
        # begin stubbing
        self.mox.StubOutWithMock(weather_helper, "sync_existing_and_new_weather_data")

        # begin recording
        weather_helper.sync_existing_and_new_weather_data("chicken_woot", "sloppy_joes").AndReturn(("bob", "saget"))

        # replay all
        self.mox.ReplayAll()

        # go!
        gp._preprocess_data_for_save()

        # verify that the gp set everything correctly
        self.assertEqual(gp.new_weather_data, "bob")
        self.assertEqual(gp.weather_ids_to_delete, "saget")


    def test_save_processed_data__new_weather__code_doesnt_change(self):

        # define the gp and its properties
        gp = GP16GetStoreWeather()
        gp._store_id = "whatever"
        gp.new_weather_data = "bob_saget"
        gp.existing_weather_code = "chicken_woot"
        gp.weather_station_unique_combined_code = "chicken_woot"
        gp.existing_temp_distance = 1
        gp.existing_precip_distance = 2
        gp.temp_station_distance = 1
        gp.precip_station_distance = 2
        gp.weather_ids_to_delete = []

        # stub out some data
        self.mox.StubOutWithMock(weather_helper, "upsert_new_weather_data")
        self.mox.StubOutWithMock(gp, "_update_store_weather_code")
        self.mox.StubOutWithMock(weather_helper, "delete_existing_weather_records")

        # begin recording
        weather_helper.upsert_new_weather_data("bob_saget", "chicken_woot")

        # replay all
        self.mox.ReplayAll()

        # Big Poppa
        gp._save_processed_data()


    def test_save_processed_data__no_new_weather__code_changes(self):

        # define the gp and its properties
        gp = GP16GetStoreWeather()
        gp._store_id = "whatever"
        gp.new_weather_data = []
        gp.existing_weather_code = "chicken"
        gp.weather_station_unique_combined_code = "chicken_woot"
        gp.existing_temp_distance = 1
        gp.existing_precip_distance = 2
        gp.temp_station_distance = 1
        gp.precip_station_distance = 2
        gp.weather_ids_to_delete = []

        # stub out some data
        self.mox.StubOutWithMock(weather_helper, "upsert_new_weather_data")
        self.mox.StubOutWithMock(gp, "_update_store_weather_code")
        self.mox.StubOutWithMock(weather_helper, "delete_existing_weather_records")

        # begin recording
开发者ID:erezrubinstein,项目名称:aa,代码行数:70,代码来源:test_gp16.py

示例4: TestCustomAnalyticsScheduler

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import update [as 别名]
class TestCustomAnalyticsScheduler(mox.MoxTestBase):

    def setUp(self):

        # call parent set up
        super(TestCustomAnalyticsScheduler, self).setUp()

        # register mock dependencies
        register_common_mox_dependencies(self.mox)

        # get various mox dependencies
        self.mock_retail_access = Dependency("RetailMongoAccess").value
        self.mock_logger = Dependency("FlaskLogger").value
        self.mock_main_access = Dependency("CoreAPIProvider").value

        # various needed data
        self.context = { "user": "chicken_woot" }
        self.task_rec = { "context": self.context }

        # create the scheduler
        self.scheduler = CustomAnalyticsScheduler(self.task_rec)


    def doCleanups(self):

        # call parent clean up
        super(TestCustomAnalyticsScheduler, self).doCleanups()

        # clear dependencies
        dependencies.clear()


    def test_run__success__next_runs_plus_stuck(self):

        # begin stubbing
        self.mox.StubOutWithMock(self.scheduler, "_get_in_progress")
        self.mox.StubOutWithMock(self.scheduler, "_get_next_ca_run_ids")
        self.mox.StubOutWithMock(self.scheduler, "_update_statuses")
        self.mox.StubOutWithMock(self.scheduler, "_start_next_runs")
        self.mox.StubOutWithMock(self.scheduler, "_send_stuck_tasks_warning_email")

        # begin recording
        self.scheduler._get_in_progress().AndReturn((["woot"], ["chicken_woot"]))
        self.scheduler._get_next_ca_run_ids(2).AndReturn("chilly")
        self.scheduler._update_statuses("chilly")
        self.scheduler._start_next_runs("chilly")
        self.scheduler._update_statuses(["chicken_woot"], "queued", "queued")
        self.scheduler._send_stuck_tasks_warning_email(["chicken_woot"])

        # replay all
        self.mox.ReplayAll()

        # respect!
        self.scheduler.run()


    def test_run__success__no_room_to_run(self):

        # begin stubbing
        self.mox.StubOutWithMock(self.scheduler, "_get_in_progress")
        self.mox.StubOutWithMock(self.scheduler, "_get_next_ca_run_ids")
        self.mox.StubOutWithMock(self.scheduler, "_update_statuses")
        self.mox.StubOutWithMock(self.scheduler, "_start_next_runs")
        self.mox.StubOutWithMock(self.scheduler, "_send_stuck_tasks_warning_email")

        # begin recording
        self.scheduler._get_in_progress().AndReturn((["woot", "chilly", "willy"], []))

        # replay all
        self.mox.ReplayAll()

        # respect!
        self.scheduler.run()


    def test_run__exception(self):

        # define exception side effect method
        exception = Exception("yo mama")
        def raise_exception():
            raise exception

        # begin stubbing
        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()


#.........这里部分代码省略.........
开发者ID:erezrubinstein,项目名称:aa,代码行数:103,代码来源:test_custom_analytics_scheduler.py

示例5: WeatherHelperTests

# 需要导入模块: from common.utilities.inversion_of_control import Dependency [as 别名]
# 或者: from common.utilities.inversion_of_control.Dependency import update [as 别名]

#.........这里部分代码省略.........
            },
            {
                "date": "date_2",
                "precip_in" : 9,
                "precip_mm" : 10,
                "precip_station_code" : "chicken",
                "precip_station_name" : "whatever",
                "temp_c_max" : 11,
                "temp_c_mean" : 12,
                "temp_c_min" : 13,
                "temp_f_max" : 14,
                "temp_f_mean" : 15,
                "temp_f_min" : 16,
                "temp_station_code" : "woot",
                "temp_station_name" : "whatever",
            }
        ]

        # expected update call
        expected_batch_upserts = [
            {
                "query": {
                    "d": "date_1",
                    "code": "chicken_woot"
                },
                "operations": {
                    "$set": {
                        "d": mock_new_weather_data[0]["date"],
                        "pin": mock_new_weather_data[0]["precip_in"],
                        "pmm": mock_new_weather_data[0]["precip_mm"],
                        "tcmax": mock_new_weather_data[0]["temp_c_max"],
                        "tcmean": mock_new_weather_data[0]["temp_c_mean"],
                        "tcmin": mock_new_weather_data[0]["temp_c_min"],
                        "tfmax": mock_new_weather_data[0]["temp_f_max"],
                        "tfmean": mock_new_weather_data[0]["temp_f_mean"],
                        "tfmin": mock_new_weather_data[0]["temp_f_min"],
                        "code": "chicken_woot",
                    }
                }
            },
            {
                "query": {
                    "d": "date_2",
                    "code": "chicken_woot"
                },
                "operations": {
                    "$set": {
                        "d": mock_new_weather_data[1]["date"],
                        "pin": mock_new_weather_data[1]["precip_in"],
                        "pmm": mock_new_weather_data[1]["precip_mm"],
                        "tcmax": mock_new_weather_data[1]["temp_c_max"],
                        "tcmean": mock_new_weather_data[1]["temp_c_mean"],
                        "tcmin": mock_new_weather_data[1]["temp_c_min"],
                        "tfmax": mock_new_weather_data[1]["temp_f_max"],
                        "tfmean": mock_new_weather_data[1]["temp_f_mean"],
                        "tfmin": mock_new_weather_data[1]["temp_f_min"],
                        "code": "chicken_woot",
                    }
                }
            }
        ]


        # begin recording
        self.mock_mds_access.update("weather", expected_batch_upserts[0]["query"], expected_batch_upserts[0]["operations"], upsert=True, raw=True)
        self.mock_mds_access.update("weather", expected_batch_upserts[1]["query"], expected_batch_upserts[1]["operations"], upsert=True, raw=True)

        # replay all
        self.mox.ReplayAll()

        # I love goooood!
        weather_helper.upsert_new_weather_data(mock_new_weather_data, "chicken_woot")


    def test_parse_weather_station_code__simple(self):

        precip, temp = weather_helper.parse_weather_station_code("chicken#[email protected]")
        self.assertEqual(precip, "chicken")
        self.assertEqual(temp, "woot")


    def test_parse_weather_station_code__one_empty(self):

        precip, temp = weather_helper.parse_weather_station_code("#[email protected]")
        self.assertEqual(precip, "")
        self.assertEqual(temp, "woot")

        precip, temp = weather_helper.parse_weather_station_code("chicken#[email protected]")
        self.assertEqual(precip, "chicken")
        self.assertEqual(temp, "")

        precip, temp = weather_helper.parse_weather_station_code("#[email protected]")
        self.assertEqual(precip, "")
        self.assertEqual(temp, "")


    def test_parse_weather_station_code__error(self):

        with self.assertRaises(Exception):
            weather_helper.parse_weather_station_code("")
开发者ID:erezrubinstein,项目名称:aa,代码行数:104,代码来源:test_weather_helper.py


注:本文中的common.utilities.inversion_of_control.Dependency.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。