How to use get_dashboard method in localstack

Best Python code snippet using localstack_python

base.py

Source:base.py Github

copy

Full Screen

...112 horizon.register(MyPanel)113 with self.assertRaises(ValueError):114 horizon.register("MyPanel")115 # Retrieval116 my_dash_instance_by_name = horizon.get_dashboard("mydash")117 self.assertTrue(isinstance(my_dash_instance_by_name, MyDash))118 my_dash_instance_by_class = horizon.get_dashboard(MyDash)119 self.assertEqual(my_dash_instance_by_name, my_dash_instance_by_class)120 with self.assertRaises(base.NotRegistered):121 horizon.get_dashboard("fake")122 self.assertQuerysetEqual(horizon.get_dashboards(),123 ['<Dashboard: cats>',124 '<Dashboard: dogs>',125 '<Dashboard: mydash>'])126 # Removal127 self.assertEqual(len(base.Horizon._registry), 3)128 horizon.unregister(MyDash)129 self.assertEqual(len(base.Horizon._registry), 2)130 with self.assertRaises(base.NotRegistered):131 horizon.get_dashboard(MyDash)132 def test_site(self):133 self.assertEqual(unicode(base.Horizon), "Horizon")134 self.assertEqual(repr(base.Horizon), "<Site: horizon>")135 dash = base.Horizon.get_dashboard('cats')136 self.assertEqual(base.Horizon.get_default_dashboard(), dash)137 test_user = User()138 self.assertEqual(base.Horizon.get_user_home(test_user),139 dash.get_absolute_url())140 def test_dashboard(self):141 cats = horizon.get_dashboard("cats")142 self.assertEqual(cats._registered_with, base.Horizon)143 self.assertQuerysetEqual(cats.get_panels(),144 ['<Panel: kittens>',145 '<Panel: tigers>'])146 self.assertEqual(cats.get_absolute_url(), "/cats/")147 self.assertEqual(cats.name, "Cats")148 # Test registering a module with a dashboard that defines panels149 # as a panel group.150 cats.register(MyPanel)151 self.assertQuerysetEqual(cats.get_panel_groups()['other'],152 ['<Panel: myslug>'])153 # Test that panels defined as a tuple still return a PanelGroup154 dogs = horizon.get_dashboard("dogs")155 self.assertQuerysetEqual(dogs.get_panel_groups().values(),156 ['<PanelGroup: default>'])157 # Test registering a module with a dashboard that defines panels158 # as a tuple.159 dogs = horizon.get_dashboard("dogs")160 dogs.register(MyPanel)161 self.assertQuerysetEqual(dogs.get_panels(),162 ['<Panel: puppies>',163 '<Panel: myslug>'])164 def test_panels(self):165 cats = horizon.get_dashboard("cats")166 tigers = cats.get_panel("tigers")167 self.assertEqual(tigers._registered_with, cats)168 self.assertEqual(tigers.get_absolute_url(), "/cats/tigers/")169 def test_index_url_name(self):170 cats = horizon.get_dashboard("cats")171 tigers = cats.get_panel("tigers")172 tigers.index_url_name = "does_not_exist"173 with self.assertRaises(urlresolvers.NoReverseMatch):174 tigers.get_absolute_url()175 tigers.index_url_name = "index"176 self.assertEqual(tigers.get_absolute_url(), "/cats/tigers/")177 def test_lazy_urls(self):178 urlpatterns = horizon.urls[0]179 self.assertTrue(isinstance(urlpatterns, base.LazyURLPattern))180 # The following two methods simply should not raise any exceptions181 iter(urlpatterns)182 reversed(urlpatterns)183 def test_horizon_test_isolation_1(self):184 """ Isolation Test Part 1: sets a value. """185 cats = horizon.get_dashboard("cats")186 cats.evil = True187 def test_horizon_test_isolation_2(self):188 """ Isolation Test Part 2: The value set in part 1 should be gone. """189 cats = horizon.get_dashboard("cats")190 self.assertFalse(hasattr(cats, "evil"))191 def test_public(self):192 dogs = horizon.get_dashboard("dogs")193 # Known to have no restrictions on it other than being logged in.194 puppies = dogs.get_panel("puppies")195 url = puppies.get_absolute_url()196 # Get a clean, logged out client instance.197 self.client.logout()198 resp = self.client.get(url)199 redirect_url = "?".join(['http://testserver' + settings.LOGIN_URL,200 "next=%s" % url])201 self.assertRedirects(resp, redirect_url)202 # Simulate ajax call203 resp = self.client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')204 # Response should be HTTP 401 with redirect header205 self.assertEqual(resp.status_code, 401)206 self.assertEqual(resp["X-Horizon-Location"],207 redirect_url)208 def test_required_permissions(self):209 dash = horizon.get_dashboard("cats")210 panel = dash.get_panel('tigers')211 # Non-admin user212 self.assertQuerysetEqual(self.user.get_all_permissions(), [])213 resp = self.client.get(panel.get_absolute_url())214 self.assertEqual(resp.status_code, 302)215 resp = self.client.get(panel.get_absolute_url(),216 follow=False,217 HTTP_X_REQUESTED_WITH='XMLHttpRequest')218 self.assertEqual(resp.status_code, 401)219 # Test insufficient permissions for logged-in user220 resp = self.client.get(panel.get_absolute_url(), follow=True)221 self.assertEqual(resp.status_code, 200)222 self.assertTemplateUsed(resp, "auth/login.html")223 self.assertContains(resp, "Login as different user", 1, 200)224 # Set roles for admin user225 self.set_permissions(permissions=['test'])226 resp = self.client.get(panel.get_absolute_url())227 self.assertEqual(resp.status_code, 200)228 # Test modal form229 resp = self.client.get(panel.get_absolute_url(),230 follow=False,231 HTTP_X_REQUESTED_WITH='XMLHttpRequest')232 self.assertEqual(resp.status_code, 200)233 def test_ssl_redirect_by_proxy(self):234 dogs = horizon.get_dashboard("dogs")235 puppies = dogs.get_panel("puppies")236 url = puppies.get_absolute_url()237 redirect_url = "?".join([settings.LOGIN_URL,238 "next=%s" % url])239 self.client.logout()240 resp = self.client.get(url)241 self.assertRedirects(resp, redirect_url)242 # Set SSL settings for test server243 settings.SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL',244 'https')245 resp = self.client.get(url, HTTP_X_FORWARDED_PROTOCOL="https")246 self.assertEqual(resp.status_code, 302)247 self.assertEqual(resp['location'],248 'https://testserver:80%s' % redirect_url)249 # Restore settings250 settings.SECURE_PROXY_SSL_HEADER = None251class CustomPanelTests(BaseHorizonTests):252 """ Test customization of dashboards and panels253 using 'customization_module' to HORIZON_CONFIG.254 """255 def setUp(self):256 settings.HORIZON_CONFIG['customization_module'] = \257 'horizon.test.customization.cust_test1'258 # refresh config259 conf.HORIZON_CONFIG._setup()260 super(CustomPanelTests, self).setUp()261 def tearDown(self):262 # Restore dash263 cats = horizon.get_dashboard("cats")264 cats.name = "Cats"265 horizon.register(Dogs)266 self._discovered_dashboards.append(Dogs)267 Dogs.register(Puppies)268 Cats.register(Tigers)269 super(CustomPanelTests, self).tearDown()270 settings.HORIZON_CONFIG.pop('customization_module')271 # refresh config272 conf.HORIZON_CONFIG._setup()273 def test_customize_dashboard(self):274 cats = horizon.get_dashboard("cats")275 self.assertEqual(cats.name, "WildCats")276 self.assertQuerysetEqual(cats.get_panels(),277 ['<Panel: kittens>'])278 with self.assertRaises(base.NotRegistered):279 horizon.get_dashboard("dogs")280class CustomPermissionsTests(BaseHorizonTests):281 """ Test customization of permissions on panels282 using 'customization_module' to HORIZON_CONFIG.283 """284 def setUp(self):285 settings.HORIZON_CONFIG['customization_module'] = \286 'horizon.test.customization.cust_test2'287 # refresh config288 conf.HORIZON_CONFIG._setup()289 super(CustomPermissionsTests, self).setUp()290 def tearDown(self):291 # Restore permissions292 dogs = horizon.get_dashboard("dogs")293 puppies = dogs.get_panel("puppies")294 puppies.permissions = tuple([])295 super(CustomPermissionsTests, self).tearDown()296 settings.HORIZON_CONFIG.pop('customization_module')297 # refresh config298 conf.HORIZON_CONFIG._setup()299 def test_customized_permissions(self):300 dogs = horizon.get_dashboard("dogs")301 panel = dogs.get_panel('puppies')302 # Non-admin user303 self.assertQuerysetEqual(self.user.get_all_permissions(), [])304 resp = self.client.get(panel.get_absolute_url())305 self.assertEqual(resp.status_code, 302)306 resp = self.client.get(panel.get_absolute_url(),307 follow=False,308 HTTP_X_REQUESTED_WITH='XMLHttpRequest')309 self.assertEqual(resp.status_code, 401)310 # Test customized permissions for logged-in user311 resp = self.client.get(panel.get_absolute_url(), follow=True)312 self.assertEqual(resp.status_code, 200)313 self.assertTemplateUsed(resp, "auth/login.html")314 self.assertContains(resp, "Login as different user", 1, 200)...

