Best Python code snippet using testcontainers-python_python
test_serialize.py
Source:test_serialize.py
...319 device = make_device(with_services=False, with_subdevices=False)320 d = Device()321 d.deserialize(json.loads(JSON_RESULT_TEST_SERIALIZE_DEVICE))322 assert d == device323def test_serialize_device_with_services():324 device = make_device(with_services=True, with_subdevices=False)325 result = json.dumps(device.serialize())326 assert result == JSON_RESULT_TEST_SERIALIZE_DEVICE_WITH_SERVICES327def test_deserialize_device_with_services():328 device = make_device(with_services=True, with_subdevices=False)329 d = Device()330 d.deserialize(json.loads(JSON_RESULT_TEST_SERIALIZE_DEVICE_WITH_SERVICES))331 assert d == device332def test_serialize_device_with_services_and_subdevices():333 device = make_device(with_services=True, with_subdevices=True)334 result = json.dumps(device.serialize())335 assert (336 result == JSON_RESULT_TEST_SERIALIZE_DEVICE_WITH_SERVICES_AND_SUBDEVICES337 )338def test_deserialize_device_with_services_and_subdevices():339 device = make_device(with_services=True, with_subdevices=True)340 d = Device()341 d.deserialize(...
test_vehicle_log.py
Source:test_vehicle_log.py
1# -*- coding: utf-8 -*-2# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors3# See license.txt4from __future__ import unicode_literals5import unittest6import frappe7from frappe.utils import cstr, flt, nowdate, random_string8from erpnext.hr.doctype.employee.test_employee import make_employee9from erpnext.hr.doctype.vehicle_log.vehicle_log import make_expense_claim10class TestVehicleLog(unittest.TestCase):11 def setUp(self):12 employee_id = frappe.db.sql("""select name from `tabEmployee` where name='testdriver@example.com'""")13 self.employee_id = employee_id[0][0] if employee_id else None14 if not self.employee_id:15 self.employee_id = make_employee("testdriver@example.com", company="_Test Company")16 self.license_plate = get_vehicle(self.employee_id)17 def tearDown(self):18 frappe.delete_doc("Vehicle", self.license_plate, force=1)19 frappe.delete_doc("Employee", self.employee_id, force=1)20 def test_make_vehicle_log_and_syncing_of_odometer_value(self):21 vehicle_log = make_vehicle_log(self.license_plate, self.employee_id)22 #checking value of vehicle odometer value on submit.23 vehicle = frappe.get_doc("Vehicle", self.license_plate)24 self.assertEqual(vehicle.last_odometer, vehicle_log.odometer)25 #checking value vehicle odometer on vehicle log cancellation.26 last_odometer = vehicle_log.last_odometer27 current_odometer = vehicle_log.odometer28 distance_travelled = current_odometer - last_odometer29 vehicle_log.cancel()30 vehicle.reload()31 self.assertEqual(vehicle.last_odometer, current_odometer - distance_travelled)32 vehicle_log.delete()33 def test_vehicle_log_fuel_expense(self):34 vehicle_log = make_vehicle_log(self.license_plate, self.employee_id)35 expense_claim = make_expense_claim(vehicle_log.name)36 fuel_expense = expense_claim.expenses[0].amount37 self.assertEqual(fuel_expense, 50*500)38 vehicle_log.cancel()39 frappe.delete_doc("Expense Claim", expense_claim.name)40 frappe.delete_doc("Vehicle Log", vehicle_log.name)41 def test_vehicle_log_with_service_expenses(self):42 vehicle_log = make_vehicle_log(self.license_plate, self.employee_id, with_services=True)43 expense_claim = make_expense_claim(vehicle_log.name)44 expenses = expense_claim.expenses[0].amount45 self.assertEqual(expenses, 27000)46 vehicle_log.cancel()47 frappe.delete_doc("Expense Claim", expense_claim.name)48 frappe.delete_doc("Vehicle Log", vehicle_log.name)49def get_vehicle(employee_id):50 license_plate=random_string(10).upper()51 vehicle = frappe.get_doc({52 "doctype": "Vehicle",53 "license_plate": cstr(license_plate),54 "make": "Maruti",55 "model": "PCM",56 "employee": employee_id,57 "last_odometer": 5000,58 "acquisition_date": nowdate(),59 "location": "Mumbai",60 "chassis_no": "1234ABCD",61 "uom": "Litre",62 "vehicle_value": flt(500000)63 })64 try:65 vehicle.insert()66 except frappe.DuplicateEntryError:67 pass68 return license_plate69def make_vehicle_log(license_plate, employee_id, with_services=False):70 vehicle_log = frappe.get_doc({71 "doctype": "Vehicle Log",72 "license_plate": cstr(license_plate),73 "employee": employee_id,74 "date": nowdate(),75 "odometer": 5010,76 "fuel_qty": flt(50),77 "price": flt(500)78 })79 if with_services:80 vehicle_log.append("service_detail", {81 "service_item": "Oil Change",82 "type": "Inspection",83 "frequency": "Mileage",84 "expense_amount": flt(500)85 })86 vehicle_log.append("service_detail", {87 "service_item": "Wheels",88 "type": "Change",89 "frequency": "Half Yearly",90 "expense_amount": flt(1500)91 })92 vehicle_log.save()93 vehicle_log.submit()...
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!!