Skip to content
Snippets Groups Projects
Commit 295cc7bf authored by Saket Agrahari's avatar Saket Agrahari
Browse files

test case survey publisher v1

parent ed7298c1
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,6 @@ def db_budget_migration():
exceldata = parse_excel_data.fetch_budget_excel_data()
for nren, budget, year in exceldata:
budget_entry = model.BudgetEntry(
nren=nren, budget=budget, year=year)
session.merge(budget_entry)
......@@ -83,14 +82,18 @@ def db_funding_migration():
session.commit()
def _cli(config):
init_db(config)
db_budget_migration()
db_funding_migration()
@click.command()
@click.option('--config', type=click.STRING, default='config.json')
def cli(config):
app_config = load(open(config, 'r'))
print("survey-publisher-v1 starting")
init_db(app_config)
db_budget_migration()
db_funding_migration()
_cli(app_config)
if __name__ == "__main__":
......
......@@ -30,13 +30,3 @@ class Nrens(base_schema):
budgets = relationship('Budgets', back_populates='nren')
# class BudgetEntry(base_schema):
# # Session = sessionmaker(bind=engine)
# # session = Session()
#
# __tablename__ = 'budgets'
# session.query(Budget).all()
# id = sa.Column(sa.Integer, autoincrement=True)
# nren = sa.Column(sa.String(128), primary_key=True)
# budget = sa.Column(sa.String(128), nullable=True)
# year = sa.Column(sa.String(128), primary_key=True)
......@@ -6,6 +6,7 @@ import pytest
import compendium_v2
from compendium_v2 import db
from compendium_v2.db import model
from compendium_v2 import survey_db
from compendium_v2.survey_db import model as survey_model
from sqlalchemy import create_engine
......@@ -82,6 +83,33 @@ def test_budget_data():
budget=float(budget),
year=int(year))
)
with survey_db.session_scope() as session:
data = _test_data_csv("BudgetTestData.csv")
nrens = set()
budgets_data=[]
for row in data:
nren = row["nren"]
budget = row["budget"]
year = row["year"]
country_code = row["nren"]
nrens.add(nren)
budgets_data.append(
survey_model.Budgets(
budget=budget,
year=year,
country_code=country_code
)
)
for nren in nrens:
session.add(
survey_model.Nrens(
abbreviation=nren,
country_code= nren
))
session.add_all(budgets_data)
@pytest.fixture
......
File added
import os
from compendium_v2.publishers.survey_publisher_v1 import _cli
EXCEL_FILE = os.path.join(
os.path.dirname(__file__), "data",
"2021_Organisation_DataSeries.xlsx")
def test_publisher(client, mocker, dummy_config):
mocker.patch('compendium_v2.background_task.parse_excel_data.EXCEL_FILE',
return_value=EXCEL_FILE)
_cli(dummy_config)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment