Source code for conftest

from django.contrib.auth import get_user_model,get_user
from django.contrib.auth.models import User,AbstractBaseUser,AbstractUser,PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from core.models import Account,User,Addition,Style,ShipUnit,Bottle,Country,LocationType,Location
from datetime import date,timedelta,datetime
from notes.models import Notes
import pytest 
from model_bakery import baker




[docs] @pytest.fixture def guest_user(db) -> User: # Returns a Guest User guest_user = User.objects.create_user(username='test_guest', email='guest@example.com', password='password') return guest_user
[docs] @pytest.fixture def member_user(db) -> User: # Returns a Member User member_user = User.objects.create_user(username='test_member', email='member@example.com', password='password') return member_user
[docs] @pytest.fixture def account(db) -> Account: # Returns a Test Account test_account = Account.objects.create(account='test_account') return test_account
[docs] @pytest.fixture def account_user(db,account) -> User: # Returns a User assigned to a Test Account account_user = User.objects.create_user(username='account_member', email='account_member@example.com', password='password',account=account) account_user.account=account return account_user
[docs] @pytest.fixture def test_red_style(db) -> Style: # Returns a Red Style test_red_style = Style.objects.create(name='Light Red') return test_red_style
[docs] @pytest.fixture def test_ship_unit_case_6(db) -> ShipUnit: # Returns a Case of 6 case_6 = ShipUnit.objects.create(ship_unit='Case of 6',qty='6') return case_6
[docs] @pytest.fixture def ship_unit_bottle(db) -> ShipUnit: # Returns a single bottle- Qty 1 del_unit_bottle = ShipUnit.objects.create(ship_unit='Bottle',qty='1') return del_unit_bottle
[docs] @pytest.fixture def test_75cl_bottle(db) -> Bottle: # Returns a 75cl Bottle Instance bottle = Bottle.objects.create(size='Bottle',cl='75') return bottle
[docs] @pytest.fixture def test_country(db) -> Country: # Returns France Country Instance test_country = Country.objects.create(country='France') return test_country
[docs] @pytest.fixture def test_location_types(db,account) -> LocationType: ''' Location types are currently the same across the whole system''' # Returns Rack Location Types test_rack = LocationType.objects.create(location_type ='Rack',location_max_qty=1,location_note='Can only hold 1 bottle') test_Bin001 = LocationType.objects.create(location_type ='Bin',location_max_qty=99,location_note='Location holding a mix of bottles') test_Case = LocationType.objects.create(location_type ='Case',location_max_qty=24,location_note='All bottles have the same wine (Addition) id ') test_Merchant = LocationType.objects.create(location_type ='Merchant',location_max_qty=999,location_note='External cellar') return test_location_types
[docs] @pytest.fixture def test_locations(db,account,test_location_types) -> Location: # Returns Rack Locations type = LocationType.objects.get(location_type ='Rack') test_rack = Location.objects.create(type = type,name = 'A1',location_qty=0,account=account) type = LocationType.objects.get(location_type = 'Bin') bin = Location.objects.create(type =type,name = 'Bin001',location_qty=0,account=account) type = LocationType.objects.get(location_type = 'Case') bin = Location.objects.create(type =type,name = 'Case001',location_qty=10,account=account) type = LocationType.objects.get(location_type = 'Merchant') bin = Location.objects.create(type = type,name = 'My Merchant',location_qty=0,account=account) return test_locations
[docs] @pytest.fixture def wine_order_case_6_red(db,account,test_red_style,test_ship_unit_case_6,test_75cl_bottle,test_country) -> Addition: # Returns an Addition instance - with : # addition_status = 'Ordered' # shipkey = form.cleaned_data.get('delivery_unit') # **** shipqty=ShipUnit.objects.get(ship_unit=shipkey).qty # **** del_unit_qty = form.cleaned_data.get('delivery_qty') # **** order.quantity=int(shipqty) * int(del_unit_qty) #create a note for the wine test_wine_order_case_6_red = Addition.objects.create(name='test_wine_order', account=account, style = test_red_style, country =test_country, year ='NV', size =test_75cl_bottle, price='120', source='wine_merchant', delivery_unit=test_ship_unit_case_6, delivery_qty='1', order_ref = 'order_ref1', ship_costs = '40', expected_delivery='2024-12-25', quantity = '6', ) return test_wine_order_case_6_red
[docs] @pytest.fixture def wine_retail_bottle(db,account,test_red_style,test_75cl_bottle,test_country,ship_unit_bottle) -> Addition: # Returns an Addition instance - with : # addition_status = 'Received' # shipkey = form.cleaned_data.get('delivery_unit') # **** shipqty=ShipUnit.objects.get(ship_unit=shipkey).qty # **** del_unit_qty = form.cleaned_data.get('delivery_qty') # **** order.quantity=int(shipqty) * int(del_unit_qty) #create a note for the wine retail_add_wine_bottle_red = Addition.objects.create(name='test_add_wine', account=account, style = test_red_style, country =test_country, year ='2024', size =test_75cl_bottle, price='8.99', source='M&S', delivery_unit=ship_unit_bottle, delivery_qty='1', order_ref = 'retail_addition', ship_costs = '0', expected_delivery= datetime.now(), addition_status = 'Received', quantity = '1', ) return retail_add_wine_bottle_red
[docs] @pytest.fixture def notes(wine_order_case_6_red): """Fixture for baked Notes model.""" a=baker.make(Notes,addition=wine_order_case_6_red) return a print('addition for notes =',a)
#@pytest.fixture #def wine_location_values(db,account,test_red_style,test_locationstest_ship_unit_case_6,test_75cl_bottle,test_country) -> Addition: # Returns an Addition instance - with : # addition_status = 'Ordered' # shipkey = form.cleaned_data.get('delivery_unit') # **** shipqty=ShipUnit.objects.get(ship_unit=shipkey).qty # **** del_unit_qty = form.cleaned_data.get('delivery_qty') # **** order.quantity=int(shipqty) * int(del_unit_qty) #create a note for the wine