How to use resource_status method in localstack

Best Python code snippet using localstack_python

resource_status.py

Source:resource_status.py Github

copy

Full Screen

1"""2********************************************************************************3* Name: resource_status.py4* Author: nswain5* Created On: September 24, 20186* Copyright: (c) Aquaveo 20187********************************************************************************8"""9from unittest import mock10from django.http import HttpResponseRedirect11from django.test import RequestFactory12from tethys_sdk.testing import TethysTestCase13from tethysext.atcore.tests.factories.django_user import UserFactory14from tethysext.atcore.controllers.app_users.resource_status import ResourceStatus15class ResourceStatusControllerTests(TethysTestCase):16 def setUp(self):17 self.controller = ResourceStatus.as_controller()18 self.resource_id = 'abc123'19 self.user = UserFactory()20 self.request_factory = RequestFactory()21 def tearDown(self):22 pass23 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.ResourceStatus._handle_get')24 def test_get(self, mock_handle_get):25 mock_request = self.request_factory.get('/foo/bar/status/')26 ret = self.controller(mock_request, back_url='/foo/bar')27 mock_handle_get.assert_called_with(mock_request, back_url='/foo/bar')28 self.assertEqual(mock_handle_get(), ret)29 @mock.patch('tethys_apps.decorators.has_permission', return_value=True)30 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.JobsTable')31 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.render')32 def test_handle_get_without_resource_id(self, mock_render, mock_JobsTable, _):33 mock_request = self.request_factory.get('/foo/bar/status/')34 mock_request.user = self.user35 mock_job1 = mock.MagicMock(extended_properties={})36 mock_job2 = mock.MagicMock(extended_properties={'resource_id': 'def456'})37 mock_job3 = mock.MagicMock(extended_properties={'resource_id': self.resource_id})38 all_jobs = [mock_job1, mock_job2, mock_job3]39 mock_app = mock.MagicMock()40 mock_app.get_job_manager().list_jobs.return_value = all_jobs41 controller = ResourceStatus.as_controller(_app=mock_app)42 ret = controller(mock_request, back_url='/foo/bar')43 mjt_call_args = mock_JobsTable.call_args_list44 self.assertEqual(all_jobs, mjt_call_args[0][1]['jobs'])45 mr_call_args = mock_render.call_args_list46 context = mr_call_args[0][0][2]47 self.assertEqual(mock_JobsTable(), context['jobs_table'])48 self.assertIsNone(context['resource_id'])49 self.assertIsNone(context['resource'])50 self.assertEqual(mock_render(), ret)51 @mock.patch('tethys_apps.decorators.has_permission', return_value=True)52 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.ResourceStatus.get_resource',53 return_value=mock.MagicMock())54 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.JobsTable')55 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.render')56 def test_handle_get_with_resource_id(self, mock_render, mock_jobs_table, _, __):57 mock_request = self.request_factory.get('/foo/bar/status/?r={}'.format(self.resource_id))58 mock_request.user = self.user59 mock_job1 = mock.MagicMock(extended_properties={})60 mock_job2 = mock.MagicMock(extended_properties={'resource_id': 'def456'})61 mock_job3 = mock.MagicMock(extended_properties={'resource_id': self.resource_id})62 all_jobs = [mock_job1, mock_job2, mock_job3]63 mock_app = mock.MagicMock()64 mock_app.get_job_manager().list_jobs.return_value = all_jobs65 controller = ResourceStatus.as_controller(_app=mock_app)66 ret = controller(mock_request, back_url='/foo/bar')67 mjt_call_args = mock_jobs_table.call_args_list68 self.assertEqual([mock_job3], mjt_call_args[0][1]['jobs'])69 mr_call_args = mock_render.call_args_list70 context = mr_call_args[0][0][2]71 self.assertEqual(mock_jobs_table(), context['jobs_table'])72 self.assertEqual(self.resource_id, context['resource_id'])73 self.assertIsNotNone(context['resource'])74 self.assertEqual(mock_render(), ret)75 @mock.patch('tethys_apps.decorators.has_permission', return_value=True)76 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.ResourceStatus.get_resource')77 def test_handle_get_resource_is_http(self, mock_get_resource, _):78 mock_request = self.request_factory.get('/foo/bar/status/?r={}'.format(self.resource_id))79 mock_request.user = self.user80 mock_app = mock.MagicMock()81 controller = ResourceStatus.as_controller(_app=mock_app)82 redirect_response = mock.MagicMock(spec=HttpResponseRedirect)83 mock_get_resource.return_value = redirect_response84 ret = controller(mock_request, back_url='/foo/bar')85 self.assertEqual(redirect_response, ret)86 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.reverse')87 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.get_active_app')88 def test_default_back_url(self, mock_ga, mock_reverse):89 resource_id = self.resource_id90 mock_request = self.request_factory.get('/foo/bar/status/?r={}'.format(self.resource_id))91 mock_app = mock.MagicMock()92 mock_ga().namespace = 'test_namespace'93 mock_reverse.return_value = 'test1'94 rs = ResourceStatus(_app=mock_app, back_url='/foo/bar')95 # call the method96 ret = rs.default_back_url(mock_request, resource_id=resource_id)97 # test the results98 self.assertEqual('test1', ret)99 ss = mock_reverse.call_args_list100 self.assertEqual('test_namespace:resources_manage_resources', ss[0][0][0])101 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.reverse')102 @mock.patch('tethysext.atcore.controllers.app_users.resource_status.get_active_app')103 def test_default_back_url_with_back_args(self, mock_ga, mock_reverse):104 resource_id = self.resource_id105 mock_request = mock.MagicMock()106 mock_request.GET.get.return_value = 'resource-details'107 mock_app = mock.MagicMock()108 mock_ga().namespace = 'test_namespace'109 mock_reverse.return_value = 'test1'110 rs = ResourceStatus(_app=mock_app, back_url='/foo/bar')111 # call the method112 ret = rs.default_back_url(mock_request, resource_id=resource_id)113 # test the results114 self.assertEqual('test1', ret)115 ss = mock_reverse.call_args_list116 self.assertEqual('test_namespace:resources_resource_details', ss[0][0][0])...

