Skip to content

Commit

Permalink
Schema Updates in Bulksignup, performance updates in search index in …
Browse files Browse the repository at this point in the history
…signup. (#97)

* Update tests

* Schema updates in bulk signup

* Fixed displayed village list

* Create index to improve performance while using

* update tests
  • Loading branch information
HemanthSai7 authored Aug 25, 2023
1 parent 0f20ddf commit 2eb56fd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion API/services/auth/AuthServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSign

invalid_users = []
valid_users = []
users_created = []

for user in zip(AADHAR_NOS,passwords):
userinfo = {
Expand All @@ -67,6 +68,7 @@ def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSign
userinfo["AADHAR"] = user[0]
userinfo["password"] = Auth.get_password_hash(user[1])
valid_users.append(userinfo)
users_created.append(user[0])

if len(valid_users)!=0:
DBQueries.insert_to_database("Auth", role_manager.user, valid_users) # saving user to database
Expand All @@ -75,7 +77,8 @@ def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSign
else:
response_result['status'] = f'failure'
response_result['message'] = [f'No users created']
response_result["message"].append(f"Users with these AADHAR NOs already exist: {invalid_users} hence aborting")

response_result['data'] = {"invalid_users":invalid_users, "valid_users":users_created}


def user_login(tokens: TokenSchema, form_data: UserAuth):
Expand Down
3 changes: 2 additions & 1 deletion API/services/db/utils/DBQueries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Queries script for the API. It is used to create the queries
that are used to interact with the database.
"""
import regex as re
from typing import Union, Tuple, List
from datetime import datetime

Expand Down Expand Up @@ -118,7 +119,7 @@ def list_database_names(cls)->list:
list: list of all database names
"""
return [db_names for db_names in DBConnection.get_client().list_database_names() if
db_names not in ['Auth']]
not (db_names == 'Auth' or db_names.startswith('test'))]

@classmethod
def create_db(cls, db_name:str, user_creds:str)->None:
Expand Down
2 changes: 2 additions & 0 deletions scripts/ttl.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
globaldb:PRIMARY> db.user.createIndex({"_ts":1}, {expireAfterSeconds: 10})

globaldb:PRIMARY> db.user.createIndex({"AADHAR":1})

globaldb:PRIMARY> db.user.getIndexes()

globaldb:PRIMARY> db.user.dropIndexes()
2 changes: 1 addition & 1 deletion tests/test_delete_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MyDeleteDatabaseTest(unittest.TestCase):
"role": f"{os.environ['ADMIN_ROLE']}"
}

params={"dbname":"test_db"}
params={"dbname":"db_test"}
DEL_VILLAGE_NAME=BASE_URL+"/ops/delete_database"
GET_VILLAGE_LIST=BASE_URL+"/api/get_village_list"
PUT_URL=BASE_URL+'/ops/update_village_list'
Expand Down
6 changes: 5 additions & 1 deletion tests/test_update_village_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyUpdateVillageListTest(unittest.TestCase):
"role": f"{os.environ['ADMIN_ROLE']}"
}

params={"dbname":"test_db"}
params={"dbname":"db_test"}

GET_VILLAGE_LIST=BASE_URL+"/api/get_village_list"
DEL_VILLAGE_NAME=BASE_URL+"/ops/delete_database"
Expand Down Expand Up @@ -50,6 +50,8 @@ def test_update_existing_village_owner(self):
else:
response=requests.put(MyUpdateVillageListTest.PUT_URL,headers=headers,params=MyUpdateVillageListTest.params)
response=requests.put(MyUpdateVillageListTest.PUT_URL,headers=headers,params=MyUpdateVillageListTest.params)

requests.delete(MyUpdateVillageListTest.DEL_VILLAGE_NAME,headers=headers,params=MyUpdateVillageListTest.params)
return self.assertEqual(response.status_code,409)

def test_update_new_village_owner(self):
Expand All @@ -67,6 +69,8 @@ def test_update_new_village_owner(self):
response=requests.put(MyUpdateVillageListTest.PUT_URL,headers=headers,params=MyUpdateVillageListTest.params)
else:
response=requests.put(MyUpdateVillageListTest.PUT_URL,headers=headers,params=MyUpdateVillageListTest.params)

requests.delete(MyUpdateVillageListTest.DEL_VILLAGE_NAME,headers=headers,params=MyUpdateVillageListTest.params)
return self.assertEqual(response.status_code,200)

def test_unauth(self):
Expand Down

0 comments on commit 2eb56fd

Please sign in to comment.