From a54a11c4a443a1b1a387468e148e362bf04313cb Mon Sep 17 00:00:00 2001 From: "G.Hemanth Sai" <73033596+HemanthSai7@users.noreply.github.com> Date: Mon, 21 Aug 2023 23:18:18 +0530 Subject: [PATCH] Fix json encoder issues and nested queries --- API/services/auth/AuthServices.py | 2 +- API/services/db/DBManipulation.py | 2 +- tests/intended_responses/fetch_fam_data.json | 291 ++--- tests/intended_responses/respdata.json | 1110 +++++++++++++++++ tests/intended_responses/respid_data.json | 23 - tests/login_utils.py | 8 +- tests/test_delete_database.py | 2 +- ...et_resp_id.py => test_get_resp_id_data.py} | 22 +- tests/test_update_village_list.py | 2 +- 9 files changed, 1247 insertions(+), 215 deletions(-) create mode 100644 tests/intended_responses/respdata.json delete mode 100644 tests/intended_responses/respid_data.json rename tests/{test_get_resp_id.py => test_get_resp_id_data.py} (80%) diff --git a/API/services/auth/AuthServices.py b/API/services/auth/AuthServices.py index 75ef80b..bc00293 100644 --- a/API/services/auth/AuthServices.py +++ b/API/services/auth/AuthServices.py @@ -49,7 +49,7 @@ def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSign passwords=[Auth.get_password_hash(passwd) for passwd in data.passwords] village_name=data.village_name - users=DBQueries.filtered_db_search("Auth",role_manager.user,["_id","password","village_name"],AADHAR={"$in":AADHAR_NOS}) + users=DBQueries.filtered_db_search("Auth",role_manager.user,["_id","password","village_name"],search_idxs={"AADHAR":{"$in":AADHAR_NOS}}) users=[user["AADHAR"] for user in users] invalid_users=[] diff --git a/API/services/db/DBManipulation.py b/API/services/db/DBManipulation.py index 7e8aeb1..0f78672 100644 --- a/API/services/db/DBManipulation.py +++ b/API/services/db/DBManipulation.py @@ -77,7 +77,7 @@ def fetch_from_db(response_result: dict, resp_data: str)->dict: result = DBQueries.retrieve_documents(db,collection_names["fam_data"]) return result - +@json_encoder({ObjectId: str}) def fetch_familydata(response_result: dict, village_name: str, respondent_id: str)->dict: """Wrapper function to fetch family data from the database. Args: diff --git a/tests/intended_responses/fetch_fam_data.json b/tests/intended_responses/fetch_fam_data.json index 8380924..1cfd097 100644 --- a/tests/intended_responses/fetch_fam_data.json +++ b/tests/intended_responses/fetch_fam_data.json @@ -1,176 +1,31 @@ { "status": "success", - "message": [ - "Authenticated" - ], + "message": ["Authenticated"], "data": { - "gen_ho_info": [ - { - "ho_id": "A1", - "hoh_name": "Dada", - "hoh_gender": "Male", - "category": "OBC", - "pov_status": "BPL", - "own_house": true, - "house_type": "pucca", - "toilet": "Private", - "drainage_status": "open", - "waste_collection_sys": "doorstep", - "compost_pit": "Individual", - "biogas_plant": "Group", - "annual_income": 120000 - } - ], - "agri_inputs": [ - { - "is_chemical_fertilizer_used": [ - true, - 5 - ], - "is_chemical_insecticide_used": [ - false, - 0 - ], - "is_chemical_weedicide_used": [ - false, - 0 - ], - "is_chemical_organic_manures": [ - false, - 0 - ], - "irrigation": "Open", - "irrigation_sys": "Open" - } - ], - "source_of_energy": [ - { - "electricity_conn": true, - "elec_avail_perday_hour": 12, - "lighting": [ - "electricity" - ], - "cooking": [ - "LPG" - ], - "cook_chullah": "Smokeless", - "appliances": [ - { - "appliance_name": "fan", - "appliance_nos": 2, - "appliance_dur": 5 - }, - { - "appliance_name": "bulb", - "appliance_nos": 2, - "appliance_dur": 5 - } - ] - } - ], - "land_holding_info": [ - { - "total_land": 2, - "irrigated_area": 0.5, - "barren_or_wasteland": 0.1, - "cultivable_area": 0.4, - "unirrigated_area": 0.3, - "uncultivable_area": 0.2 - } - ], - "water_source": [ - { - "piped_water": [ - true, - 10 - ], - "hand_pump": [ - true, - 20 - ], - "comm_water": [ - false, - 0 - ], - "open_well": [ - true, - 40 - ], - "mode_of_water_storage": "individual", - "other_water_source": "None" - } - ], - "agri_products": [ - { - "crop_name": "rice", - "crop_area_prev_yr_acre": 0.2, - "productivity_in_quintals_per_acre": 3 - } - ], - "livestock_nos": [ - { - "cows": 2, - "buffalo": 2, - "goats_and_sheeps": 0, - "calves": 1, - "bullocks": 1, - "poultry_and_ducks": 0, - "livestock_shelter": [ - "open" - ], - "avg_daily_milk_prod_litres": 5, - "animal_waste_or_cow_dung_kgs": 1 - } - ], - "major_problems": [ - { - "problems": [ - "None" - ], - "Suggestions_by_villagers": [ - "None" - ] - } - ], - "govt_schemes": [ - { - "PM_jan_dhan_yojana": 2, - "PM_ujjawala_yojana": 3, - "PM_awas_yojana": 2, - "sukanya_samriddhi_yojana": 3, - "mudra_yojana": 0, - "PM_jivan_jyoti_yojana": 0, - "PM_suraksha_bima_yojana": 0, - "atal_pension_yojana": 0, - "fasal_bima_yojana": 0, - "kaushal_vikas_yojana": 0, - "krishi_sinchai_yojana": 0, - "jan_aushadhi_yojana": 0, - "SBM_toilet": 0, - "soil_health_card": 0, - "ladli_lakshmi_yojana": 0, - "janni_suraksha_yojana": 0, - "kisan_credit_card": 0 - } - ], - "respondent_prof": [ - { - "respondents_name": "Hemanth", - "respondents_age": 20, - "relation_w_hoh": "Son", - "respondents_contact": "8479239724", - "id_type": "AC", - "id_no": "test" - } - ], - "mig_status": [ - { - "are_migrants": false, - "num_migrants": 0, - "migration_period_months": 0, - "years_since_migration": 0 - } - ], + "_id": "64e37e96588d2c453b5694e4", + "respondent_prof": { + "respondents_name": "Hemanth", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "test" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, "fam_info": [ { "name": "Mayuresh", @@ -237,7 +92,97 @@ "occupations": "Student" } ], - "filled_by": "5734219582373335", - "filled_time": "2023-02-17T13:16:37.888000" + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T15:11:18.182000" } -} \ No newline at end of file +} diff --git a/tests/intended_responses/respdata.json b/tests/intended_responses/respdata.json new file mode 100644 index 0000000..ecc6b89 --- /dev/null +++ b/tests/intended_responses/respdata.json @@ -0,0 +1,1110 @@ +{ + "status": "success", + "message": ["authorized"], + "data": [ + { + "_id": "64e37e96588d2c453b5694e4", + "respondent_prof": { + "respondents_name": "Hemanth", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "test" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, + "fam_info": [ + { + "name": "Mayuresh", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "1234", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Anmol", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "test_sub", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Hemanth", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "3456", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Gargi", + "age": 20, + "sex": "Female", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "4567", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + } + ], + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T15:11:18.182000" + }, + { + "_id": "64e3939ece795f00bc33d41b", + "respondent_prof": { + "respondents_name": "Hemanth", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "8523705708935799" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, + "fam_info": [ + { + "name": "Mayuresh", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "1234", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Anmol", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "2345", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Hemanth", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "3456", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Gargi", + "age": 20, + "sex": "Female", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "4567", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + } + ], + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T22:11:02.181000" + }, + { + "_id": "64e3939fce795f00bc33d41c", + "respondent_prof": { + "respondents_name": "Hemanth", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "791228828148196" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, + "fam_info": [ + { + "name": "Mayuresh", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "1234", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Anmol", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "2345", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Hemanth", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "3456", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Gargi", + "age": 20, + "sex": "Female", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "4567", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + } + ], + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T22:11:03.209000" + }, + { + "_id": "64e393acce795f00bc33d41d", + "respondent_prof": { + "respondents_name": "Hemanth", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "801283712946576" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, + "fam_info": [ + { + "name": "Mayuresh", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "1234", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Anmol", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "2345", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Hemanth", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "3456", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Gargi", + "age": 20, + "sex": "Female", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "4567", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + } + ], + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T22:11:16.924000" + }, + { + "_id": "64e39669680494c663ce5d0e", + "respondent_prof": { + "respondents_name": "string", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "string2" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, + "fam_info": [ + { + "name": "Mayuresh", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "1234", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Anmol", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "2345", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Hemanth", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "3456", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Gargi", + "age": 20, + "sex": "Female", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "4567", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + } + ], + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T22:22:57.910000" + }, + { + "_id": "64e396ae680494c663ce5d0f", + "respondent_prof": { + "respondents_name": "string", + "respondents_age": 20, + "relation_w_hoh": "Son", + "respondents_contact": "8479239724", + "id_type": "AC", + "id_no": "string3" + }, + "gen_ho_info": { + "ho_id": "A1", + "hoh_name": "Dada", + "hoh_gender": "Male", + "category": "OBC", + "pov_status": "BPL", + "own_house": true, + "house_type": "pucca", + "toilet": "Private", + "drainage_status": "open", + "waste_collection_sys": "doorstep", + "compost_pit": "Individual", + "biogas_plant": "Group", + "annual_income": 120000 + }, + "fam_info": [ + { + "name": "Mayuresh", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "1234", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Anmol", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "2345", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Hemanth", + "age": 20, + "sex": "Male", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "3456", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + }, + { + "name": "Gargi", + "age": 20, + "sex": "Female", + "marital_status": "U", + "education": "College", + "schooling_status": "3 year", + "AADHAR_No": "4567", + "has_bank_acc": true, + "is_computer_literate": true, + "has_SSP": "no pension", + "health_prob": "None", + "has_MNREGA": true, + "SHG": true, + "occupations": "Student" + } + ], + "mig_status": { + "are_migrants": false, + "num_migrants": 0, + "migration_period_months": 0, + "years_since_migration": 0 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 2, + "PM_ujjawala_yojana": 3, + "PM_awas_yojana": 2, + "sukanya_samriddhi_yojana": 3, + "mudra_yojana": 0, + "PM_jivan_jyoti_yojana": 0, + "PM_suraksha_bima_yojana": 0, + "atal_pension_yojana": 0, + "fasal_bima_yojana": 0, + "kaushal_vikas_yojana": 0, + "krishi_sinchai_yojana": 0, + "jan_aushadhi_yojana": 0, + "SBM_toilet": 0, + "soil_health_card": 0, + "ladli_lakshmi_yojana": 0, + "janni_suraksha_yojana": 0, + "kisan_credit_card": 0 + }, + "water_source": { + "piped_water": [true, 10], + "hand_pump": [true, 20], + "comm_water": [false, 0], + "open_well": [true, 40], + "mode_of_water_storage": "individual", + "other_water_source": "None" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 12, + "lighting": ["electricity"], + "cooking": ["LPG"], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "fan", + "appliance_nos": 2, + "appliance_dur": 5 + }, + { + "appliance_name": "bulb", + "appliance_nos": 2, + "appliance_dur": 5 + } + ] + }, + "land_holding_info": { + "total_land": 2, + "irrigated_area": 0.5, + "barren_or_wasteland": 0.1, + "cultivable_area": 0.4, + "unirrigated_area": 0.3, + "uncultivable_area": 0.2 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [true, 5], + "is_chemical_insecticide_used": [false, 0], + "is_chemical_weedicide_used": [false, 0], + "is_chemical_organic_manures": [false, 0], + "irrigation": "Open", + "irrigation_sys": "Open" + }, + "agri_products": [ + { + "crop_name": "rice", + "crop_area_prev_yr_acre": 0.2, + "productivity_in_quintals_per_acre": 3 + } + ], + "livestock_nos": { + "cows": 2, + "buffalo": 2, + "goats_and_sheeps": 0, + "calves": 1, + "bullocks": 1, + "poultry_and_ducks": 0, + "livestock_shelter": ["open"], + "avg_daily_milk_prod_litres": 5, + "animal_waste_or_cow_dung_kgs": 1 + }, + "major_problems": { + "problems": ["None"], + "Suggestions_by_villagers": ["None"] + }, + "volunteer_id": "5734219582373335", + "timestamp": "2023-08-21T22:24:06.170000" + } + ] +} diff --git a/tests/intended_responses/respid_data.json b/tests/intended_responses/respid_data.json deleted file mode 100644 index 658648e..0000000 --- a/tests/intended_responses/respid_data.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "user_ids": [ - "123412341234", - "012345678999", - "121212121212", - "121212121212", - "123412341235", - "123456789101", - "VIV1234567", - "102192837465", - "ZAS12345", - "111111115", - "111111116", - "111111117", - "111111118", - "111111119", - "873912790318", - "448003990988988", - "516329145259208", - "327247887001101", - "645574464113240" - ] -} \ No newline at end of file diff --git a/tests/login_utils.py b/tests/login_utils.py index 175db08..5b8dd39 100644 --- a/tests/login_utils.py +++ b/tests/login_utils.py @@ -1,11 +1,11 @@ import json import requests -# from dotenv import load_dotenv -# load_dotenv() +from dotenv import load_dotenv +load_dotenv() -BASE_URL = "https://ubaformapi-git-prod-fastapis-build.vercel.app" # for GitHub actions -# BASE_URL = "http://127.0.0.1:8000" # for testing locally +# BASE_URL = "https://ubaformapi-git-prod-fastapis-build.vercel.app" # for GitHub actions +BASE_URL = "http://127.0.0.1:8000" # for testing locally # BASE_URL = "https://ubaformapi-git-fastapi01000andpydanticv2c-80d502-fastapis-build.vercel.app" diff --git a/tests/test_delete_database.py b/tests/test_delete_database.py index 6c4eff1..aeca320 100644 --- a/tests/test_delete_database.py +++ b/tests/test_delete_database.py @@ -15,7 +15,7 @@ class MyDeleteDatabaseTest(unittest.TestCase): params={"dbname":"test_db"} DEL_VILLAGE_NAME=BASE_URL+"/ops/delete_database" - GET_VILLAGE_LIST=BASE_URL+"/ops/get_village_list" + GET_VILLAGE_LIST=BASE_URL+"/api/get_village_list" PUT_URL=BASE_URL+'/ops/update_village_list' def test_delete_database_user(self): diff --git a/tests/test_get_resp_id.py b/tests/test_get_resp_id_data.py similarity index 80% rename from tests/test_get_resp_id.py rename to tests/test_get_resp_id_data.py index 06517f6..fcc947f 100644 --- a/tests/test_get_resp_id.py +++ b/tests/test_get_resp_id_data.py @@ -5,35 +5,35 @@ from login_utils import get_access_token, BASE_URL class MyGetRespIDTestCase(unittest.TestCase): - url=BASE_URL+"/api/get_respid_list" + url=BASE_URL+"/api/get_respdata_list" - with open("tests/intended_responses/respid_data.json","r") as f: + with open("tests/intended_responses/respdata.json","r") as f: data=json.load(f) - def test_get_respid_owner_valid_village(self): + def test_get_respdata_owner_valid_village(self): signincred = { "AADHAR_NO": f"{os.environ['ADMIN_ID']}", "password": f"{os.environ['ADMIN_PWD']}", "village_name": f"{os.environ['ADMIN_VILLAGE_NAME']}", "role": f"{os.environ['OWNER_ROLE']}" } - params={"date":"27-02-2023","village_name":"Sehore"} + params={"date":"2023-08-21","village_name":"Sehore"} headers={ "accept":"application/json", "Authorization": f"Bearer {get_access_token(signincred)}", "Content-Type": "application/json", } response=requests.get(url=self.url,params=params,headers=headers) - self.assertEqual(response.json()["data"],self.data) + self.assertEqual(response.json(),self.data) - def test_get_respid_owner_invalid_village(self): + def test_get_respdata_owner_invalid_village(self): signincred = { "AADHAR_NO": f"{os.environ['ADMIN_ID']}", "password": f"{os.environ['ADMIN_PWD']}", "village_name": f"{os.environ['ADMIN_VILLAGE_NAME']}", "role": f"{os.environ['OWNER_ROLE']}" } - params={"date":"27-02-2023","village_name":"villageDoesNotExist"} + params={"date":"2023-08-21","village_name":"villageDoesNotExist"} headers={ "accept":"application/json", "Authorization": f"Bearer {get_access_token(signincred)}", @@ -42,7 +42,7 @@ def test_get_respid_owner_invalid_village(self): response=requests.get(url=self.url,params=params,headers=headers) self.assertEqual(response.status_code,400) - def test_get_respid_admin(self): + def test_get_respdata_admin(self): signincred = { "AADHAR_NO": f"{os.environ['ADMIN_ID']}", "password": f"{os.environ['ADMIN_PWD']}", @@ -50,16 +50,16 @@ def test_get_respid_admin(self): "role": f"{os.environ['ADMIN_ROLE']}" } - params={"date":"27-02-2023","village_name":"None"} + params={"date":"2023-08-21","village_name":"None"} headers = { "accept": "application/json", "Authorization": f"Bearer {get_access_token(signincred)}", "Content-Type": "application/json", } response=requests.get(url=self.url,params=params,headers=headers) - self.assertEqual(response.json()["data"],self.data) + self.assertEqual(response.json(),self.data) - def test_get_respid_user(self): + def test_get_respdata_user(self): signincred = { "AADHAR_NO": f"{os.environ['ADMIN_ID']}", "password": f"{os.environ['ADMIN_PWD']}", diff --git a/tests/test_update_village_list.py b/tests/test_update_village_list.py index f15bfb2..b84b546 100644 --- a/tests/test_update_village_list.py +++ b/tests/test_update_village_list.py @@ -14,7 +14,7 @@ class MyUpdateVillageListTest(unittest.TestCase): params={"dbname":"test_db"} - GET_VILLAGE_LIST=BASE_URL+"/ops/get_village_list" + GET_VILLAGE_LIST=BASE_URL+"/api/get_village_list" DEL_VILLAGE_NAME=BASE_URL+"/ops/delete_database" PUT_URL=BASE_URL+'/ops/update_village_list'