How to use relationship method in PyHamcrest

Best Python code snippet using PyHamcrest_python

views.py

Source:views.py Github

copy

Full Screen

1from django.shortcuts import render2from django.shortcuts import render,redirect, HttpResponse3from django.contrib.auth import authenticate,login,logout4from django.contrib.auth.decorators import login_required5from django.contrib.auth.hashers import make_password6from user.models import Profile, RelationshipStatus, Friend_Request, Accepted, BreakUp7from django.contrib.auth.models import User8from django.contrib import messages9@login_required(login_url='/login')10def home(request):11 gender = "female"12 check = Profile.objects.get(user__username=request.user)13 relationship = RelationshipStatus.objects.get(profile=check)14 if relationship.status == "In Open Relationship":15 return redirect('/welcome') 16 currentUser = check.user.username17 db = Profile.objects.filter(gender='female')18 for i in db:19 if i.user.username ==currentUser:20 return redirect('/login')21 else:22 pass23 myprofile = Profile.objects.get(user__username=request.user)24 data = Profile.objects.filter(gender=gender)25 return render(request,'maleapp.html',{'maledata':data,'myprofile':myprofile})26@login_required(login_url='/login')27def fullprofile(request,id):28 u=Profile.objects.get(user__username=request.user)29 relationship = RelationshipStatus.objects.get(profile=u)30 db = Profile.objects.get(id=id)31 if db.gender =='male':32 return redirect('/login')33 elif relationship.status == "In Open Relationship":34 return redirect('/welcome')35 else:36 fulldata = Profile.objects.get(id=id)37 myprofile = Profile.objects.get(user__username=request.user)38 relationship = RelationshipStatus.objects.get(profile=id)39 return render(request,'fullprofileofgirl.html',{'fulldata':fulldata,'myprofile':myprofile,'relationship':relationship})40@login_required(login_url='/login')41def NextProcess(request,id):42 user = Profile.objects.get(user__username=request.user)43 relationship = RelationshipStatus.objects.get(profile=user)44 if relationship.status == "In Open Relationship":45 return redirect('/welcome')46 if relationship.status == "Protected":47 return redirect('/waiting')48 requested_to = Profile.objects.get(id=id)49 relationship = Accepted.objects.all()50 inopen = []51 for i in relationship:52 inopen.append(i.user1.user.username)53 inopen.append(i.user2.user.username)54 print(inopen)55 if requested_to.gender =='male':56 return redirect('/login')57 elif requested_to.user.username in inopen:58 return redirect('/login')59 else:60 f_q = Friend_Request(requested_by = user, requested_to = requested_to)61 f_q.save()62 RelationshipStatus.objects.filter(profile=user).update(status="Trying")63 return redirect('/maleapp')64@login_required(login_url='/login')65def rrtomale(request):66 user = Profile.objects.get(user__username=request.user)67 relationship = RelationshipStatus.objects.get(profile=user)68 if relationship.status == "In Open Relationship":69 return redirect('/welcome')70 f_q = Friend_Request.objects.filter(requested_to=user)71 return render(request,'rrtomale.html',{'f_q':f_q})72@login_required(login_url='/login')73def rejectthisgirl(request,id):74 user = Profile.objects.get(user__username=request.user)75 relationship = RelationshipStatus.objects.get(profile=user)76 if relationship.status == "In Open Relationship":77 return redirect('/welcome')78 f_q = Friend_Request.objects.get(id=id)79 f_q.delete()80 return redirect('/maleapp/rrtomale')81@login_required(login_url='/login')82def acceptthisgirl(request,id):83 user = Profile.objects.get(user__username=request.user)84 relationship = RelationshipStatus.objects.get(profile=user)85 if relationship.status == "In Open Relationship":86 return redirect('/welcome')87 db = Profile.objects.get(id=id)88 if db.gender =='male':89 return redirect('/login')90 else:91 user1 = Profile.objects.get(user__username=request.user)92 user2 = Profile.objects.get(id=id)93 pair = Accepted(user1=user1,user2=user2)94 pair.save()95 RelationshipStatus.objects.filter(profile=user1).update(status="In Open Relationship")96 RelationshipStatus.objects.filter(profile=user2).update(status="In Open Relationship")97 f_q = Friend_Request.objects.filter(requested_to=user1)98 f_q.delete()99 f_q = Friend_Request.objects.filter(requested_by=user1)100 f_q.delete()101 f_q = Friend_Request.objects.filter(requested_to=user2)102 f_q.delete()103 f_q = Friend_Request.objects.filter(requested_by=user2)104 f_q.delete()105 print("Accepted")106 return redirect('/welcome')107def brtofemale(request,id):108 user = Profile.objects.get(user__username=request.user)109 relationship = RelationshipStatus.objects.get(profile=user)110 if relationship.status == "Single" or relationship.status == "Trying":111 return redirect('/login')112 db = Profile.objects.get(id=id)113 relationship = RelationshipStatus.objects.get(profile=db)114 if db.gender =='male':115 return redirect('/login')116 elif relationship.status == "Single" or relationship.status == "Trying":117 return redirect('/login')118 else:119 requested_by = Profile.objects.get(user__username=request.user)120 requested_to = Profile.objects.get(id=id)121 b_q = BreakUp(requested_b = requested_by, requested_t=requested_to)122 b_q.save()123 message = "Break-up request sent successfully..."124 messages.info(request, message)125 return redirect('/welcome')126def brtomalelist(request):127 user = Profile.objects.get(user__username=request.user)128 relationship = RelationshipStatus.objects.get(profile=user)129 if relationship.status == "Single" or relationship.status == "Trying":130 return redirect('/login')131 user = Profile.objects.get(user__username=request.user)132 b_q = BreakUp.objects.filter(requested_t = user)133 return render(request,'brtomalelist.html',{'b_q':b_q})134def brdeclinebymale(request):135 user = Profile.objects.get(user__username=request.user)136 relationship = RelationshipStatus.objects.get(profile=user)137 if relationship.status == "Single" or relationship.status == "Trying":138 return redirect('/login')139 user = Profile.objects.get(user__username=request.user)140 b_q = BreakUp.objects.filter(requested_t = user)141 b_q.delete()142 b_q = BreakUp.objects.filter(requested_b = user)143 b_q.delete()144 return redirect('/welcome')145def yesBreakUp(request):146 user = Profile.objects.get(user__username=request.user)147 relationship = RelationshipStatus.objects.get(profile=user)148 if relationship.status == "Single" or relationship.status == "Trying":149 return redirect('/login')150 151 user = Profile.objects.get(user__username=request.user)152 b_q = BreakUp.objects.filter(requested_t = user)153 for i in b_q:154 RelationshipStatus.objects.filter(profile=i.requested_t).update(status="Single")155 RelationshipStatus.objects.filter(profile=i.requested_b).update(status="Single")156 b_q.delete()157 b_q = BreakUp.objects.filter(requested_b = user)158 for i in b_q:159 RelationshipStatus.objects.filter(profile=i.requested_t).update(status="Single")160 RelationshipStatus.objects.filter(profile=i.requested_b).update(status="Single")161 b_q.delete()162 Accepted_data = Accepted.objects.filter(user1=user)163 Accepted_data.delete()164 Accepted_data = Accepted.objects.filter(user2=user)165 Accepted_data.delete()166 return redirect('/maleapp')167def superbreakup(request):168 user = Profile.objects.get(user__username=request.user)169 relationship = RelationshipStatus.objects.get(profile=user)170 if relationship.status == "Single" or relationship.status == "Trying":171 return redirect('/login')172 user = Profile.objects.get(user__username=request.user)173 b_q = BreakUp.objects.filter(requested_b = user)174 if b_q:175 b_q = BreakUp.objects.filter(requested_t = user)176 for i in b_q:177 RelationshipStatus.objects.filter(profile=i.requested_t).update(status="Single")178 RelationshipStatus.objects.filter(profile=i.requested_b).update(status="Single")179 b_q.delete()180 b_q = BreakUp.objects.filter(requested_b = user)181 for i in b_q:182 RelationshipStatus.objects.filter(profile=i.requested_t).update(status="Single")183 RelationshipStatus.objects.filter(profile=i.requested_b).update(status="Single")184 b_q.delete()185 else:186 message = "First Try Normal Break-Up..."187 messages.info(request, message)188 return redirect('/welcome')189 Accepted_data = Accepted.objects.filter(user1=user)190 Accepted_data.delete()191 Accepted_data = Accepted.objects.filter(user2=user)192 Accepted_data.delete()...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1import copy2def print_conditions(conditions, seperator='Λ'):3 """Pretty prints a set of conditions with a custom seperator."""4 5 formula = ""6 for i, (table, condition) in enumerate(conditions):7 formula += table + "." + condition8 if i < len(conditions) - 1:9 formula += ' ' + seperator + ' '10 return formula11def gen_full_join_query(schema_graph, relationship_set, table_set, join_type):12 """13 Creates the full outer join to for a relationship set for join_type FULL OUTER JOIN or JOIN14 """15 from_clause = ""16 if len(relationship_set) == 0:17 assert(len(table_set) == 1)18 from_clause = list(table_set)[0]19 20 else:21 included_tables = set()22 relationships = copy.copy(relationship_set)23 24 while relationships:25 # first relation to be included26 if len(included_tables) == 0:27 relationship = relationships.pop()28 relationship_obj = schema_graph.relationship_dictionary[relationship]29 included_tables.add(relationship_obj.start)30 included_tables.add(relationship_obj.end)31 from_clause += relationship_obj.start + " " + join_type + " " + relationship_obj.end + " ON " + relationship32 else:33 # search in suitable relations34 relationship_to_add = None35 for relationship in relationships:36 relationship_obj = schema_graph.relationship_dictionary[relationship]37 if (relationship_obj.start in included_tables and relationship_obj.end not in included_tables) or \38 (relationship_obj.end in included_tables and relationship_obj.start not in included_tables):39 relationship_to_add = relationship40 if relationship_to_add is None:41 raise ValueError("Query not a tree")42 # add it to where formula43 relationship_obj = schema_graph.relationship_dictionary[relationship_to_add]44 if (relationship_obj.start in included_tables and relationship_obj.end not in included_tables):45 from_clause += " " + join_type + " " + relationship_obj.end + " ON " + relationship_to_add46 included_tables.add(relationship_obj.end)47 relationships.remove(relationship_to_add)48 elif (relationship_obj.end in included_tables and relationship_obj.start not in included_tables):49 from_clause += " " + join_type + " " + relationship_obj.start + " ON " + relationship_to_add50 included_tables.add(relationship_obj.start)51 relationships.remove(relationship_to_add)52 ...

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