Best Python code snippet using tempest_python
test_create_limit.py
Source:test_create_limit.py
1from dataclasses import dataclass2import pytest3from motor.motor_asyncio import AsyncIOMotorClient4from pytest import mark5from app.core.config import get6from app.core.errors import CreateQuantityLimit, PermissionDoesNotExist, ParamsError7from app.enums.common import 产ååç±»8from app.enums.equipment import è£
å¤åç±»_39from app.models.user import User10from app.service.create_limit import å建æ°ééå¶11pytestmark = mark.asyncio12@dataclass13class MockCollection(object):14 conn: AsyncIOMotorClient15 config: str16 async def count_documents(self, *args, **kwargs):17 from app import settings18 return settings.num_limit["VIPç¨æ·"][get(self.config)]19@dataclass20class MockLittleCollection(object):21 conn: AsyncIOMotorClient22 config: str23 async def count_documents(self, *args, **kwargs):24 from app import settings25 return settings.num_limit["VIPç¨æ·"][get(self.config)] - 126@mark.parametrize(27 "category, è£
å¤åç±», user",28 [29 (产ååç±».equipment, è£
å¤åç±»_3.éè¡, "å
è´¹ç¨æ·"),30 (产ååç±».robot, None, "VIPç¨æ·"),31 (产ååç±».portfolio, None, "VIPç¨æ·"),32 (产ååç±».equipment, è£
å¤åç±»_3.éè¡, "VIPç¨æ·"),33 (产ååç±».equipment, None, "VIPç¨æ·"),34 (产ååç±».equipment, è£
å¤åç±»_3.éè¡, "è¶
级ç¨æ·"),35 ],36)37async def test_check_create_quota_by_category(38 fixture_client, fixture_settings, fixture_db, logined_root_user, logined_free_user, logined_vip_user, category, è£
å¤åç±», user, mocker39):40 if user == "è¶
级ç¨æ·":41 response = await å建æ°ééå¶(fixture_db, category, User(**logined_root_user["user"]), è£
å¤åç±»)42 assert response is True43 elif user == "å
è´¹ç¨æ·":44 with pytest.raises(PermissionDoesNotExist):45 await å建æ°ééå¶(fixture_db, category, User(**logined_free_user["user"]), è£
å¤åç±»)46 else:47 if category == 产ååç±».equipment and è£
å¤åç±» is None:48 mocker.patch("app.service.create_limit.get_collection_by_config", side_effect=MockCollection)49 with pytest.raises(ParamsError):50 await å建æ°ééå¶(fixture_db, category, User(**logined_vip_user["user"]), è£
å¤åç±»)51 else:52 # wright53 mocker.patch("app.service.create_limit.get_collection_by_config", side_effect=MockLittleCollection)54 response = await å建æ°ééå¶(fixture_db, category, User(**logined_vip_user["user"]), è£
å¤åç±»)55 assert response is True56 # error57 mocker.patch("app.service.create_limit.get_collection_by_config", side_effect=MockCollection)58 with pytest.raises(CreateQuantityLimit):...
test_limit_view.py
Source:test_limit_view.py
1import json2from .cli import cli3async def create_limit(cli):4 resp = await cli.post(5 '/limit',6 data=json.dumps(dict(country="RUS", currency="RUB", max_sum_per_month="1000.15"))7 )8 print(await resp.json())9 return (await resp.json())['limit_id']10async def test_limit_view_get(cli):11 resp = await cli.get('/limit')12 assert resp.status == 20013 limit_id = await create_limit(cli)14 resp = await cli.get(f'/limit/{limit_id}')15 assert resp.status == 20016 resp = await cli.get('/limit/0')17 assert resp.status == 40018async def test_limit_view_post(cli):19 resp = await cli.post(20 '/limit',21 data=json.dumps(dict(country="RUS", currency="RUB", max_sum_per_month="999999999.99"))22 )23 assert resp.status == 20024 resp = await cli.post(25 '/limit',26 data=json.dumps(dict(country="ERR", currency="ERR", max_sum_per_month="0"))27 )28 assert resp.status == 40029async def test_limit_view_put(cli):30 resp = await cli.put(31 '/limit/0',32 data=json.dumps(dict(country="RUS", currency="RUB", max_sum_per_month="999999999.99"))33 )34 assert resp.status == 40035 limit_id = await create_limit(cli)36 resp = await cli.put(37 f'/limit/{limit_id}',38 data=json.dumps(dict(country="RUS", currency="RUB", max_sum_per_month="11.111"))39 )40 assert resp.status == 20041 resp = await cli.put(42 '/limit/0',43 data=json.dumps(dict(country="ERR", currency="ERR", max_sum_per_month="0"))44 )45 assert resp.status == 40046async def test_limit_view_delete(cli):47 resp = await cli.delete('/limit/0')48 assert resp.status == 40049 print(await resp.json())50 limit_id = await create_limit(cli)51 resp = await cli.delete(f'/limit/{limit_id}')...
signals.py
Source:signals.py
...3# from django.db.models.signals import post_save4# from django.dispatch import receiver5#6#7# def create_limit(sender, instance, created, **kwargs):8#9# if created:10# Limits.objects.create(owner=instance)11# print("limit created")12#13#14# post_save.connect(create_limit, sender=User)15#16#17# def update_limit(sender, instance, created, **kwargs):18#19# if created == False:20# instance.limit.save()21# print("limit updated")...
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!!