How to use get_description method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

TestFormats.py

Source:TestFormats.py Github

copy

Full Screen

...25 """26 Tests formated cron expressions27 """28 def test_every_minute(self):29 self.assertEqual("Every minute", get_description("* * * * *", self.options))30 def test_every1_minute(self):31 self.assertEqual("Every minute", get_description("*/1 * * * *", self.options))32 self.assertEqual("Every minute", get_description("0 0/1 * * * ?", self.options))33 def test_every_hour(self):34 self.assertEqual("Every hour", get_description("0 0 * * * ?", self.options))35 self.assertEqual("Every hour", get_description("0 0 0/1 * * ?", self.options))36 def test_time_of_day_certain_days_of_week(self):37 self.assertEqual(38 "At 11:00 PM, Monday through Friday",39 get_description("0 23 ? * MON-FRI", self.options))40 def test_every_second(self):41 self.assertEqual("Every second", get_description("* * * * * *", self.options))42 def test_every45_seconds(self):43 self.assertEqual("Every 45 seconds", get_description("*/45 * * * * *", self.options))44 def test_every5_minutes(self):45 self.assertEqual("Every 5 minutes", get_description("*/5 * * * *", self.options))46 self.assertEqual("Every 10 minutes", get_description("0 0/10 * * * ?", self.options))47 def test_every5_minutes_on_the_second(self):48 self.assertEqual("Every 5 minutes", get_description("0 */5 * * * *", self.options))49 def test_weekdays_at_time(self):50 self.assertEqual(51 "At 11:30 AM, Monday through Friday",52 get_description("30 11 * * 1-5", self.options))53 def test_daily_at_time(self):54 self.assertEqual("At 11:30 AM", get_description("30 11 * * *", self.options))55 def test_minute_span(self):56 self.assertEqual(57 "Every minute between 11:00 AM and 11:10 AM", get_description("0-10 11 * * *", self.options))58 def test_one_month_only(self):59 self.assertEqual(60 "Every minute, only in March",61 get_description("* * * 3 *", self.options))62 def test_two_months_only(self):63 self.assertEqual(64 "Every minute, only in March and June",65 get_description("* * * 3,6 *", self.options))66 def test_two_times_each_afternoon(self):67 self.assertEqual(68 "At 02:30 PM and 04:30 PM",69 get_description("30 14,16 * * *", self.options))70 def test_three_times_daily(self):71 self.assertEqual(72 "At 06:30 AM, 02:30 PM and 04:30 PM",73 get_description("30 6,14,16 * * *", self.options))74 def test_once_a_week(self):75 self.assertEqual(76 "At 09:46 AM, only on Monday",77 get_description("46 9 * * 1", self.options))78 def test_day_of_month(self):79 self.assertEqual(80 "At 12:23 PM, on day 15 of the month",81 get_description("23 12 15 * *", self.options))82 def test_month_name(self):83 self.assertEqual(84 "At 12:23 PM, only in January",85 get_description("23 12 * JAN *", self.options))86 def test_day_of_month_with_question_mark(self):87 self.assertEqual(88 "At 12:23 PM, only in January",89 get_description("23 12 ? JAN *", self.options))90 def test_month_name_range2(self):91 self.assertEqual(92 "At 12:23 PM, January through February", get_description("23 12 * JAN-FEB *", self.options))93 def test_month_name_range3(self):94 self.assertEqual(95 "At 12:23 PM, January through March",96 get_description("23 12 * JAN-MAR *", self.options))97 def test_day_of_week_name(self):98 self.assertEqual(99 "At 12:23 PM, only on Sunday",100 get_description("23 12 * * SUN", self.options))101 def test_day_of_week_name_lowercase(self):102 self.assertEqual(103 "At 12:23 PM, only on Sunday",104 get_description("23 12 * * sun", self.options))105 def test_day_of_week_range(self):106 self.assertEqual(107 "Every 5 minutes, at 03:00 PM, Monday through Friday", get_description("*/5 15 * * MON-FRI", self.options))108 def test_day_of_week_once_in_month(self):109 self.assertEqual(110 "Every minute, on the third Monday of the month", get_description("* * * * MON#3", self.options))111 def test_last_day_of_the_week_of_the_month(self):112 self.assertEqual(113 "Every minute, on the last Thursday of the month", get_description("* * * * 4L", self.options))114 def test_last_day_of_the_month(self):115 self.assertEqual(116 "Every 5 minutes, on the last day of the month, only in January", get_description(117 "*/5 * L JAN *",118 self.options119 )120 )121 def test_last_weekday_of_the_month(self):122 self.assertEqual(123 "Every minute, on the last weekday of the month", get_description("* * LW * *", self.options))124 def test_last_weekday_of_the_month2(self):125 self.assertEqual(126 "Every minute, on the last weekday of the month", get_description("* * WL * *", self.options))127 def test_first_weekday_of_the_month(self):128 self.assertEqual(129 "Every minute, on the first weekday of the month", get_description("* * 1W * *", self.options))130 def test_thirteenth_weekday_of_the_month(self):131 self.assertEqual(132 "Every minute, on the weekday nearest day 13 of the month", get_description("* * 13W * *", self.options))133 def test_first_weekday_of_the_month2(self):134 self.assertEqual(135 "Every minute, on the first weekday of the month", get_description("* * W1 * *", self.options))136 def test_particular_weekday_of_the_month(self):137 self.assertEqual(138 "Every minute, on the weekday nearest day 5 of the month", get_description("* * 5W * *", self.options))139 def test_particular_weekday_of_the_month2(self):140 self.assertEqual(141 "Every minute, on the weekday nearest day 5 of the month", get_description("* * W5 * *", self.options))142 def test_time_of_day_with_seconds(self):143 self.assertEqual("At 02:02:30 PM", get_description("30 02 14 * * *", self.options))144 def test_second_intervals(self):145 self.assertEqual(146 "Seconds 5 through 10 past the minute",147 get_description("5-10 * * * * *", self.options))148 def test_second_minutes_hours_intervals(self):149 self.assertEqual((150 "Seconds 5 through 10 past the minute, "151 "minutes 30 through 35 past the hour, "152 "between 10:00 AM and 12:59 PM"), get_description("5-10 30-35 10-12 * * *", self.options))153 def test_every5_minutes_at30_seconds(self):154 self.assertEqual(155 "At 30 seconds past the minute, every 5 minutes", get_description("30 */5 * * * *", self.options))156 def test_minutes_past_the_hour_range(self):157 self.assertEqual((158 "At 30 minutes past the hour, "159 "between 10:00 AM and 01:59 PM, "160 "only on Wednesday and Friday"), get_description("0 30 10-13 ? * WED,FRI", self.options))161 def test_seconds_past_the_minute_interval(self):162 self.assertEqual(163 "At 10 seconds past the minute, every 5 minutes", get_description("10 0/5 * * * ?", self.options))164 def test_between_with_interval(self):165 self.assertEqual(166 ("Every 3 minutes, minutes 2 through 59 past the hour, "167 "at 01:00 AM, 09:00 AM, and 10:00 PM, between day 11 and 26 of the month, "168 "January through June"), get_description("2-59/3 1,9,22 11-26 1-6 ?", self.options))169 def test_recurring_first_of_month(self):170 self.assertEqual("At 06:00 AM", get_description("0 0 6 1/1 * ?", self.options))171 def test_minutes_past_the_hour(self):172 self.assertEqual(173 "At 5 minutes past the hour",174 get_description("0 5 0/1 * * ?", self.options))175 def test_one_year_only_with_seconds(self):176 self.assertEqual(177 "Every second, only in 2013",178 get_description("* * * * * * 2013", self.options))179 def test_one_year_only_without_seconds(self):180 self.assertEqual(181 "Every minute, only in 2013",182 get_description("* * * * * 2013", self.options))183 def test_two_years_only(self):184 self.assertEqual(185 "Every minute, only in 2013 and 2014", get_description("* * * * * 2013,2014", self.options))186 def test_year_range2(self):187 self.assertEqual(188 "At 12:23 PM, January through February, 2013 through 2014", get_description(189 "23 12 * JAN-FEB * 2013-2014",190 self.options191 )192 )193 def test_year_range3(self):194 self.assertEqual(195 "At 12:23 PM, January through March, 2013 through 2015", get_description(196 "23 12 * JAN-MAR * 2013-2015",197 self.options198 )199 )200 def test_hour_range(self):201 self.assertEqual((202 "Every 30 minutes, between 08:00 AM and 09:59 AM, "203 "on day 5 and 20 of the month"), get_description("0 0/30 8-9 5,20 * ?", self.options))204 def test_day_of_week_modifier(self):205 self.assertEqual(206 "At 12:23 PM, on the second Sunday of the month", get_description("23 12 * * SUN#2", self.options))207 def test_day_of_week_modifier_with_sunday_start_one(self):208 self.options.day_of_week_start_index_zero = False209 self.assertEqual(210 "At 12:23 PM, on the second Sunday of the month", get_description("23 12 * * 1#2", self.options))211 def test_hour_range_with_every_portion(self):212 self.assertEqual((213 "At 25 minutes past the hour, every 13 hours, "214 "between 07:00 AM and 07:59 PM"), get_description("0 25 7-19/13 ? * *", self.options))215 def test_hour_range_with_trailing_zero_with_every_portion(self):216 self.assertEqual((217 "At 25 minutes past the hour, every 13 hours, "218 "between 07:00 AM and 08:59 PM"), get_description("0 25 7-20/13 ? * *", self.options))219 def test_every3_day(self):220 self.assertEqual(221 "At 08:00 AM, every 3 days",222 get_description("0 0 8 1/3 * ? *", self.options))223 def tests_every3_day_of_the_week(self):224 self.assertEqual(225 "At 10:15 AM, every 3 days of the week",226 get_description("0 15 10 ? * */3", self.options))227 def test_every_2_day_of_the_week_in_range(self):228 self.assertEqual(229 "Every second, every 2 days of the week, Monday through Friday",230 get_description("* * * ? * 1-5/2", self.options))231 def test_every_2_day_of_the_week_in_range_with_sunday_start_one(self):232 self.options.day_of_week_start_index_zero = False233 self.assertEqual(234 "Every second, every 2 days of the week, Monday through Friday",235 get_description("* * * ? * 2-6/2", self.options))236 def test_every3_month(self):237 self.assertEqual(238 "At 07:05 AM, on day 2 of the month, every 3 months", get_description("0 5 7 2 1/3 ? *", self.options))239 def test_every2_years(self):240 self.assertEqual(241 "At 06:15 AM, on day 1 of the month, only in January, every 2 years", get_description(242 "0 15 6 1 1 ? 1/2",243 self.options244 )245 )246 def test_muti_part_range_minutes(self):247 self.assertEqual(248 "At 2 and 4 through 5 minutes past the hour, at 01:00 AM", get_description("2,4-5 1 * * *", self.options))249 def test_muti_part_range_minutes_2(self):250 self.assertEqual(251 "At 2 and 26 through 28 minutes past the hour, at 06:00 PM", get_description(252 "2,26-28 18 * * *",253 self.options254 )255 )256 def test_trailing_space_does_not_cause_a_wrong_description(self):257 self.assertEqual(258 "At 07:00 AM", get_description("0 7 * * * ", self.options))259 def test_multi_part_day_of_the_week(self):260 self.assertEqual(261 "At 10:00 AM, only on Monday through Thursday and Sunday", get_description("0 00 10 ? * MON-THU,SUN *"))262 def test_day_of_week_with_day_of_month(self):263 self.assertEqual(264 "At 00:00 AM, on day 1, 2, and 3 of the month, only on Wednesday and Friday",265 get_description("0 0 0 1,2,3 * WED,FRI", self.options)266 )267 def test_seconds_internal_with_step_value(self):268 self.assertEqual(269 "Every 30 seconds, starting at 5 seconds past the minute",270 get_description("5/30 * * * * ?", self.options))271 def test_minutes_internal_with_step_value(self):272 self.assertEqual(273 "Every 30 minutes, starting at 5 minutes past the hour",274 get_description("0 5/30 * * * ?", self.options))275 def test_hours_internal_with_step_value(self):276 self.assertEqual(277 "Every second, every 8 hours, starting at 05:00 AM",278 get_description("* * 5/8 * * ?", self.options))279 def test_day_of_month_internal_with_step_value(self):280 self.assertEqual(281 "At 07:05 AM, every 3 days, starting on day 2 of the month",282 get_description("0 5 7 2/3 * ? *", self.options))283 def test_month_internal_with_step_value(self):284 self.assertEqual(285 "At 07:05 AM, every 2 months, March through December",286 get_description("0 5 7 ? 3/2 ? *", self.options))287 def test_day_of_week_internal_with_step_value(self):288 self.assertEqual(289 "At 07:05 AM, every 3 days of the week, Tuesday through Saturday",290 get_description("0 5 7 ? * 2/3 *", self.options))291 def test_year_internal_with_step_value(self):292 self.assertEqual(293 "At 07:05 AM, every 4 years, 2016 through 9999",294 get_description("0 5 7 ? * ? 2016/4", self.options))295 def test_minites_combined_with_multiple_hour_ranges(self):296 self.assertEqual(297 "At 1 minutes past the hour, at 01:00 AM and 03:00 AM through 04:59 AM",...

Full Screen

Full Screen

test_describable.py

Source:test_describable.py Github

copy

Full Screen

...123 assert isinstance(f, Foo19)124 assert init_called == [description]125# ##################### get_description ##############################126def test_get_description_basic_types():127 assert get_description(13) == 13128 assert get_description(0xff) == 0xff129 assert get_description(23.5) == 23.5130 assert get_description(1.3e-7) == 1.3e-7131 assert get_description(True) is True132 assert get_description(False) is False133 assert get_description('foo') == 'foo'134 assert get_description(None) is None135def test_get_description_list():136 assert get_description([]) == []137 assert get_description([1, 2, 3]) == [1, 2, 3]138 assert get_description([1, 'b']) == [1, 'b']139def test_get_description_dict():140 assert get_description({}) == {}141 assert get_description({'a': 1, 'b': 'bar'}) == {'a': 1, 'b': 'bar'}142def test_get_description_ndarray():143 assert get_description(np.array(1.7)) == 1.7144 assert get_description(np.array([[1], [2], [3]])) == [[1], [2], [3]]145 assert get_description(np.array([1, 2, 3])) == [1, 2, 3]146def test_get_description_describable():147 class Foo20(Describable):148 pass149 f = Foo20()150 assert get_description(f) == {'@type': 'Foo20'}151def test_get_description_for_undescribable_raises():152 with pytest.raises(TypeError) as excinfo:153 get_description(pytest)154 assert excinfo.value.args[0].find("module") > -1155def test_get_description_with_undescribable_in_list_raises():156 with pytest.raises(TypeError) as excinfo:157 get_description([1, 2, pytest, 4])158 assert excinfo.value.args[0].find("module") > -1159 assert excinfo.value.args[0].find("[2]") > -1160def test_get_description_with_undescribable_in_dict_raises():161 with pytest.raises(TypeError) as excinfo:162 get_description({'foo': pytest})163 assert excinfo.value.args[0].find("module") > -1164 assert excinfo.value.args[0].find("[foo]") > -1165def test_get_description_with_undescribable_in_describable_raises():166 class Foo21(Describable):167 pass168 f = Foo21()169 f.mymod = pytest170 with pytest.raises(TypeError) as excinfo:171 get_description(f)172 assert excinfo.value.args[0].find("module") > -1173 assert excinfo.value.args[0].find("[Foo21.mymod]") > -1174# ##################### create_from_description ##############################175def test_create_from_description():176 assert create_from_description(13) == 13177 assert create_from_description(0xff) == 0xff178 assert create_from_description(23.5) == 23.5179 assert create_from_description(1.3e-7) == 1.3e-7180 assert create_from_description(True) is True181 assert create_from_description(False) is False182 assert create_from_description('foo') == 'foo'183 assert create_from_description(None) is None184def test_create_from_description_list():185 assert create_from_description([]) == []186 assert create_from_description([1, 2, 3]) == [1, 2, 3]187 assert create_from_description([1, 'b']) == [1, 'b']188def test_create_from_description_dict():189 assert create_from_description({}) == {}190 assert create_from_description({'a': 1, 'b': 'ar'}) == {'a': 1, 'b': 'ar'}191def test_create_from_description_describable():192 class Foo22(Describable):193 pass194 f = create_from_description({'@type': 'Foo22'})195 assert isinstance(f, Foo22)196def test_create_from_description_with_undescribable_raises():197 with pytest.raises(TypeError) as excinfo:198 create_from_description({'@type': 'Unknown66'})199 assert excinfo.value.args[0].find("Unknown66") > -1200def test_create_from_description_with_invalid_description_raises():201 with pytest.raises(TypeError) as excinfo:202 create_from_description(pytest)203 assert excinfo.value.args[0].find('module') > -1204# ################# test describing handler ###################################205@pytest.mark.skipif(has_pycuda is False, reason='requires pycuda and skcuda')206def test_describe_pycuda_handler():207 from brainstorm.handlers.pycuda_handler import PyCudaHandler208 pch = PyCudaHandler()209 d = get_description(pch)210 assert d == {'@type': 'PyCudaHandler'}211 pch2 = create_from_description(d)212 assert isinstance(pch2, PyCudaHandler)213def test_describe_numpy_handler():214 nh = NumpyHandler(np.float32)215 d = get_description(nh)216 assert d == {'@type': 'NumpyHandler', 'dtype': 'float32'}217 nh2 = create_from_description(d)218 assert isinstance(nh2, NumpyHandler)219 assert nh2.dtype == np.float32220# ################# test describing a Network #################################221arch = generate_architecture(222 bs.layers.Input(out_shapes={'default': ('T', 'B', 7)}) >>223 bs.layers.FullyConnected(3) >>224 bs.layers.Loss())225def test_describe_network():226 net = bs.Network.from_architecture(arch)227 net.initialize(1)228 assert get_description(net) == {229 '@type': 'Network',230 'architecture': json.loads(json.dumps(arch)),231 'handler': {'@type': 'NumpyHandler', 'dtype': 'float32'},232 'initializers': {'default': 1},233 'weight_modifiers': {},234 'gradient_modifiers': {},235 'output_name': None236 }237def test_get_network_from_description():238 net = bs.Network.from_architecture(arch)239 net.initialize(1)240 d = get_description(net)241 net2 = create_from_description(d)242 assert isinstance(net2, bs.Network)243 assert net2.layers.keys() == net.layers.keys()244 assert isinstance(net2.handler, NumpyHandler)245 assert net2.handler.dtype == np.float32246 assert np.all(net2.buffer.parameters == net.buffer.parameters)247# ################# test describing a Trainer #################################248def test_describe_trainer():249 tr = bs.Trainer(bs.training.SgdStepper(learning_rate=0.7), verbose=False)250 tr.add_hook(bs.hooks.StopAfterEpoch(23))251 tr.add_hook(bs.hooks.StopOnNan())252 d = get_description(tr)253 assert d == {254 '@type': 'Trainer',255 'verbose': False,256 'hooks': {257 'StopAfterEpoch': {258 '@type': 'StopAfterEpoch',259 'max_epochs': 23,260 'priority': 1},261 'StopOnNan': {262 '@type': 'StopOnNan',263 'check_parameters': True,264 'check_training_loss': True,265 'logs_to_check': [],266 'priority': 2}},267 'stepper': {268 '@type': 'SgdStepper',269 'learning_rate': 0.7},270 'train_scorers': []271 }272def test_recreate_trainer_from_description():273 tr = bs.Trainer(bs.training.SgdStepper(learning_rate=0.7), verbose=False)274 tr.add_hook(bs.hooks.StopAfterEpoch(23))275 tr.add_hook(bs.hooks.StopOnNan())276 d = get_description(tr)277 tr2 = create_from_description(d)278 assert isinstance(tr2, bs.Trainer)279 assert tr2.verbose is False280 assert list(tr2.hooks.keys()) == ['StopAfterEpoch', 'StopOnNan']281 assert tr2.hooks['StopAfterEpoch'].max_epochs == 23282 assert isinstance(tr2.stepper, bs.training.SgdStepper)...

Full Screen

Full Screen

core_services.py

Source:core_services.py Github

copy

Full Screen

...38 return envs.EnvironmentServices.get_status(environment_id)39 @staticmethod40 def get_data(environment_id, path, session_id=None):41 get_description = envs.EnvironmentServices.get_environment_description42 env_description = get_description(environment_id, session_id)43 if env_description is None:44 return None45 if 'services' not in env_description:46 return []47 result = utils.TraverseHelper.get(path, env_description)48 if path == '/services':49 get_status = CoreServices.get_service_status50 for srv in result:51 srv['?']['status'] = get_status(environment_id, srv['?']['id'])52 return result53 @staticmethod54 def get_template_data(env_template_id, path):55 """It obtains the data for the template.56 It includes all the services. In case the path includes information57 such as the env_template_id, the information provided will58 be related to the entity specified in the path59 :param env_template_id: The env_template_id to obtain the data60 :param path: Id of service for which we checking status.61 :return: The template description62 """63 temp_description = env_temp.EnvTemplateServices.\64 get_description(env_template_id)65 if temp_description is None:66 return None67 if 'services' not in temp_description:68 return []69 result = utils.TraverseHelper.get(path, temp_description)70 if result is None:71 msg = _('Environment Template <EnvId {id}> is not found').format(72 id=env_template_id)73 LOG.error(msg)74 raise exc.HTTPNotFound(explanation=msg)75 return result76 @staticmethod77 def post_env_template_data(env_template_id, data, path):78 """It stores the template data inside the template description.79 :param env_template_id: The env_template_id to obtain the data80 :param data: the template description81 :param path: Id of service for which we checking status.82 :return: The template description83 """84 get_description = env_temp.EnvTemplateServices.get_description85 save_description = env_temp.EnvTemplateServices.save_description86 temp_description = get_description(env_template_id)87 if temp_description is None:88 msg = _('Environment Template <EnvId {id}> is not found').format(89 id=env_template_id)90 LOG.error(msg)91 raise exc.HTTPNotFound(explanation=msg)92 if 'services' not in temp_description:93 temp_description['services'] = []94 if path == '/services':95 if isinstance(data, list):96 utils.TraverseHelper.extend(path, data, temp_description)97 else:98 utils.TraverseHelper.insert(path, data, temp_description)99 save_description(temp_description)100 return data101 @staticmethod102 def post_application_data(env_template_id, data, path):103 """It stores the application data inside the template description.104 :param env_template_id: The env_template_id to obtain the data105 :param data: the template description106 :param path: Id of service for which we checking status.107 :return: The template description108 """109 get_description = env_temp.EnvTemplateServices.get_description110 save_description = env_temp.EnvTemplateServices.save_description111 temp_description = get_description(env_template_id)112 if temp_description is None:113 msg = _('Environment Template <EnvId {0}> is not found').format(114 env_template_id)115 LOG.error(msg)116 raise exc.HTTPNotFound(explanation=msg)117 if 'services' not in temp_description:118 temp_description['services'] = []119 if path == '/services':120 if isinstance(data, list):121 utils.TraverseHelper.extend(path, data, temp_description)122 else:123 utils.TraverseHelper.insert(path, data, temp_description)124 save_description(temp_description, env_template_id)125 return data126 @staticmethod127 def post_data(environment_id, session_id, data, path):128 get_description = envs.EnvironmentServices.get_environment_description129 save_description = envs.EnvironmentServices.\130 save_environment_description131 env_description = get_description(environment_id, session_id)132 if env_description is None:133 msg = _('Environment <EnvId {0}> is not found').format(134 environment_id)135 LOG.error(msg)136 raise exc.HTTPNotFound(explanation=msg)137 if 'services' not in env_description:138 env_description['services'] = []139 if path == '/services':140 if isinstance(data, list):141 utils.TraverseHelper.extend(path, data, env_description)142 else:143 utils.TraverseHelper.insert(path, data, env_description)144 save_description(session_id, env_description)145 return data146 @staticmethod147 def put_data(environment_id, session_id, data, path):148 get_description = envs.EnvironmentServices.get_environment_description149 save_description = envs.EnvironmentServices.\150 save_environment_description151 env_description = get_description(environment_id, session_id)152 utils.TraverseHelper.update(path, data, env_description)153 env_description['?']['updated'] = str(timeutils.utcnow())154 save_description(session_id, env_description)155 return data156 @staticmethod157 def delete_data(environment_id, session_id, path):158 get_description = envs.EnvironmentServices.get_environment_description159 save_description = envs.EnvironmentServices.\160 save_environment_description161 env_description = get_description(environment_id, session_id)162 utils.TraverseHelper.remove(path, env_description)163 save_description(session_id, env_description)164 @staticmethod165 def delete_env_template_data(env_template_id, path):166 """It deletes a template.167 :param env_template_id: The env_template_id to be deleted.168 :param path: The path to check.169 """170 get_description = env_temp.EnvTemplateServices.get_description171 save_description = env_temp.EnvTemplateServices.save_description172 tmp_description = get_description(env_template_id)173 if tmp_description is None:174 msg = _('Environment Template <EnvId {0}> is not found').format(175 env_template_id)176 LOG.error(msg)177 raise exc.HTTPNotFound(explanation=msg)178 utils.TraverseHelper.remove(path, tmp_description)179 save_description(tmp_description, env_template_id)180 return tmp_description181 @staticmethod182 def put_application_data(env_template_id, data, path):183 """It stores the application data inside the template description.184 :param env_template_id: The env_template_id to obtain the data185 :param data: the template description186 :param path: Id of service for which we checking status.187 :return: The template description188 """189 get_description = env_temp.EnvTemplateServices.get_description190 save_description = env_temp.EnvTemplateServices.save_description191 temp_description = get_description(env_template_id)192 if temp_description is None:193 msg = _('Environment Template <EnvId {0}> is not found').format(194 env_template_id)195 LOG.error(msg)196 raise exc.HTTPNotFound(explanation=msg)197 count = 0198 id = path[1:].split('/')[-1]199 for service in temp_description["services"]:200 if service["?"]["id"]:201 if service["?"]["id"] == id:202 break203 count+1204 utils.TraverseHelper.update("services/{0}".format(count),205 data, temp_description)...

Full Screen

Full Screen

test_core_service.py

Source:test_core_service.py Github

copy

Full Screen

1# Copyright (c) 2015 Telefonica I+D.2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or11# implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import mock15from webob import exc16from murano.db.services import core_services17from murano.tests.unit import base18from murano.tests.unit.db.services import environment_templates as et19class TestCoreServices(base.MuranoTestCase):20 def setUp(self):21 super(TestCoreServices, self).setUp()22 self.core_services = core_services.CoreServices23 self.addCleanup(mock.patch.stopall)24 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')25 def test_empty_template(self, template_services_mock):26 """Check obtaining the template description without services."""27 fixture = self.useFixture(et.EmptyEnvironmentTemplateFixture())28 template_services_mock.get_description.return_value = \29 fixture.environment_template_desc30 template_des = self.core_services.get_template_data('any', '/services')31 self.assertEqual([], template_des)32 template_services_mock.get_description.assert_called_with('any')33 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')34 def test_template_services(self, template_services_mock):35 """Check obtaining the template description with services."""36 fixture_apps = self.useFixture(et.ApplicationsFixture())37 fixture_env_apps = self.useFixture(et.AppEnvTemplateFixture())38 template_services_mock.get_description.return_value = \39 fixture_env_apps.env_template_desc40 template_des = self.core_services.get_template_data('any', '/services')41 self.assertEqual(fixture_apps.applications_desc, template_des)42 template_services_mock.get_description.assert_called_with('any')43 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')44 def test_template_get_service(self, template_services_mock):45 """Check obtaining the service description."""46 fixture = self.useFixture(et.AppEnvTemplateFixture())47 fixture2 = self.useFixture(et.ApplicationTomcatFixture())48 template_services_mock.get_description.return_value = \49 fixture.env_template_desc50 template_des = \51 self.core_services.get_template_data('any',52 '/services/tomcat_id')53 self.assertEqual(fixture2.application_tomcat_desc, template_des)54 template_services_mock.get_description.assert_called_with('any')55 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')56 def test_template_post_services(self, template_services_mock):57 """Check adding a service to a template."""58 fixture = self.useFixture(et.EmptyEnvironmentTemplateFixture())59 fixture2 = self.useFixture(et.AppEnvTemplateFixture())60 template_services_mock.get_description.return_value = \61 fixture.environment_template_desc62 template_des = self.core_services.\63 post_env_template_data('any',64 fixture2.env_template_desc,65 '/services')66 self.assertEqual(fixture2.env_template_desc, template_des)67 template_services_mock.get_description.assert_called_with('any')68 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')69 def test_template_delete_services(self, template_services_mock):70 """Check deleting a service in a template."""71 fixture2 = self.useFixture(et.AppEnvTemplateFixture())72 fixture = self.useFixture(et.ApplicationTomcatFixture())73 template_services_mock.get_description.return_value = \74 fixture2.env_template_desc75 self.core_services.\76 delete_env_template_data('any',77 '/services/54aaa43d-5970')78 template_des = self.core_services.get_template_data('any', '/services')79 self.assertEqual([fixture.application_tomcat_desc], template_des)80 template_services_mock.get_description.assert_called_with('any')81 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')82 def test_get_template_no_exists(self, template_services_mock):83 """Check obtaining a non-existing service."""84 fixture2 = self.useFixture(et.AppEnvTemplateFixture())85 template_services_mock.get_description.return_value = \86 fixture2.env_template_desc87 self.assertRaises(exc.HTTPNotFound,88 self.core_services.get_template_data,89 'any', '/services/noexists')90 template_services_mock.get_description.assert_called_with('any')91 @mock.patch('murano.db.services.environment_templates.EnvTemplateServices')92 def test_adding_services(self, template_services_mock):93 """Check adding services to a template."""94 ftomcat = self.useFixture(et.ApplicationTomcatFixture())95 fmysql = self.useFixture(et.ApplicationMysqlFixture())96 fixture = self.useFixture(et.EmptyEnvironmentTemplateFixture())97 fservices = self.useFixture(et.ApplicationsFixture())98 template_services_mock.get_description.return_value =\99 fixture.environment_template_desc100 self.core_services.\101 post_env_template_data('any',102 ftomcat.application_tomcat_desc,103 '/services')104 self.core_services.\105 post_env_template_data('any',106 fmysql.application_mysql_desc,107 '/services')108 template_des = \109 self.core_services.get_template_data('any', '/services')110 self.assertEqual(fservices.applications_desc, template_des)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful