How to use _create_template method in localstack

Best Python code snippet using localstack_python

test_template.py

Source: test_template.py Github

copy

Full Screen

...33 # ensure django ValidationError is raised34 with self.assertRaises(ValidationError):35 t.full_clean()36 def test_config_status_modified_after_change(self):37 t = self._create_template()38 c = self._create_config(device=self._create_device(name='test-status'))39 self.assertEqual(c.status, 'modified')40 with catch_signal(config_status_changed) as handler:41 c.templates.add(t)42 handler.assert_not_called()43 c.status = 'applied'44 c.save()45 c.refresh_from_db()46 self.assertEqual(c.status, 'applied')47 t.config['interfaces'][0]['name'] = 'eth1'48 t.full_clean()49 with catch_signal(config_status_changed) as handler:50 t.save()51 c.refresh_from_db()52 handler.assert_called_once_with(53 sender=Config, signal=config_status_changed, instance=c,54 )55 self.assertEqual(c.status, 'modified')56 # status has already changed to modified57 # sgnal should not be triggered again58 with catch_signal(config_status_changed) as handler:59 t.config['interfaces'][0]['name'] = 'eth2'60 t.full_clean()61 t.save()62 c.refresh_from_db()63 handler.assert_not_called()64 self.assertEqual(c.status, 'modified')65 def test_config_status_modified_after_template_added(self):66 t = self._create_template()67 c = self._create_config(device=self._create_device(name='test-status'))68 c.status = 'applied'69 c.save()70 c.refresh_from_db()71 with catch_signal(config_status_changed) as handler:72 c.templates.add(t)73 c.refresh_from_db()74 handler.assert_called_once_with(75 sender=Config, signal=config_status_changed, instance=c,76 )77 def test_config_modified_signal_always_sent(self):78 t = self._create_template()79 c = self._create_config(device=self._create_device(name='test-status'))80 self.assertEqual(c.status, 'modified')81 with catch_signal(config_modified) as handler:82 c.templates.add(t)83 handler.assert_called_once_with(84 sender=Config,85 signal=config_modified,86 instance=c,87 device=c.device,88 config=c,89 )90 c.status = 'applied'91 c.save()92 c.refresh_from_db()93 self.assertEqual(c.status, 'applied')94 t.config['interfaces'][0]['name'] = 'eth1'95 t.full_clean()96 with catch_signal(config_modified) as handler:97 t.save()98 c.refresh_from_db()99 handler.assert_called_once()100 self.assertEqual(c.status, 'modified')101 # status has already changed to modified102 # sgnal should be triggered anyway103 with catch_signal(config_modified) as handler:104 t.config['interfaces'][0]['name'] = 'eth2'105 t.full_clean()106 t.save()107 c.refresh_from_db()108 handler.assert_called_once()109 self.assertEqual(c.status, 'modified')110 def test_no_auto_hostname(self):111 t = self._create_template()112 self.assertNotIn('general', t.backend_instance.config)113 t.refresh_from_db()114 self.assertNotIn('general', t.config)115 def test_default_template(self):116 # no default templates defined yet117 c = self._create_config()118 self.assertEqual(c.templates.count(), 0)119 c.device.delete()120 # create default templates for different backends121 t1 = self._create_template(122 name='default-openwrt', backend='netjsonconfig.OpenWrt', default=True123 )124 t2 = self._create_template(125 name='default-openwisp', backend='netjsonconfig.OpenWisp', default=True126 )127 c1 = self._create_config(128 device=self._create_device(name='test-openwrt'),129 backend='netjsonconfig.OpenWrt',130 )131 d2 = self._create_device(132 name='test-openwisp', mac_address=self.TEST_MAC_ADDRESS.replace('55', '56')133 )134 c2 = self._create_config(device=d2, backend='netjsonconfig.OpenWisp')135 # ensure OpenWRT device has only the default OpenWRT backend136 self.assertEqual(c1.templates.count(), 1)137 self.assertEqual(c1.templates.first().id, t1.id)138 # ensure OpenWISP device has only the default OpenWISP backend139 self.assertEqual(c2.templates.count(), 1)140 self.assertEqual(c2.templates.first().id, t2.id)141 def test_vpn_missing(self):142 try:143 self._create_template(type='vpn')144 except ValidationError as err:145 self.assertTrue('vpn' in err.message_dict)146 else:147 self.fail('ValidationError not raised')148 def test_generic_has_no_vpn(self):149 t = self._create_template(vpn=self._create_vpn())150 self.assertIsNone(t.vpn)151 self.assertFalse(t.auto_cert)152 def test_generic_has_create_cert_false(self):153 t = self._create_template()154 self.assertFalse(t.auto_cert)155 def test_auto_client_template(self):156 vpn = self._create_vpn()157 t = self._create_template(158 name='autoclient', type='vpn', auto_cert=True, vpn=vpn, config={}159 )160 control = t.vpn.auto_client()161 self.assertDictEqual(t.config, control)162 def test_auto_client_template_auto_cert_False(self):163 vpn = self._create_vpn()164 t = self._create_template(165 name='autoclient', type='vpn', auto_cert=False, vpn=vpn, config={}166 )167 vpn = t.config['openvpn'][0]168 self.assertEqual(vpn['cert'], 'cert.pem')169 self.assertEqual(vpn['key'], 'key.pem')170 self.assertEqual(len(t.config['files']), 1)171 self.assertIn('ca_path', t.config['files'][0]['path'])172 def test_template_context_var(self):173 t = self._create_template(174 config={175 'files': [176 {177 'path': '/​etc/​vpnserver1',178 'mode': '0644',179 'contents': '{{ name }}\n{{ vpnserver1 }}\n',180 }181 ]182 }183 )184 c = self._create_config()185 c.templates.add(t)186 # clear cache187 del c.backend_instance188 output = c.backend_instance.render()189 vpnserver1 = settings.NETJSONCONFIG_CONTEXT['vpnserver1']190 self.assertIn(vpnserver1, output)191 def test_get_context(self):192 t = self._create_template()193 expected = {}194 expected.update(settings.NETJSONCONFIG_CONTEXT)195 self.assertEqual(t.get_context(), expected)196 def test_tamplates_clone(self):197 t = self._create_template(default=True)198 t.save()199 user = User.objects.create_superuser(200 username='admin', password='tester', email='admin@admin.com'201 )202 c = t.clone(user)203 c.full_clean()204 c.save()205 self.assertEqual(c.name, '{} (Clone)'.format(t.name))206 self.assertIsNotNone(c.pk)207 self.assertNotEqual(c.pk, t.pk)208 self.assertFalse(c.default)209 def test_duplicate_files_in_template(self):210 try:211 self._create_template(212 name='test-vpn-1',213 config={214 'files': [215 {216 'path': '/​etc/​vpnserver1',217 'mode': '0644',218 'contents': '{{ name }}\n{{ vpnserver1 }}\n',219 },220 {221 'path': '/​etc/​vpnserver1',222 'mode': '0644',223 'contents': '{{ name }}\n{{ vpnserver1 }}\n',224 },225 ]...

