Best Python code snippet using responses
test_dcc_utilities.py
Source:test_dcc_utilities.py
1# -*- coding: utf-8 -*-2# ----------------------------------------------------------------------------#3# Copyright © 2015-2016 VMware, Inc. All Rights Reserved. #4# #5# Licensed under the BSD 2-Clause License (the âLicenseâ); you may not use #6# this file except in compliance with the License. #7# #8# The BSD 2-Clause License #9# #10# Redistribution and use in source and binary forms, with or without #11# modification, are permitted provided that the following conditions are met:#12# #13# - Redistributions of source code must retain the above copyright notice, #14# this list of conditions and the following disclaimer. #15# #16# - Redistributions in binary form must reproduce the above copyright #17# notice, this list of conditions and the following disclaimer in the #18# documentation and/or other materials provided with the distribution. #19# #20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"#21# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE #22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE #23# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE #24# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR #25# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF #26# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS #27# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN #28# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) #29# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF #30# THE POSSIBILITY OF SUCH DAMAGE. #31# ----------------------------------------------------------------------------#32import unittest33import mock34import pint35from liota.dccs.aws_iot import AWSIoT36from liota.entities.devices.simulated_device import SimulatedDevice37from liota.entities.edge_systems.dell5k_edge_system import Dell5KEdgeSystem38from liota.entities.metrics.metric import Metric39from liota.lib.utilities.dcc_utility import *40from liota.lib.utilities.si_unit import parse_unit, UnsupportedUnitError41from liota.lib.utilities.utility import getUTCmillis42# Sampling function43def sampling_function():44 pass45def raise_exception(*args, **kwargs):46 """47 Method to raise the UnsupportedUnitError48 :return: None 49 """50 raise UnsupportedUnitError("UnsupportedUnitError")51# Create a pint unit registry52ureg = pint.UnitRegistry()53def validate_json(obj):54 """55 Method to sort the provided json and returns back the sorted list representation of the json.56 :param obj: json object57 :return: sorted list of json58 """59 if isinstance(obj, dict):60 return sorted((k, validate_json(v)) for k, v in obj.items())61 if isinstance(obj, list):62 return sorted(validate_json(x) for x in obj)63 else:64 return obj65class DCCUtilityTest(unittest.TestCase):66 """67 Unit test cases for DCC Utility global functions68 """69 def setUp(self):70 """71 Setup all required parameters required during the tests72 :return: None73 """74 # EdgeSystem name75 self.edge_system = Dell5KEdgeSystem("TestEdgeSystem")76 # Mocking the DataCenterComponent init method77 with mock.patch("liota.dccs.aws_iot.DataCenterComponent.__init__") as mocked_dcc:78 self.aws = AWSIoT("Mocked DCC", enclose_metadata=True)79 def tearDown(self):80 """81 Clean up all parameters used in test cases82 :return: None83 """84 self.edge_system = Dell5KEdgeSystem("TestEdgeSystem")85 self.aws = None86 def test_implementation_get_formatted_data_no_data(self):87 """88 Test case to check the implementation of _format_data for empty metric data.89 :return: None90 """91 # Mocking the DataCenterComponent init method92 with mock.patch("liota.dccs.aws_iot.DataCenterComponent.__init__") as mocked_dcc:93 self.aws = AWSIoT("Mocked DCC", enclose_metadata=False)94 # Register the edge95 registered_entity = self.aws.register(self.edge_system)96 # Creating test Metric97 test_metric = Metric(98 name="Test_Metric",99 unit=None,100 interval=10,101 aggregation_size=2,102 sampling_function=sampling_function103 )104 registered_metric = self.aws.register(test_metric)105 # Creating the parent-child relationship106 self.aws.create_relationship(registered_entity, registered_metric)107 # Getting the parent child relationship array from registered metric108 # formatted_data = self.aws._format_data(registered_metric)109 formatted_data = get_formatted_data(registered_metric, False)110 # Check two dicts are equal or not111 self.assertEqual(None, formatted_data, "Check implementation of get_formatted_data")112 def test_implementation_get_formatted_data_with_enclose_metadata(self):113 """114 Test case to check the implementation of get_formatted_data method with enclose_metadata option of AWSIoT class.115 RegisteredEdgeSystem->RegisteredMetric116 :return: None117 """118 # Register the edge119 registered_entity = self.aws.register(self.edge_system)120 # Creating test Metric121 test_metric = Metric(122 name="Test_Metric",123 unit=None,124 interval=10,125 aggregation_size=2,126 sampling_function=sampling_function127 )128 registered_metric = self.aws.register(test_metric)129 # Creating the parent-child relationship130 self.aws.create_relationship(registered_entity, registered_metric)131 timestamp = getUTCmillis()132 registered_metric.values.put((timestamp, 10))133 expected_output = {134 "edge_system_name": registered_entity.ref_entity.name,135 "metric_name": registered_metric.ref_entity.name,136 "metric_data": [{137 "value": 10,138 "timestamp": timestamp139 }],140 "unit": "null"141 }142 # Getting the parent child relationship array from registered metric143 formatted_data = get_formatted_data(registered_metric, True)144 formatted_json_data = json.loads(formatted_data)145 # Check two dicts are equal or not146 self.assertEqual(validate_json(formatted_json_data) == validate_json(expected_output), True,147 "Check implementation of get_formatted_data")148 def test_implementation_get_formatted_data_without_enclose_metatadata(self):149 """150 Test case to check the output given by get_formatted_data method without enclosed meta_data option.151 RegisteredEdgeSystem->RegisteredMetric152 :return: None153 """154 # Mocking the DataCenterComponent init method155 with mock.patch("liota.dccs.aws_iot.DataCenterComponent.__init__") as mocked_dcc:156 self.aws = AWSIoT("Mocked DCC", enclose_metadata=False)157 # Register the edge158 registered_entity = self.aws.register(self.edge_system)159 # Creating test Metric160 test_metric = Metric(161 name="Test_Metric",162 unit=None,163 interval=10,164 aggregation_size=2,165 sampling_function=sampling_function166 )167 registered_metric = self.aws.register(test_metric)168 # Creating the parent-child relationship169 self.aws.create_relationship(registered_entity, registered_metric)170 # Get current timestamp171 timestamp = getUTCmillis()172 registered_metric.values.put((timestamp, 10))173 # Expected output without enclosed metadata174 expected_output = {175 "metric_name": registered_metric.ref_entity.name,176 "metric_data": [{177 "value": 10,178 "timestamp": timestamp179 }],180 "unit": "null"181 }182 # Getting the parent child relationship array from registered metric183 formatted_data = get_formatted_data(registered_metric, False)184 # Convert json string to dict for the comparision185 formatted_json_data = json.loads(formatted_data)186 # Check two dicts are equal or not187 self.assertEqual(validate_json(formatted_json_data) == validate_json(expected_output), True,188 "Check implementation of get_formatted_data")189 def test_implementation_get_formatted_data_with_enclose_metadata_device(self):190 """191 Test case to test the implementation of get_formatted_data method with enclose_metadata option.192 RegisteredEdgeSystem->RegisteredDevice->RegisteredMetric193 :return: None194 """195 # Register the edge196 registered_entity = self.aws.register(self.edge_system)197 # Creating Simulated Device198 test_sensor = SimulatedDevice("TestSensor")199 # Registering Device and creating Parent-Child relationship200 reg_test_sensor = self.aws.register(test_sensor)201 self.aws.create_relationship(registered_entity, reg_test_sensor)202 # Creating test Metric203 test_metric = Metric(204 name="Test_Metric",205 unit=ureg.degC,206 interval=10,207 aggregation_size=2,208 sampling_function=sampling_function209 )210 registered_metric = self.aws.register(test_metric)211 # Creating the parent-child relationship212 self.aws.create_relationship(reg_test_sensor, registered_metric)213 # Get current timestamp214 timestamp = getUTCmillis()215 registered_metric.values.put((timestamp, 10))216 # Expected output without enclosed metadata217 expected_output = {218 "edge_system_name": registered_entity.ref_entity.name,219 "metric_name": registered_metric.ref_entity.name,220 "device_name": reg_test_sensor.ref_entity.name,221 "metric_data": [{222 "value": 10,223 "timestamp": timestamp224 }],225 "unit": "null"226 }227 unit_tuple = parse_unit(ureg.degC)228 if unit_tuple[0] is None:229 # Base and Derived Units230 expected_output['unit'] = unit_tuple[1]231 else:232 # Prefixed or non-SI Units233 expected_output['unit'] = unit_tuple[0] + unit_tuple[1]234 # Getting the parent child relationship array from registered metric235 formatted_data = get_formatted_data(registered_metric, True)236 # Convert json string to dict for the comparision237 formatted_json_data = json.loads(formatted_data)238 # Check two dicts are equal or not239 self.assertEqual(validate_json(formatted_json_data) == validate_json(expected_output), True,240 "Check implementation of get_formatted_data")241 def test_implementation_get_formatted_data_with_enclose_metadata_device_exception_flow(self):242 """243 Test case to test the implementation of get_formatted_data method with enclose_metadata option.244 RegisteredEdgeSystem->RegisteredDevice->RegisteredMetric245 :return: None246 """247 # Mock the get_formatted_data248 with mock.patch("liota.lib.utilities.dcc_utility.parse_unit") as mocked_parse_unit:249 # Method to be invoked on calling the parse_unit function250 mocked_parse_unit.side_effect = raise_exception251 # Register the edge252 registered_entity = self.aws.register(self.edge_system)253 # Creating Simulated Device254 test_sensor = SimulatedDevice("TestSensor")255 # Registering Device and creating Parent-Child relationship256 reg_test_sensor = self.aws.register(test_sensor)257 self.aws.create_relationship(registered_entity, reg_test_sensor)258 # Creating test Metric259 test_metric = Metric(260 name="Test_Metric",261 unit=ureg.degC,262 interval=10,263 aggregation_size=2,264 sampling_function=sampling_function265 )266 registered_metric = self.aws.register(test_metric)267 # Creating the parent-child relationship268 self.aws.create_relationship(reg_test_sensor, registered_metric)269 # Get current timestamp270 timestamp = getUTCmillis()271 registered_metric.values.put((timestamp, 10))272 # Expected output without enclosed metadata273 expected_output = {274 "edge_system_name": registered_entity.ref_entity.name,275 "metric_name": registered_metric.ref_entity.name,276 "device_name": reg_test_sensor.ref_entity.name,277 "metric_data": [{278 "value": 10,279 "timestamp": timestamp280 }],281 "unit": "null"282 }283 # Getting the parent child relationship array from registered metric284 formatted_data = get_formatted_data(registered_metric, True)285 # Convert json string to dict for the comparision286 formatted_json_data = json.loads(formatted_data)287 # Check two dicts are equal or not288 self.assertEqual(validate_json(formatted_json_data) == validate_json(expected_output), True,289 "Check implementation of get_formatted_data")290 def test_validation_get_entity_hierarchy(self):291 """292 Test case to check the validation of _get_entity_hierarchy method for Metric object.293 :return: None294 """295 # Creating test Metric296 test_metric = Metric(297 name="Test_Metric",298 unit=None,299 interval=10,300 aggregation_size=2,301 sampling_function=sampling_function302 )303 # Checking whether implementation raising the TypeError for invalid input304 with self.assertRaises(TypeError):305 get_entity_hierarchy(test_metric)306 def test_implementation_get_entity_hierarchy(self):307 """308 Test case to check get_entity_entity_hierarchy() for RegisteredEdgeSystem->RegisteredMetric309 :return: None310 """311 # Register the edge312 registered_entity = self.aws.register(self.edge_system)313 # Creating test Metric314 test_metric = Metric(315 name="Test_Metric",316 unit=None,317 interval=10,318 aggregation_size=2,319 sampling_function=sampling_function320 )321 registered_metric = self.aws.register(test_metric)322 # Creating the parent-child relationship323 self.aws.create_relationship(registered_entity, registered_metric)324 # Getting the parent child relationship array from registered metric325 entity_hierarchy = get_entity_hierarchy(registered_metric)326 self.assertSequenceEqual([registered_entity.ref_entity.name, registered_metric.ref_entity.name],327 entity_hierarchy, "Check the implementation of _get_entity_hierarchy for "328 "RegisteredEdgeSystem->RegisteredMetric")329 def test_implementation_get_entity_hierarchy_device_metric(self):330 """331 Test case to check get_entity_entity_hierarchy() for RegisteredEdgeSystem->RegisteredDevice->RegisteredMetric332 :return: None333 """334 # Register the edge335 registered_entity = self.aws.register(self.edge_system)336 # Creating Simulated Device337 test_sensor = SimulatedDevice("TestSensor")338 # Registering Device and creating Parent-Child relationship339 reg_test_sensor = self.aws.register(test_sensor)340 self.aws.create_relationship(registered_entity, reg_test_sensor)341 # Creating test Metric342 test_metric = Metric(343 name="Test_Metric",344 unit=ureg.degC,345 interval=10,346 aggregation_size=2,347 sampling_function=sampling_function348 )349 registered_metric = self.aws.register(test_metric)350 # Creating the parent-child relationship351 self.aws.create_relationship(reg_test_sensor, registered_metric)352 # Getting the parent child relationship array from registered metric353 entity_hierarchy = get_entity_hierarchy(registered_metric)354 self.assertSequenceEqual([registered_entity.ref_entity.name, reg_test_sensor.ref_entity.name,355 registered_metric.ref_entity.name], entity_hierarchy,356 "Check the implementation of _get_entity_hierarchy for "357 "RegisteredEdgeSystem->RegisteredDevice->RegisteredMetric")358if __name__ == '__main__':...
map_plots_top_left_v1.py
Source:map_plots_top_left_v1.py
1from calc_coords import *2plot_data = {"row1_plots": [3 {"plotNumber": 100002, "height": feet_inch_to_m(4 5, 9), "registeredName": "Kidd"},5 {"plotNumber": 100003, "height": feet_inch_to_m(6 12, 10), "registeredName": "Whisker"},7 {"plotNumber": 100004, "height": feet_inch_to_m(8 6, 3), "registeredName": "Stanley"},9 {"plotNumber": 100005, "height": feet_inch_to_m(10 5), "registeredName": "Wilson"},11 {"plotNumber": 100006, "height": feet_inch_to_m(12 7), "registeredName": "Allom"},13 {"plotNumber": 100007, "height": feet_inch_to_m(14 3), "registeredName": "Wills"},15 {"plotNumber": 100008, "height": feet_inch_to_m(16 8, 9), "registeredName": "Clayton"},17 {"plotNumber": 100009, "height": feet_inch_to_m(18 9), "registeredName": "Jones"},19 {"plotNumber": 100010, "height": feet_inch_to_m(20 7, 6), "registeredName": "Shipherd"},21 {"plotNumber": 100011, "height": feet_inch_to_m(22 6, 6), "registeredName": "Phillipson"},23 # height on map is ambiguous ^ ð¤¨24 {"plotNumber": 100012, "height": feet_inch_to_m(25 4, 6), "registeredName": "Cook"},26 {"plotNumber": 100013, "height": feet_inch_to_m(27 9), "registeredName": "McQuillen"},28 # padding between two plots (i.e. empty space) ð29 {"height": feet_inch_to_m(3)},30 {"plotNumber": 100014, "height": feet_inch_to_m(31 7), "registeredName": "Palmer"},32 {"plotNumber": 100015, "height": feet_inch_to_m(33 4), "registeredName": "Bassett"},34 {"plotNumber": 100016, "height": feet_inch_to_m(35 12), "registeredName": "Banks"},36 {"plotNumber": 100017, "height": feet_inch_to_m(37 3), "registeredName": "G.U."},38 # ambiguous name ^39 {"plotNumber": 100018, "height": feet_inch_to_m(40 4), "registeredName": "Burnette"},41 {"height": feet_inch_to_m(3, 9)},42 {"plotNumber": 100019, "height": feet_inch_to_m(43 4), "registeredName": "Cromby"},44 {"plotNumber": 100020, "height": feet_inch_to_m(45 8), "registeredName": "Heywood"},46 {"plotNumber": 100021, "height": feet_inch_to_m(47 8), "registeredName": "Buchanan"},48 {"plotNumber": 100022, "height": feet_inch_to_m(49 8, 6), "registeredName": "Harrop"},50 {"plotNumber": 100023, "height": feet_inch_to_m(51 9, 9), "registeredName": "Hesketh"},52 {"plotNumber": 100024, "height": feet_inch_to_m(53 5), "registeredName": "Coster"},54 {"plotNumber": 100025, "height": feet_inch_to_m(55 9), "registeredName": "Serle"},56 {"height": feet_inch_to_m(9/10)},57 {"plotNumber": 100026, "height": feet_inch_to_m(58 9), "registeredName": "W.Horn"},59],60 "row2_plots": [61 {"plotNumber": 100027, "height": feet_inch_to_m(62 7), "registeredName": "Mucklestone"},63 {"plotNumber": 100028, "height": feet_inch_to_m(64 9), "registeredName": "Crisp"},65 {"plotNumber": 100029, "height": feet_inch_to_m(66 9), "registeredName": "Railey"},67 {"plotNumber": 100030, "height": feet_inch_to_m(68 7), "registeredName": "Alderton"},69 {"plotNumber": 100031, "height": feet_inch_to_m(70 9), "registeredName": "Holmes"},71 {"plotNumber": 100032, "height": feet_inch_to_m(72 9), "registeredName": "Barnett"},73 {"plotNumber": 100033, "height": feet_inch_to_m(74 4, 6), "registeredName": "Charles"},75 {"height": feet_inch_to_m(2, 5)},76 {"plotNumber": 100034, "height": feet_inch_to_m(77 8), "registeredName": "Osborne"},78 {"plotNumber": 100035, "height": feet_inch_to_m(79 9), "registeredName": "Clark"},80 {"plotNumber": 100036, "height": feet_inch_to_m(81 8, 9), "registeredName": "Archer"},82 {"plotNumber": 100037, "height": feet_inch_to_m(83 4, 6), "registeredName": "Richardson"},84 {"plotNumber": 100038, "height": feet_inch_to_m(85 4, 6), "registeredName": "Heard"},86 {"plotNumber": 100039, "height": feet_inch_to_m(87 9), "registeredName": "Edwards"},88 {"plotNumber": 100040, "height": feet_inch_to_m(89 9), "registeredName": "Garland"},90 {"plotNumber": 100041, "height": feet_inch_to_m(91 9), "registeredName": "Jones"},92 {"plotNumber": 100042, "height": feet_inch_to_m(93 11), "registeredName": "McGuire"},94 {"plotNumber": 100043, "height": feet_inch_to_m(95 11), "registeredName": "Aickin"},96 {"plotNumber": 100044, "height": feet_inch_to_m(97 6), "registeredName": "Yonge"},98 {"plotNumber": 100045, "height": feet_inch_to_m(99 13), "registeredName": "S. Hesketh"},100],101 "row3_plots": [102 {"plotNumber": 100046, "height": feet_inch_to_m(103 8, 3), "registeredName": "Margan"},104 {"plotNumber": 100047, "height": feet_inch_to_m(105 13, 3), "registeredName": "Edgerley"},106 {"plotNumber": 100048, "height": feet_inch_to_m(107 9, 6), "registeredName": "Roberts"},108 {"plotNumber": 100049, "height": feet_inch_to_m(109 9, 9), "registeredName": "Maxwell"},110 {"plotNumber": 100050, "height": feet_inch_to_m(111 9), "registeredName": "Whisker"},112 {"plotNumber": 100051, "height": feet_inch_to_m(113 9), "registeredName": "Lennard"},114 {"plotNumber": 100052, "height": feet_inch_to_m(115 6), "registeredName": "Bassett"},116 {"plotNumber": 100053, "height": feet_inch_to_m(117 4, 6), "registeredName": "Price"},118 {"plotNumber": 100054, "height": feet_inch_to_m(119 10), "registeredName": "Knight"},120 {"plotNumber": 100055, "height": feet_inch_to_m(121 9), "registeredName": "Bruce"},122 {"plotNumber": 100056, "height": feet_inch_to_m(123 9), "registeredName": "J.Smith"},124 {"plotNumber": 100057, "height": feet_inch_to_m(125 6, 3), "registeredName": "Cook"},126 {"plotNumber": 100058, "height": feet_inch_to_m(127 9), "registeredName": "Worden"},128 {"plotNumber": 100059, "height": feet_inch_to_m(129 8), "registeredName": "Barnsley"},130 {"plotNumber": 100060, "height": feet_inch_to_m(131 6, 3), "registeredName": "Crowhurst"},132 {"plotNumber": 100061, "height": feet_inch_to_m(133 6, 3), "registeredName": "G.S. Wood"},134 {"plotNumber": 100062, "height": feet_inch_to_m(135 5), "registeredName": "Carson"},136],137 "row4_plots": [138 {"plotNumber": 100063, "height": feet_inch_to_m(139 4, 6), "registeredName": "Redmand"},140 {"plotNumber": 100064, "height": feet_inch_to_m(141 7, 9), "registeredName": "J. Williams"},142 {"plotNumber": 100065, "height": feet_inch_to_m(143 8, 3), "registeredName": "Prill"}, # ambiguous width144 {"plotNumber": 100066, "height": feet_inch_to_m(145 9), "registeredName": "Pickmere"},146 {"plotNumber": 100067, "height": feet_inch_to_m(147 4, 6), "registeredName": "King"},148 {"plotNumber": 100068, "height": feet_inch_to_m(149 4, 6), "registeredName": "Lord"},150 {"plotNumber": 100069, "height": feet_inch_to_m(151 9, 9), "registeredName": "Graham"},152 {"plotNumber": 100070, "height": feet_inch_to_m(153 9, 6), "registeredName": "Patterson"},154 {"height": 0.3},155 {"plotNumber": 100071, "height": feet_inch_to_m(156 8), "registeredName": "Russell"},157 {"plotNumber": 100072, "height": feet_inch_to_m(158 10), "registeredName": "Larkins"},159 {"plotNumber": 100073, "height": feet_inch_to_m(160 9, 6), "registeredName": "Browning"},161 {"plotNumber": 100074, "height": feet_inch_to_m(162 9), "registeredName": "Reach"},163 {"plotNumber": 100075, "height": feet_inch_to_m(164 4, 6), "registeredName": "Potter"},165],166 "row5_plots": [167 {"plotNumber": 100076, "height": feet_inch_to_m(168 9), "registeredName": "Hamlin"},169 {"plotNumber": 100077, "height": feet_inch_to_m(170 9), "registeredName": "Tye"},171 {"plotNumber": 100078, "height": feet_inch_to_m(172 9), "registeredName": "Bishop"},173 {"height": 0.26},174 {"plotNumber": 100079, "height": feet_inch_to_m(175 9), "registeredName": "Austin"},176 {"plotNumber": 100080, "height": feet_inch_to_m(177 10), "registeredName": "Reeves"},178 {"plotNumber": 100081, "height": feet_inch_to_m(179 7), "registeredName": "Kinder"}, # ambiguous width180 {"plotNumber": 100082, "height": feet_inch_to_m(181 6, 6), "registeredName": "Box"}, # ambiguous width and height182]...
models.py
Source:models.py
1from utils import *2from google.appengine.ext import webapp, db3REQUEST_CODE_USEREVENT = 04REQUEST_STATUS_USEREVENT = 15REGISTER_USEREVENT = 26CODEFAILED_USEREVENT = 37DOWNLOAD_USEREVENT = 48class UserEvent(db.Expando):9 date = db.DateTimeProperty(auto_now_add=True)10 ev_type = db.IntegerProperty(required=True, indexed=True)11 requester = db.StringProperty(required=True, indexed=True)12def spawn_event(hdlr, ev_type, **kwargs):13 return UserEvent(ev_type=ev_type, requester=hdlr.request.remote_addr, **kwargs)14# define state machine constants15NOTHING_REGISTERED_STATE = 016DEVICE_REGISTERED_STATE = 117SERVER_REGISTERED_STATE = 218BOTH_REGISTERED_STATE = 319DEVICE_REGISTERED_EVENT = 020SERVER_REGISTERED_EVENT = 121class DeviceRegistration(db.Model):22 code = db.StringProperty()23 state = db.IntegerProperty(default = NOTHING_REGISTERED_STATE)24 date = db.DateTimeProperty(auto_now_add=True)25 server = db.StringProperty(default = "UNKNOWN")26 @classmethod27 def for_code(klass, code_str):28 codes = DeviceRegistration.gql("WHERE code = :1", code_str)29 if(codes.count() != 1):30 raise HTTPException(404)31 return codes[0]32 def update_state(self, new_event):33 table = {34 NOTHING_REGISTERED_STATE: {35 DEVICE_REGISTERED_EVENT: DEVICE_REGISTERED_STATE,36 SERVER_REGISTERED_EVENT: BOTH_REGISTERED_STATE },37 DEVICE_REGISTERED_STATE: {38 DEVICE_REGISTERED_EVENT: DEVICE_REGISTERED_STATE,39 SERVER_REGISTERED_EVENT: BOTH_REGISTERED_STATE },40 SERVER_REGISTERED_STATE: {41 DEVICE_REGISTERED_EVENT: BOTH_REGISTERED_STATE,42 SERVER_REGISTERED_EVENT: SERVER_REGISTERED_STATE },43 BOTH_REGISTERED_STATE: {44 DEVICE_REGISTERED_EVENT: BOTH_REGISTERED_STATE,45 SERVER_REGISTERED_EVENT: BOTH_REGISTERED_STATE } }46 47 self.state = table[self.state][new_event]48 return self.state49 50 def state_str(self):51 if(self.state == NOTHING_REGISTERED_STATE):52 return "NOTHING_REGISTERED"53 elif(self.state == DEVICE_REGISTERED_STATE):54 return "DEVICE_REGISTERED"55 elif(self.state == SERVER_REGISTERED_STATE):56 return "SERVER_REGISTERED"57 elif(self.state == BOTH_REGISTERED_STATE):58 return "BOTH_REGISTERED"59 60class RegistrationStats(db.Model):61 date = db.DateTimeProperty(auto_now_add=True, indexed=True)62 finished_count = db.IntegerProperty(indexed=False)63 device_count = db.IntegerProperty(indexed=False)64 created_count = db.IntegerProperty(indexed=False)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!