Full Screen

Full Screen

coffee_maker.py

Source:coffee_maker.py Github

copy

Full Screen

...69exit70"""71def list_coffees():72 print("%s, %s, %s" % (ESPRESSO, AMERICANO, CAPPUCCINO))73def resource_status():74 print("%s: %d%%" % (WATER, RESOURCES[WATER]))75 print("%s: %d%%" % (COFFEE, RESOURCES[COFFEE]))76 print("%s: %d%%" % (MILK, RESOURCES[MILK]))77def get_recipe(coffee_type):78 return RECIPES[coffee_type]79def get_coffee_type():80 print("Which coffee?")81 return sys.stdin.readline().strip()82def make(coffee_type):83 try:84 RECIPE = RECIPES[coffee_type]85 except KeyError as e:86 print("Invalid coffee name")87 return88 new_water_val = RESOURCES[WATER] - RECIPE[WATER]89 new_coffee_val = RESOURCES[COFFEE] - RECIPE[COFFEE]90 new_milk_val = RESOURCES[MILK] - RECIPE[MILK]91 if new_water_val < 0 or new_coffee_val < 0 or new_milk_val < 0:92 print("Not enough resources to make ", coffee_type)93 return94 RESOURCES[WATER] = new_water_val95 RESOURCES[COFFEE] = new_coffee_val96 RESOURCES[MILK] = new_milk_val97 print("Here's your %s!" % (coffee_type))98def get_resource_type():99 print("Which resource? Type 'all' for refilling everything")100 return sys.stdin.readline().strip()101def refill(resource_type):102 if resource_type == "all":103 RESOURCES[WATER] = 100104 RESOURCES[COFFEE] = 100105 RESOURCES[MILK] = 100106 elif resource_type == WATER:107 RESOURCES[WATER] = 100108 elif resource_type == MILK:109 RESOURCES[MILK] = 100110 elif resource_type == COFFEE:111 RESOURCES[COFFEE] = 100 112def help():113 print("List of possible commands:")114 for command in commands:115 print(command)116if __name__ == "__main__":117 command = ""118 print("I'm a smart coffee maker")119 while not command == EXIT:120 print("Enter command:")121 command = sys.stdin.readline().strip()122 if command == LIST_COFFEES:123 list_coffees()124 elif command == RESOURCE_STATUS:125 resource_status()126 elif command == MAKE_COFFEE:127 coffee_type = get_coffee_type()128 make(coffee_type)129 elif command == REFILL:130 resource_type = get_resource_type()131 refill(resource_type)132 resource_status()133 elif command == HELP:...

Full Screen

Full Screen

status_info.py

Source:status_info.py Github

copy

Full Screen

...36 :rtype: StatusInfo37 """38 return util.deserialize_model(dikt, cls)39 @property40 def resource_status(self):41 """Gets the resource_status of this StatusInfo.42 :return: The resource_status of this StatusInfo.43 :rtype: ResourceStatus44 """45 return self._resource_status46 @resource_status.setter47 def resource_status(self, resource_status):48 """Sets the resource_status of this StatusInfo.49 :param resource_status: The resource_status of this StatusInfo.50 :type resource_status: ResourceStatus51 """52 if resource_status is None:53 raise ValueError("Invalid value for `resource_status`, must not be `None`") # noqa: E50154 self._resource_status = resource_status55 @property56 def cause(self):57 """Gets the cause of this StatusInfo.58 :return: The cause of this StatusInfo.59 :rtype: Cause60 """61 return self._cause...

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