Full Screen

Full Screen

tsdl182gen.py

Source: tsdl182gen.py Github

copy

Full Screen

...75 'ft_str': _filt_ft_str,76 'ft_lengths': _filt_ft_lengths,77 'deepest_ft': _filt_deepest_ft,78}79def _create_template(name: str, is_file_template: bool = False,80 cfg: Optional[barectf_config.Configuration] = None) -> barectf_template._Template:81 return barectf_template._Template(f'metadata/​{name}', is_file_template, cfg,82 typing.cast(barectf_template._Filters, _TEMPL_FILTERS))83_ENUM_FT_TEMPL = _create_template('enum-ft.j2')84_INT_FT_TEMPL = _create_template('int-ft.j2')85_REAL_FT_TEMPL = _create_template('real-ft.j2')86_STR_FT_TEMPL = _create_template('str-ft.j2')87_STRUCT_FT_TEMPL = _create_template('struct-ft.j2')88def _from_config(cfg: barectf_config.Configuration) -> str:...

Full Screen

Full Screen

__template.py

Source: __template.py Github

copy

Full Screen

...11 self.log(response.status)12if __name__ == '__main__':13 MySpider.run(__file__)14"""15def _create_template(file_path, method="GET", url=None, formdata=None):16 config = dict()17 config['url'] = url or "https:/​/​github.com/​CzaOrz"18 if method == "GET":19 config['request'] = "Request"20 config['formdata'] = ""21 config['start_requests'] = "yield Request(url)"22 elif method == "POST":23 config['request'] = "FormRequest"24 config['formdata'] = f"formdata = {formdata or {}}\n"25 config['start_requests'] = "yield FormRequest(url, formdata=self.formdata)"26 elif method == "EASE":27 template_string = template_base.format("", "")28 return create_template(file_path, template_string, config)29 else:30 raise RuntimeError("just support GET/​POST")31 template_string = template_base.format(32 """from scrapy import $request\n""",33 """$formdata34 def start_requests(self):35 for url in self.start_urls:36 $start_requests37 """38 )39 return create_template(file_path, template_string, config)40def template_get(file_path, url=None):41 _create_template(file_path, method="GET", url=url)42def template_post(file_path, url=None, formdata=None):43 _create_template(file_path, method="POST", url=url, formdata=formdata)44def template_ease(file_path, url=None):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

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 localstack 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