Implemented fixtures & Implementing Resource pattern
This commit is contained in:
@@ -1,44 +1,68 @@
|
||||
from datetime import date
|
||||
|
||||
from account.models import Account
|
||||
from account.schemas import AccountCreate
|
||||
from account.schemas import AccountCreate, CategoryCreate
|
||||
|
||||
def inject_fixtures(session):
|
||||
for f in fixtures:
|
||||
if f['parent_path']:
|
||||
parent = Account.get_by_path(session, f['parent_path'])
|
||||
f['parent_account_id'] = parent.id
|
||||
else:
|
||||
f['parent_account_id'] = None
|
||||
del f['parent_path']
|
||||
for f in fixtures_account:
|
||||
f = prepare_dict(session, f)
|
||||
schema = AccountCreate(**f)
|
||||
Account.create(schema)
|
||||
Account.create(schema, session)
|
||||
|
||||
fixtures = [{
|
||||
for f in fixtures_category:
|
||||
f = prepare_dict(session, f)
|
||||
schema = CategoryCreate(**f)
|
||||
Account.create(schema, session)
|
||||
|
||||
def prepare_dict(session, entry):
|
||||
if entry['parent_path']:
|
||||
parent = Account.get_by_path(session, entry['parent_path'])
|
||||
entry['parent_account_id'] = parent.id
|
||||
else:
|
||||
entry['parent_account_id'] = None
|
||||
del entry['parent_path']
|
||||
return entry
|
||||
|
||||
fixtures_account = [
|
||||
{
|
||||
"name": "Current Assets",
|
||||
"parent_path": None,
|
||||
"type": "Asset"
|
||||
},{
|
||||
"type": "Asset",
|
||||
"opening_date": date(1970, 1, 1),
|
||||
},
|
||||
{
|
||||
"name": "Cash in Wallet",
|
||||
"parent_path": "/Accounts/Asset/",
|
||||
"parent_path": "/Accounts/Asset/Current Assets/",
|
||||
"type": "Asset",
|
||||
},{
|
||||
"opening_date": date(1970, 1, 1),
|
||||
},
|
||||
{
|
||||
"name": "Checking Account",
|
||||
"parent_path": "/Accounts/Asset/",
|
||||
"parent_path": "/Accounts/Asset/Current Assets/",
|
||||
"type": "Asset",
|
||||
},{
|
||||
"opening_date": date(1970, 1, 1),
|
||||
},
|
||||
{
|
||||
"name": "Savings Account",
|
||||
"parent_path": "/Accounts/Asset/",
|
||||
"parent_path": "/Accounts/Asset/Current Assets/",
|
||||
"type": "Asset",
|
||||
"opening_date": date(1970, 1, 1),
|
||||
},
|
||||
{
|
||||
"name": "Debt Accounts",
|
||||
"parent_path": None,
|
||||
"type": "Liability",
|
||||
"opening_date": date(1970, 1, 1),
|
||||
},
|
||||
{
|
||||
"name": "Credit Card",
|
||||
"parent_path": "/Accounts/Liability/",
|
||||
"parent_path": "/Accounts/Liability/Debt Accounts/",
|
||||
"type": "Liability",
|
||||
"opening_date": date(1970, 1, 1),
|
||||
},
|
||||
]
|
||||
|
||||
fixtures_category = [
|
||||
{
|
||||
"name": "Salary",
|
||||
"parent_path": None,
|
||||
@@ -61,12 +85,12 @@ fixtures = [{
|
||||
},
|
||||
{
|
||||
"name": "Rent",
|
||||
"parent_path": "/Categories/Expense/Home",
|
||||
"parent_path": "/Categories/Expense/Home/",
|
||||
"type": "Expense",
|
||||
},
|
||||
{
|
||||
"name": "Electricity",
|
||||
"parent_path": "/Categories/Expense/Home",
|
||||
"parent_path": "/Categories/Expense/Home/",
|
||||
"type": "Expense",
|
||||
},
|
||||
{
|
||||
@@ -78,11 +102,9 @@ fixtures = [{
|
||||
"name": "Groceries",
|
||||
"parent_path": None,
|
||||
"type": "Expense",
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
"""
|
||||
<accounts>
|
||||
<account type="9" name="">
|
||||
|
||||
Reference in New Issue
Block a user