Best Python code snippet using hypothesis
views.py
Source: views.py
1from django.contrib import messages2from django.contrib.auth.decorators import login_required3from django.shortcuts import render, redirect4from django.contrib.auth.models import auth5from .models import User6# Create your views here.7# Admin User8def register(request):9 if request.method == 'POST':10 Uname = request.POST['username']11 passwd = request.POST['password']12 passwd1 = request.POST['Password1']13 phone = request.POST['Phone']14 if User.objects.filter(username=Uname).exists():15 messages.info(request, "Username is taken!!!")16 return redirect("login")17 else:18 if User.objects.filter(userPhone=phone).exists():19 messages.info(request, "Please enter a unique Phone number")20 return redirect('login')21 else:22 if passwd == passwd1:23 user = User.objects.create_superuser(username=Uname, userPhone=phone, password=passwd)24 user.save()25 messages.info(request, "Account has successfully created for " + Uname)26 return redirect('login')27 else:28 messages.info(request, "Password doesnt' match!!!")29 return redirect('login')30 else:31 return render(request, "login", {})32# Staff User33def register_staff(request):34 if request.method == 'POST':35 Uname = request.POST['username']36 passwd = request.POST['password']37 passwd1 = request.POST['Password1']38 phone = request.POST['Phone']39 if User.objects.filter(username=Uname).exists():40 messages.info(request, "Username is taken!!!")41 return redirect("login")42 else:43 if User.objects.filter(userPhone=phone).exists():44 messages.info(request, "Please enter a unique Phone number")45 return redirect('login')46 else:47 if passwd == passwd1:48 user = User.objects.create_superuser(username=Uname, userPhone=phone, password=passwd)49 user.save()50 messages.info(request, "Account has successfully created for " + Uname)51 return redirect('login')52 else:53 messages.info(request, "Password doesnt' match!!!")54 return redirect('login')55 else:56 return render(request, "login", {})57# Creating account for cashier58@login_required59def create_Stuff(request):60 if request.method == 'POST':61 Fname = request.POST['empName']62 Epass = request.POST['empPass']63 Epass1 = request.POST['empPass1']64 Ephone = request.POST['empPhone']65 Eadd = request.POST['empAdd']66 if User.objects.filter(username=Fname).exists():67 messages.info(request, "Username already exits.")68 return redirect("create_stuff")69 else:70 if User.objects.filter(userPhone=Ephone).exists():71 messages.info(request, "Please enter a unique Phone number")72 return redirect("create_stuff")73 else:74 if Epass == Epass1:75 EmpUser = User.objects.create_staff(username=Fname, userPhone=Ephone, userAdd=Eadd, password=Epass)76 EmpUser.save()77 messages.info(request, "Account has successfully created for " + Fname)78 return redirect('create_stuff')79 else:80 messages.info(request, "Password does not match.")81 return redirect("create_stuff")82 else:83 return render(request, "create_stuff.html", {})84@login_required85def Search_Cashier(request):86 if request.method == 'POST':87 empNam = request.POST['sField']88 if User.objects.filter(username=empNam).exists():89 empDetails = User.objects.all().filter(username=empNam)90 return render(request, 'update_stuff.html', {'stf': empDetails})91 else:92 messages.info(request, 'Invalid User')93 return redirect('Search_Cashier')94 else:95 return render(request, 'update_stuff.html', {})96@login_required97def Update_Cashier(request):98 if request.method == 'POST':99 eName = request.POST['empName']100 Epass1 = request.POST['empPass']101 Ephone1 = request.POST['empPhone']102 Eadd1 = request.POST['empAdd']103 hidd = request.POST['hid']104 upd = User.objects.select_related().filter(username=eName).update(userPhone=Ephone1, userAdd=Eadd1)105 print(hidd)106 messages.info(request, 'Changes successfully made.')107 return redirect('Update_Cashier')108 else:109 return render(request, 'update_stuff.html', {})110def logout(request):111 auth.logout(request)...
urls.py
Source: urls.py
1from django.contrib import admin2from django.urls import path, include3from . import views4urlpatterns = [5 path('login/register', views.register, name='register'),6 path("Home/create_stuff", views.create_Stuff, name="create_stuff"),7 path("Home/Search_Cashier", views.Search_Cashier, name="Search_Cashier"),8 path("Home/Update_Cashier", views.Update_Cashier, name="Update_Cashier"),9 path("Home/logout", views.logout, name="logout"),...
mklixo.py
Source: mklixo.py
1#!/usr/bin/env python2import os3import sys4import random5def create_stuff(nfiles):6 for nfile in xrange(nfiles):7 name = "file-%05d.METAL" % nfile8 f = open(name, "w")9 size = random.randint(1, 2000) * 102410 f.seek(size-1)11 f.write("\0")12 f.close()13if __name__ == "__main__":14 # <nfiles> <range>...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
Mobile application development is on the rise like never before, and it proportionally invites the need to perform thorough testing with the right mobile testing strategies. The strategies majorly involve the usage of various mobile automation testing tools. Mobile testing tools help businesses automate their application testing and cut down the extra cost, time, and chances of human error.
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!!