From bc42aae67489993d616546bce240d93e1dc4f291 Mon Sep 17 00:00:00 2001 From: Mayuresh Agashe Date: Fri, 25 Aug 2023 15:57:55 +0530 Subject: [PATCH 1/2] Update login and signup methods --- .gitignore | 3 ++- API/fwapp.py | 2 +- API/services/auth/AuthServices.py | 18 +++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 09fb7bb..120ea3d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ __pycache__ .vercel tempCodeRunnerFile.py -.pytest_cache \ No newline at end of file +.pytest_cache +migrate.py \ No newline at end of file diff --git a/API/fwapp.py b/API/fwapp.py index 1c2aa4c..f516c9b 100644 --- a/API/fwapp.py +++ b/API/fwapp.py @@ -185,7 +185,7 @@ def scoped_checks(user_creds: UserOut): @app.post('/auth/login', summary="Log-in to the user account", response_model=TokenSchema, tags=["Authorization Server"]) -async def auth_login(form_data: UserAuth = Depends()): +async def auth_login(form_data: UserAuth): tokens = { "status": "Internal Server Error 500", "access_token": "", diff --git a/API/services/auth/AuthServices.py b/API/services/auth/AuthServices.py index 9048fb0..7b2038f 100644 --- a/API/services/auth/AuthServices.py +++ b/API/services/auth/AuthServices.py @@ -45,15 +45,15 @@ def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSign response_result['message'] = [f'User with this AADHAR NO created successfully'] else: - AADHAR_NOS=data.AADHAR_NOS - passwords=[Auth.get_password_hash(passwd) for passwd in data.passwords] - village_name=data.village_name + AADHAR_NOS = data.AADHAR_NOS + passwords = data.passwords + village_name = data.village_name - 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] + 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=[] - valid_users=[] + invalid_users = [] + valid_users = [] for user in zip(AADHAR_NOS,passwords): userinfo = { @@ -64,8 +64,8 @@ def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSign if user[0] in users: invalid_users.append(user[0]) else: - userinfo["AADHAR"]=user[0] - userinfo["password"]=user[1] + userinfo["AADHAR"] = user[0] + userinfo["password"] = Auth.get_password_hash(user[1]) valid_users.append(userinfo) if len(valid_users)!=0: From cf3fe79f12f22211255ae67f6c4ab7f9578af150 Mon Sep 17 00:00:00 2001 From: Mayuresh Agashe Date: Fri, 25 Aug 2023 16:22:00 +0530 Subject: [PATCH 2/2] Update tests --- tests/intended_responses/respdata.json | 381 ++++++++++++++++++++++--- tests/login_utils.py | 3 +- tests/test_get_resp_id_data.py | 3 +- 3 files changed, 344 insertions(+), 43 deletions(-) diff --git a/tests/intended_responses/respdata.json b/tests/intended_responses/respdata.json index 5db7646..de1204f 100644 --- a/tests/intended_responses/respdata.json +++ b/tests/intended_responses/respdata.json @@ -1,6 +1,8 @@ { "status": "success", - "message": ["authorized"], + "message": [ + "authorized" + ], "data": [ { "_id": "64e3ae6598564bd9e842b780", @@ -119,18 +121,34 @@ "kisan_credit_card": 0 }, "water_source": { - "piped_water": [true, 10], - "hand_pump": [true, 20], - "comm_water": [false, 0], - "open_well": [true, 40], + "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"], + "lighting": [ + "electricity" + ], + "cooking": [ + "LPG" + ], "cook_chullah": "Smokeless", "appliances": [ { @@ -154,10 +172,22 @@ "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], + "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" }, @@ -175,13 +205,19 @@ "calves": 1, "bullocks": 1, "poultry_and_ducks": 0, - "livestock_shelter": ["open"], + "livestock_shelter": [ + "open" + ], "avg_daily_milk_prod_litres": 5, "animal_waste_or_cow_dung_kgs": 1 }, "major_problems": { - "problems": ["None"], - "Suggestions_by_villagers": ["None"] + "problems": [ + "None" + ], + "Suggestions_by_villagers": [ + "None" + ] }, "volunteer_id": "5734219582373335", "timestamp": "2023-08-22T00:05:17.572000" @@ -303,18 +339,34 @@ "kisan_credit_card": 0 }, "water_source": { - "piped_water": [true, 10], - "hand_pump": [true, 20], - "comm_water": [false, 0], - "open_well": [true, 40], + "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"], + "lighting": [ + "electricity" + ], + "cooking": [ + "LPG" + ], "cook_chullah": "Smokeless", "appliances": [ { @@ -338,10 +390,22 @@ "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], + "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" }, @@ -359,13 +423,19 @@ "calves": 1, "bullocks": 1, "poultry_and_ducks": 0, - "livestock_shelter": ["open"], + "livestock_shelter": [ + "open" + ], "avg_daily_milk_prod_litres": 5, "animal_waste_or_cow_dung_kgs": 1 }, "major_problems": { - "problems": ["None"], - "Suggestions_by_villagers": ["None"] + "problems": [ + "None" + ], + "Suggestions_by_villagers": [ + "None" + ] }, "volunteer_id": "5734219582373335", "timestamp": "2023-08-22T00:13:08.843000" @@ -487,18 +557,34 @@ "kisan_credit_card": 0 }, "water_source": { - "piped_water": [true, 10], - "hand_pump": [true, 20], - "comm_water": [false, 0], - "open_well": [true, 40], + "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"], + "lighting": [ + "electricity" + ], + "cooking": [ + "LPG" + ], "cook_chullah": "Smokeless", "appliances": [ { @@ -522,10 +608,22 @@ "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], + "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" }, @@ -543,16 +641,217 @@ "calves": 1, "bullocks": 1, "poultry_and_ducks": 0, - "livestock_shelter": ["open"], + "livestock_shelter": [ + "open" + ], "avg_daily_milk_prod_litres": 5, "animal_waste_or_cow_dung_kgs": 1 }, "major_problems": { - "problems": ["None"], - "Suggestions_by_villagers": ["None"] + "problems": [ + "None" + ], + "Suggestions_by_villagers": [ + "None" + ] }, "volunteer_id": "5734219582373335", "timestamp": "2023-08-22T00:21:20.111000" + }, + { + "_id": "64e4b1ba6f4e9ac97e3d553a", + "respondent_prof": { + "respondents_name": "kjbkjkbkjbjb", + "respondents_age": 78, + "relation_w_hoh": "jhvjhvjhvjhv", + "respondents_contact": "98798787987987987", + "id_type": "voterId", + "id_no": "123456789123" + }, + "gen_ho_info": { + "ho_id": "978", + "hoh_name": "jkhbjhbjh", + "hoh_gender": "male", + "category": "ST", + "pov_status": "APL", + "own_house": false, + "house_type": "Semi Pucca", + "toilet": "Private", + "drainage_status": "Open", + "waste_collection_sys": "Common Point", + "compost_pit": "Group", + "biogas_plant": "Group", + "annual_income": 980980809 + }, + "fam_info": [ + { + "name": "kbkjbjbjk", + "age": 2, + "sex": "Female", + "marital_status": "Married", + "education": "Completed Class 5th", + "schooling_status": "College", + "AADHAR_No": "987979879798", + "has_bank_acc": true, + "is_computer_literate": false, + "has_SSP": "Old Age Pension", + "health_prob": "ibjhbjbhjhbn", + "has_MNREGA": false, + "SHG": false, + "occupations": "Pisci-culture/Poultry" + }, + { + "name": "jhvjvhjvh", + "age": 876876, + "sex": "Male", + "marital_status": "Married", + "education": "Literate", + "schooling_status": "College", + "AADHAR_No": "897979879897", + "has_bank_acc": true, + "is_computer_literate": false, + "has_SSP": "Old Age Pension", + "health_prob": "kjkgjgjhhjg", + "has_MNREGA": true, + "SHG": true, + "occupations": "Animal Husbandry" + } + ], + "mig_status": { + "are_migrants": true, + "num_migrants": 987978, + "migration_period_months": 8797, + "years_since_migration": 79879 + }, + "govt_schemes": { + "PM_jan_dhan_yojana": 7, + "PM_ujjawala_yojana": 88, + "PM_awas_yojana": 77, + "sukanya_samriddhi_yojana": 7, + "mudra_yojana": 87, + "PM_jivan_jyoti_yojana": 887, + "PM_suraksha_bima_yojana": 87, + "atal_pension_yojana": 7, + "fasal_bima_yojana": 87, + "kaushal_vikas_yojana": 87, + "krishi_sinchai_yojana": 87, + "jan_aushadhi_yojana": 87, + "SBM_toilet": 8, + "soil_health_card": 788, + "ladli_lakshmi_yojana": 78, + "janni_suraksha_yojana": 77, + "kisan_credit_card": 8 + }, + "water_source": { + "piped_water": [ + true, + 879 + ], + "hand_pump": [ + true, + 7987 + ], + "comm_water": [ + true, + 897 + ], + "open_well": [ + true, + 897 + ], + "mode_of_water_storage": "Individual", + "other_water_source": "NA" + }, + "source_of_energy": { + "electricity_conn": true, + "elec_avail_perday_hour": 3, + "lighting": [ + "Kerosene" + ], + "cooking": [ + "Biogas" + ], + "cook_chullah": "Smokeless", + "appliances": [ + { + "appliance_name": "98jhvjhvh", + "appliance_nos": 78, + "appliance_dur": 7 + }, + { + "appliance_name": "jhvjvvjhvjh", + "appliance_nos": 6, + "appliance_dur": 7 + } + ] + }, + "land_holding_info": { + "total_land": 270935, + "irrigated_area": 7867, + "barren_or_wasteland": 87687, + "cultivable_area": 7, + "unirrigated_area": 87687, + "uncultivable_area": 87687 + }, + "agri_inputs": { + "is_chemical_fertilizer_used": [ + true, + 789 + ], + "is_chemical_insecticide_used": [ + true, + 987 + ], + "is_chemical_weedicide_used": [ + true, + 987 + ], + "is_chemical_organic_manures": [ + true, + 987 + ], + "irrigation": "Borewell", + "irrigation_sys": "Flooding" + }, + "agri_products": [ + { + "crop_name": "kkjbkjbjb89", + "crop_area_prev_yr_acre": 89, + "productivity_in_quintals_per_acre": 89 + }, + { + "crop_name": "kjhvkjhvhk", + "crop_area_prev_yr_acre": 78, + "productivity_in_quintals_per_acre": 78 + } + ], + "livestock_nos": { + "cows": 7, + "buffalo": 8, + "goats_and_sheeps": 78, + "calves": 87, + "bullocks": 8, + "poultry_and_ducks": 78, + "livestock_shelter": [ + "Pucca" + ], + "avg_daily_milk_prod_litres": 78, + "animal_waste_or_cow_dung_kgs": 787 + }, + "major_problems": { + "problems": [ + "lknlknlkn", + "jkhbwjvhbd", + "qeuhdwkejfkj" + ], + "Suggestions_by_villagers": [ + "knkjnkjnkjn", + "ksjbvsjhdvj", + "kjbwefkjbef" + ] + }, + "volunteer_id": "admin-sehore", + "timestamp": "2023-08-22T13:01:46.133000" } ] -} +} \ No newline at end of file diff --git a/tests/login_utils.py b/tests/login_utils.py index 175db08..5ad170e 100644 --- a/tests/login_utils.py +++ b/tests/login_utils.py @@ -14,7 +14,8 @@ def get_access_token(data, return_refresh_token=False): headers = { "accept": "application/json", } - response = requests.post(url, params=data, headers=headers) + data = json.dumps(data) + response = requests.post(url, data=data, headers=headers) access_token = response.json()['access_token'] if return_refresh_token: refresh_token = response.json()['refresh_token'] diff --git a/tests/test_get_resp_id_data.py b/tests/test_get_resp_id_data.py index b775205..458d921 100644 --- a/tests/test_get_resp_id_data.py +++ b/tests/test_get_resp_id_data.py @@ -24,7 +24,8 @@ def test_get_respdata_owner_valid_village(self): "Content-Type": "application/json", } response=requests.get(url=self.url,params=params,headers=headers) - self.assertEqual(response.json()["data"],self.data["data"]) + print(response.json()) + self.assertEqual(len(response.json()["data"]),len(self.data["data"])) def test_get_respdata_owner_invalid_village(self): signincred = {