Best Python code snippet using slash
views.py
Source:views.py
1from django.http import JsonResponse2from django.shortcuts import render3from dashboard.models import Order4from django.core import serializers5import getpass6import telnetlib, os, re7from django.views.decorators.csrf import csrf_exempt8HOST = "192.168.1.66"9PORT = 2310telnet = telnetlib.Telnet()11telnetWorking = False12print("Setup done")13try:14 telnet.open(HOST)15 telnetWorking = True16except:17 print("Telnet failed")18 print(telnetWorking) 19def dashboard_with_pivot(request):20 return render(request, 'dashboard_floorplan.html', {})21def dashboard_floorplan(request):22 return render(request, 'dashboard_floorplan.html', {})23def pivot_data(request):24 dataset = Order.objects.all()25 data = serializers.serialize('json', dataset)26 return JsonResponse(data, safe=False)27@csrf_exempt 28def row_1_to_4_turn_on(request):29 #run telnet command30 print("Turn on for row 1 to 4")31 data = {'is_complete' : True}32 print(telnetWorking)33 if telnetWorking:34 telnet.write(('P 1 12\r\n').encode('ascii'))35 data = {'is_complete' : True}36 else:37 data = {'is_complete' : False}38 return JsonResponse(data)39@csrf_exempt 40def row_1_to_4_turn_off(request):41 #run telnet command42 print("Turn off for row 1 to 4")43 data = {'is_complete' : True}44 if telnetWorking:45 telnet.write(('P 4 12\r\n').encode('ascii'))46 data = {'is_complete' : True}47 else:48 data = {'is_complete' : False}49 50 return JsonResponse(data)51@csrf_exempt 52def row_5_to_6_turn_on(request):53 #run telnet command54 print("Turn on for row 5 to 6")55 data = {'is_complete' : True}56 if telnetWorking:57 telnet.write(('P 1 13\r\n').encode('ascii'))58 data = {'is_complete' : True}59 else:60 data = {'is_complete' : False}61 return JsonResponse(data)62@csrf_exempt 63def row_5_to_6_turn_off(request):64 #run telnet command65 print("Turn off for row 5 to 6")66 data = {'is_complete' : True}67 if telnetWorking:68 telnet.write(('P 4 13\r\n').encode('ascii'))69 data = {'is_complete' : True}70 else:71 data = {'is_complete' : False}72 return JsonResponse(data)73@csrf_exempt 74def downlights_turn_on(request):75 #run telnet command76 print("Turn on downlights")77 data = {'is_complete' : True}78 if telnetWorking:79 telnet.write(('P 1 14\r\n').encode('ascii'))80 data = {'is_complete' : True}81 else:82 data = {'is_complete' : False}83 return JsonResponse(data)84@csrf_exempt 85def downlights_turn_off(request):86 #run telnet command87 print("Turn off downlights")88 data = {'is_complete' : True}89 if telnetWorking:90 telnet.write(('P 4 14\r\n').encode('ascii'))91 data = {'is_complete' : True}92 else:93 data = {'is_complete' : False}94 return JsonResponse(data)95@csrf_exempt 96def blueWallLed_turn_on(request):97 #run telnet command98 print("Turn on blueWallLed")99 data = {'is_complete' : True}100 if telnetWorking:101 telnet.write(('P 1 15\r\n').encode('ascii'))102 data = {'is_complete' : True}103 else:104 data = {'is_complete' : False}105 return JsonResponse(data)106@csrf_exempt 107def blueWallLed_turn_off(request):108 #run telnet command109 print("Turn off blueWallLed")110 data = {'is_complete' : True}111 if telnetWorking:112 telnet.write(('P 4 15\r\n').encode('ascii'))113 data = {'is_complete' : True}114 else:115 data = {'is_complete' : False}116 return JsonResponse(data)117@csrf_exempt 118def lightShow_turn_on(request):119 #run telnet command120 print("Turn on Light Show")121 data = {'is_complete' : True}122 if telnetWorking:123 telnet.write(('P 1 17\r\n').encode('ascii'))124 data = {'is_complete' : True}125 else:126 data = {'is_complete' : False}127 return JsonResponse(data)128@csrf_exempt 129def lightShow_turn_off(request):130 #run telnet command131 print("Turn off Light Show")132 data = {'is_complete' : True}133 if telnetWorking:134 telnet.write(('P 12 17\r\n').encode('ascii'))135 data = {'is_complete' : True}136 else:137 data = {'is_complete' : False}138 return JsonResponse(data)139@csrf_exempt 140def ledColorRed(request):141 #run telnet command142 print("Red")143 data = {'is_complete' : True}144 if telnetWorking:145 telnet.write(('P 1 16\r\n').encode('ascii'))146 data = {'is_complete' : True}147 else:148 data = {'is_complete' : False}149 return JsonResponse(data)150@csrf_exempt 151def ledColorGreen(request):152 #run telnet command153 print("Green")154 data = {'is_complete' : True}155 if telnetWorking:156 telnet.write(('P 2 16\r\n').encode('ascii'))157 data = {'is_complete' : True}158 else:159 data = {'is_complete' : False}160 return JsonResponse(data)161 162 163@csrf_exempt 164def ledColorBlue(request):165 #run telnet command166 print("Blue")167 data = {'is_complete' : True}168 if telnetWorking:169 telnet.write(('P 3 16\r\n').encode('ascii'))170 data = {'is_complete' : True}171 else:172 data = {'is_complete' : False}173 return JsonResponse(data)174@csrf_exempt 175def ledColorPink(request):176 #run telnet command177 print("Pink")178 data = {'is_complete' : True}179 if telnetWorking:180 telnet.write(('P 5 16\r\n').encode('ascii'))181 data = {'is_complete' : True}182 else:183 data = {'is_complete' : False}184 return JsonResponse(data)185@csrf_exempt 186def ledColorCyan(request):187 #run telnet command188 print("Cyan")189 data = {'is_complete' : True}190 if telnetWorking:191 telnet.write(('P 6 16\r\n').encode('ascii'))192 data = {'is_complete' : True}193 else:194 data = {'is_complete' : False}195 return JsonResponse(data)196@csrf_exempt 197def ledColorYellow(request):198 #run telnet command199 print("Yellow")200 data = {'is_complete' : True}201 if telnetWorking:202 telnet.write(('P 7 16\r\n').encode('ascii'))203 data = {'is_complete' : True}204 else:205 data = {'is_complete' : False}206 return JsonResponse(data)207@csrf_exempt 208def ledColorPurple(request):209 #run telnet command210 print("Purple")211 data = {'is_complete' : True}212 if telnetWorking:213 telnet.write(('P 8 16\r\n').encode('ascii'))214 data = {'is_complete' : True}215 else:216 data = {'is_complete' : False}217 return JsonResponse(data)218@csrf_exempt 219def ledColorWhite(request):220 #run telnet command221 print("White")222 data = {'is_complete' : True}223 if telnetWorking:224 telnet.write(('P 9 16\r\n').encode('ascii'))225 data = {'is_complete' : True}226 else:227 data = {'is_complete' : False}...
login_batch_query.py
Source:login_batch_query.py
...51 :type: list[str]52 """53 self._username_list = username_list54 @property55 def is_complete(self):56 """Gets the is_complete of this LoginBatchQuery. # noqa: E50157 :return: The is_complete of this LoginBatchQuery. # noqa: E50158 :rtype: bool59 """60 return self._is_complete61 @is_complete.setter62 def is_complete(self, is_complete):63 """Sets the is_complete of this LoginBatchQuery.64 :param is_complete: The is_complete of this LoginBatchQuery. # noqa: E50165 :type: bool66 """67 self._is_complete = is_complete68 def to_dict(self):69 """Returns the model properties as a dict"""70 result = {}71 for attr, _ in six.iteritems(self.swagger_types):72 value = getattr(self, attr)73 if isinstance(value, list):74 result[attr] = list(map(75 lambda x: x.to_dict() if hasattr(x, "to_dict") else x,76 value...
test_frontendbase.py
Source:test_frontendbase.py
...13def test_iscomplete():14 """ Check that is_complete works. 15 """16 f = FrontEndBase()17 assert f.is_complete('(a + a)')18 assert not f.is_complete('(a + a')19 assert f.is_complete('1')20 assert not f.is_complete('1 + ')21 assert not f.is_complete('1 + \n\n')22 assert f.is_complete('if True:\n print 1\n')23 assert not f.is_complete('if True:\n print 1')24 assert f.is_complete('def f():\n print 1\n')25if __name__ == '__main__':...
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!!