How to use apifun method in pytest-django

Best Python code snippet using pytest-django_python

api_functions.py

Source:api_functions.py Github

copy

Full Screen

1from django import template2from django.utils.translation import deactivate3from appuser.models import AttDayDetails, HrEmployee, AttPunches, NewAppSalary4from datetime import date, datetime, timedelta5from calendar import monthrange6from django.utils.dateparse import parse_datetime7register = template.Library()8# Functions9def apifun_isSameDateTime(datetime1, datetime2):10 if datetime1 == datetime2:11 print(str(datetime1) + ' == ' + str(datetime2))12 else:13 print(str(datetime1) + " Not Equal " + str(datetime2))14def apifun_getMonthRange(year, month):15 range = str(monthrange(year,month)).split(',')[1]16 range = int(range.replace(')', ''))17 return range18def apifun_getDay(datetime):19 return int(datetime.day)20def apifun_getDayName(datetime):21 return datetime.strftime('%A')22def apifun_getMonth(datetime):23 return int(datetime.month)24def apifun_getYear(datetime):25 return int(datetime.year)26def apifun_getCurrentMonth():27 # return int(datetime.now().month) - 128 return 1229def apifun_getCurrentMonthRange():30 year = datetime.now().year31 month = datetime.now().month32 range = str(monthrange(2021,12)).split(',')[1]33 range = int(range.replace(')', ''))34 return range35def apifun_getCurrentYear():36 # return int(datetime.now().year)37 return 202138def apifun_getCurrentDay():39 return int(datetime.now().day)40def apifun_getCurrentDayName():41 return str(datetime.now().strftime('%A'))42# Tags43def apifun_getTodayHourAndOverTime(user_id,date):44 # Create date45 targetDate = datetime.strftime(date,"%Y-%m-%d")46 UserdayDetails = AttDayDetails.objects.get(employee_id=user_id, att_date=date)47 checkin_time = UserdayDetails.checkin48 # checkout49 alltimesbyuser = AttPunches.objects.filter(employee_id=user_id).order_by('punch_time')50 checkout_time = ''51 for usertime in alltimesbyuser:52 looptime = datetime.strftime(usertime.punch_time,"%Y-%m-%d %H:%M:%S") 53 if targetDate in looptime:54 checkout_time = looptime55 checkout_time = parse_datetime(checkout_time)56 if checkout_time is not None and checkin_time is not None:57 targetCheckInTime = datetime.strftime(checkin_time, '%H:%M')58 targetCheckoutTime = datetime.strftime(checkout_time, '%H:%M')59 # If not checked out60 if targetCheckInTime == targetCheckoutTime:61 return [0,0]62 # Checked out63 checkout_hour = datetime.strftime(checkout_time, '%H')64 checkout_menuite = datetime.strftime(checkout_time, '%M')65 checkout_sec = datetime.strftime(checkout_time, '%S')66 checkin_hour = datetime.strftime(checkin_time, '%H')67 checkin_menuite = datetime.strftime(checkin_time, '%M')68 checkin_sec = datetime.strftime(checkin_time, '%S')69 checkout =timedelta(hours = int(checkout_hour) , minutes=int(checkout_menuite), seconds=int(checkout_sec))70 checkin = timedelta(hours= int(checkin_hour) , minutes=int(checkin_menuite), seconds=int(checkin_sec))71 total_working_hours = checkout - checkin72 str_data = str(total_working_hours)73 hour = int(str_data.split(':')[0])74 menuite = int(str_data.split(':')[1])75 sec = int(str_data.split(':')[2])76 # Round hour if work more than or equal to 45 min77 if menuite >= 45:78 hour += 179 menuite = 080 81 # Round Menuite if work less than 20 min make it 082 if menuite <= 20:83 menuite = 084 # Round menuite if work more than 20 make it 3085 if menuite > 20 and menuite < 44:86 menuite = 3087 88 # Checking if overtiem availabe89 overtimeHour = 090 overtimeMenuite = 091 totalOvertimeMenuites = 092 totalWorkingMenuites = 093 # Overtime Calculation94 if(hour >= 11 and menuite > 20):95 if hour > 11:96 overtimeHour = hour - 1197 overtimeMenuite = menuite98 99 if overtimeHour > 0 or overtimeMenuite > 0:100 # result = str(overtimeHour) + " hour and " + str(overtimeMenuite) + " min"101 totalOvertimeMenuites = (overtimeHour*60) + overtimeMenuite102 else:103 totalOvertimeMenuites = 0104 # Hour Calculation105 if(hour > 11):106 totalWorkingMenuites = (11 * 60)107 else:108 totalWorkingMenuites = (hour * 60) + menuite109 return [totalWorkingMenuites, totalOvertimeMenuites]110 else:111 return [0,0] 112def apifun_getTotalWorkingMin(user_id):113 current_month = apifun_getCurrentMonth()114 monthRange = apifun_getCurrentMonthRange()115 current_year = apifun_getCurrentYear()116 totalMonthlyWorkingTime = 0117 for day in range(monthRange):118 tdate = datetime(current_year,current_month,day+1)119 try:120 if apifun_getTodayHourAndOverTime(user_id, tdate) is not None:121 # print("Current Time: " + str(getTodayHourAndOverTime(user_id, tdate)[0]))122 totalMonthlyWorkingTime += apifun_getTodayHourAndOverTime(user_id, tdate)[0]123 except:124 pass125 126 return (totalMonthlyWorkingTime)127def apifun_getTotalOvertimeMin(user_id):128 current_month = apifun_getCurrentMonth()129 monthRange = apifun_getCurrentMonthRange()130 current_year = apifun_getCurrentYear()131 totalOvertime = 0132 for day in range(monthRange):133 tdate = datetime(current_year,current_month,day+1)134 try:135 if apifun_getTodayHourAndOverTime(user_id, tdate) is not None:136 # print("Current Time: " + str(getTodayHourAndOverTime(user_id, tdate)[1]))137 totalOvertime += apifun_getTodayHourAndOverTime(user_id, tdate)[1]138 except:139 pass140 141 return (totalOvertime)142def apifun_monthlyEarnings(user_id):143 w = apifun_getTotalWorkingMin(user_id)144 o = apifun_getTotalOvertimeMin(user_id)145 # 11 hours per day 26 days = 17160 min146 ts = NewAppSalary.objects.get(employee_id=user_id).salary147 148 perminIncome = ts / 17160149 wi = w * perminIncome150 oi = o * perminIncome151 total = wi + oi ...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from asyncio import wait_for2import asyncio3from asyncio.windows_events import NULL4from importlib.metadata import files5from logging import NullHandler6from pyexpat.errors import messages7import discord8import apifun as apifun9from secret import token as TOKEN101112class MyClient(discord.Client):13 #Einloggen14 async def on_ready(self):15 print("Ich habe mich eingeloggt Beep Boop")16 17 #Wenn Nachricht gepostet wird18 async def on_message(self, message):19 if message.author == client.user:20 return21 #Inzidenz22 if message.content.lower() == "!corona":23 update = apifun.corona_update(apifun.corona_updater())24 await message.channel.send(update.get_corona_update())2526 #Jokes27 if message.content.lower() == "!joke":28 joke = apifun.joker(apifun.get_new_joke())29 if joke.get_joke_type() == "single":30 await message.channel.send(joke.get_single())31 else:32 await message.channel.send(joke.get_setup())33 await message.channel.send(joke.get_delivery())3435 #CatFact36 if message.content.lower() == "!catfact":37 await message.channel.send(apifun.get_new_catfact())3839 #MathFact40 if message.content.lower() == "!mathfact":41 await message.channel.send(apifun.get_new_mathfact())4243 #Nasapic44 if message.content.lower() == "!nasa":45 await message.channel.send(apifun.get_new_nasapic())4647 #Dogpic48 if message.content.lower() == "!dog":49 await message.channel.send(apifun.get_new_dogpic())50 #Dogbomb51 if message.content.lower() == "!dogbomb":52 for i in range(5):53 await message.channel.send(apifun.get_new_dogpic())5455 #Dogpic56 if message.content.lower() == "!cat":57 await message.channel.send(apifun.get_new_catpic())58 #Dogbomb59 if message.content.lower() == "!catbomb":60 for i in range(5):61 await message.channel.send(apifun.get_new_catpic())6263 #ChucknorisFact64 if message.content.lower() == "!chuckfact":65 await message.channel.send(apifun.get_new_chuckfact())6667 #Ageguesser6869client = MyClient()70# @client.event71# async def on_message(message):72# if message.content.lower() == "!age":73# channel = message.channel74# await channel.send('Schreib mir einen Namen und ich sage dir wie alt er klingt')7576# def check(m):77# return m.author == message.author and m.channel == channel7879# msg = await client.wait_for('message', check=check)80# await channel.send("Der Name " + str(msg.content) + " klingt für mich als wärst du " + get_age(msg.content) + " Jahre alt.")81 ...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.contrib import admin2from django.urls import path3from api import views4urlpatterns = [5 path('',views.home.as_view()),6 path('apifun',views.apifun.as_view()),7 path('apifun/<int:pk>',views.apifun.as_view()),8 ...

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 pytest-django 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