Full Screen

Full Screen

base_tests.py

Source:base_tests.py Github

copy

Full Screen

...52 horizon.register(MyPanel)53 with self.assertRaises(ValueError):54 horizon.register("MyPanel")55 # Retrieval56 my_dash_instance_by_name = horizon.get_dashboard("mydash")57 self.assertTrue(isinstance(my_dash_instance_by_name, MyDash))58 my_dash_instance_by_class = horizon.get_dashboard(MyDash)59 self.assertEqual(my_dash_instance_by_name, my_dash_instance_by_class)60 with self.assertRaises(base.NotRegistered):61 horizon.get_dashboard("fake")62 self.assertQuerysetEqual(horizon.get_dashboards(),63 ['<Dashboard: Project>',64 '<Dashboard: Admin>',65 '<Dashboard: Settings>',66 '<Dashboard: My Dashboard>'])67 # Removal68 self.assertEqual(len(Horizon._registry), 4)69 horizon.unregister(MyDash)70 self.assertEqual(len(Horizon._registry), 3)71 with self.assertRaises(base.NotRegistered):72 horizon.get_dashboard(MyDash)73 def test_site(self):74 self.assertEqual(unicode(Horizon), "Horizon")75 self.assertEqual(repr(Horizon), "<Site: Horizon>")76 dash = Horizon.get_dashboard('nova')77 self.assertEqual(Horizon.get_default_dashboard(), dash)78 user = users.User()79 self.assertEqual(Horizon.get_user_home(user), dash.get_absolute_url())80 def test_dashboard(self):81 syspanel = horizon.get_dashboard("syspanel")82 self.assertEqual(syspanel._registered_with, Horizon)83 self.assertQuerysetEqual(syspanel.get_panels()['System Panel'],84 ['<Panel: Overview>',85 '<Panel: Instances>',86 '<Panel: Services>',87 '<Panel: Flavors>',88 '<Panel: Images>',89 '<Panel: Tenants>',90 '<Panel: Users>',91 '<Panel: Quotas>'])92 self.assertEqual(syspanel.get_absolute_url(), "/syspanel/")93 # Test registering a module with a dashboard that defines panels94 # as a dictionary.95 syspanel.register(MyPanel)96 self.assertQuerysetEqual(syspanel.get_panels()['Other'],97 ['<Panel: My Panel>'])98 # Test registering a module with a dashboard that defines panels99 # as a tuple.100 settings_dash = horizon.get_dashboard("settings")101 settings_dash.register(MyPanel)102 self.assertQuerysetEqual(settings_dash.get_panels(),103 ['<Panel: User Settings>',104 '<Panel: Tenant Settings>',105 '<Panel: My Panel>'])106 def test_panels(self):107 syspanel = horizon.get_dashboard("syspanel")108 instances = syspanel.get_panel("instances")109 self.assertEqual(instances._registered_with, syspanel)110 self.assertEqual(instances.get_absolute_url(), "/syspanel/instances/")111 def test_index_url_name(self):112 syspanel = horizon.get_dashboard("syspanel")113 instances = syspanel.get_panel("instances")114 instances.index_url_name = "does_not_exist"115 with self.assertRaises(NoReverseMatch):116 instances.get_absolute_url()117 instances.index_url_name = "index"118 self.assertEqual(instances.get_absolute_url(), "/syspanel/instances/")119 def test_lazy_urls(self):120 urlpatterns = horizon.urls[0]121 self.assertTrue(isinstance(urlpatterns, base.LazyURLPattern))122 # The following two methods simply should not raise any exceptions123 iter(urlpatterns)124 reversed(urlpatterns)125class HorizonBaseViewTests(test.BaseViewTests):126 def setUp(self):127 super(HorizonBaseViewTests, self).setUp()128 users.get_user_from_request = self._real_get_user_from_request129 def test_public(self):130 settings = horizon.get_dashboard("settings")131 # Known to have no restrictions on it other than being logged in.132 user_panel = settings.get_panel("user")133 url = user_panel.get_absolute_url()134 client = Client() # Get a clean, logged out client instance.135 client.logout()136 resp = client.get(url)...

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