Best Python code snippet using autotest_python
test_models.py
Source:test_models.py
...3from django.test import TestCase4from base.models import *5# Create your tests here.6class ProductTestCase(TestCase):7 def test__str__(self):8 product = Product.objects.create(9 user=User.objects.create_user(10 username="mailer@gmail.com", email="mailer@gmail.com", password="Stronger15!"),11 name="test",12 image="/placeholder.png",13 brand="test",14 category="",15 description="",16 price="30.80",17 is_promoted=True,18 count_in_stock=1,19 created_at="2021-11-15T09:44:46.162397Z",20 rating="4.44",21 numReviews=122 )23 nametest = "test"24 self.assertEquals(product.name, nametest)25class OderTestCase(TestCase):26 def test__str__(self):27 d1 = datetime.datetime(2021, 11, 15)28 order = Order.objects.create(29 user=User.objects.create_user(30 username="mailer@gmail.com", email="mailer@gmail.com", password="Stronger15!"),31 paymentMethod=1,32 shippingPrice=1,33 totalPrice=1,34 isPaid=False,35 paidAt='2021-11-15T11:45:08Z',36 isDelivered=False,37 deliveredAt='2021-11-15T11:45:08Z',38 createdAt=''39 )40 self.assertNotEqual(order.createdAt, '')41class OrderItemTestCase(TestCase):42 def test__str__(self):43 userInfo=User.objects.create_user(44 username="mailer@gmail.com", email="mailer@gmail.com", password="Stronger15!")45 orderitem = OrderItem.objects.create(46 product=Product.objects.create(47 user=userInfo,48 name="test",49 image="/placeholder.png",50 brand="test",51 category="",52 description="",53 price="30.80",54 is_promoted=True,55 count_in_stock=1,56 created_at="2021-11-15T09:44:46.162397Z",57 rating="4.44",58 numReviews=1),59 order=Order.objects.create(60 user=userInfo,61 paymentMethod="PayPal",62 shippingPrice=1,63 totalPrice=1,64 isPaid=False,65 paidAt='2021-11-15T09:44:46.162397Z',66 isDelivered=False,67 deliveredAt='2021-11-15T09:44:46.162397Z',68 createdAt='2021-11-15T09:44:46.162397Z'),69 name='test',70 qty=1,71 price=1,72 image=''73 )74 self.assertEquals(orderitem.name, 'test')75class ShippingAddressTestCase(TestCase):76 def test__str__(self):77 self.shipingaddress = ShippingAddress.objects.create(78 order=Order.objects.create(79 user=User.objects.create_user(80 username="mailer@gmail.com", email="mailer@gmail.com", password="Stronger15!"),81 paymentMethod=1,82 shippingPrice=1,83 totalPrice=1,84 isPaid=False,85 paidAt='2021-11-15T09:44:46.162397Z',86 isDelivered=False,87 deliveredAt='2021-11-15T09:44:46.162397Z',88 createdAt='2021-11-15T09:44:46.162397Z'),89 country='',90 city='',91 address='',92 postalCode=''93 )94 self.assertEquals(self.shipingaddress.address, '')95class ReviewTestCase(TestCase):96 def test__str__(self):97 userInfo=User.objects.create_user(98 username="mailer@gmail.com", email="mailer@gmail.com", password="Stronger15!")99 self.review = Review.objects.create(100 product=Product.objects.create(101 user=userInfo,102 name="test",103 image="/placeholder.png",104 brand="test",105 category="",106 description="",107 price="30.80",108 is_promoted=True,109 count_in_stock=1,110 created_at="2021-11-15T09:44:46.162397Z",...
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!!