-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user pytests #206
Add user pytests #206
Conversation
Hey @sidravi1 @suzinyou I’ve done my best on adding pytests for the multi-user feature.
|
844011f
to
1b072ee
Compare
90abda2
to
17e704c
Compare
@pytest.mark.parametrize( | ||
"content_title, content_text, content_metadata", | ||
[("title 3", "test content 3", {})], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parametrize makes sense if we want to test multiple different combos of parameters, but
seems like we're just using one! Fine to keep it though I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Amir!! Left some suggestions/questions.
This is not part of this PR but I'm seeing this deprecation warning:
The method "utcnow" in class "datetime" is deprecated
Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)
# make content as user1 | ||
response = client.post( | ||
"/content", | ||
headers={"Authorization": f"Bearer {fullaccess_token}"}, | ||
json={ | ||
"content_title": content_title, | ||
"content_text": content_text, | ||
"content_language": "ENGLISH", | ||
"content_metadata": content_metadata, | ||
}, | ||
) | ||
assert response.status_code == 200 | ||
json_response = response.json() | ||
assert json_response["content_metadata"] == content_metadata | ||
assert "content_id" in json_response | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!! May I suggest breaking down this tests however?
Each comment defines what the next block of code is testing... ideally each test would
be that block of code! Because if we fail "try and fail to fetch content as user2" we
have no idea whether the rest of the logic works or not.
I think you can use something like the existing_content_id
fixture to achieve this.
Create a fixture like that using user 1, and reuse it for each unit test:
- User 1 can delete it (*although I think this is tested by the TestManageContent class?)
- User 2 can't get it
- User 2 can't edit it
- User 2 can't delete it
Yup, been ignoring it lol added a backlog ticket to fix this |
0181383
to
b9e9a51
Compare
b9e9a51
to
b41dae0
Compare
* add postgres vars to template.env for clarity of use * remove deprecated "version" tag from local docker-compose scripts * change fullaccess and readonly users to user1 and user2 with fullaccess permissions * clarify `NEXT_PUBLIC_BACKEND_URL` variable in api.ts * Add user_id column to ContentDB and update content endpoints. NOTE: user_id hardcoded into QA and WhatsApp endpoints - to be inferred from bearer token later. * Admin app: Show username in profile dropdown * Disable "readonly" tests. Will add back in next PR. * Fix mismatch between get_llm_answer() and its decorators' expectation of a "question" parameter * Undo dropping of the `content_idx` index. Fix source issue later. * Remove duplicated unused AccessLevel declaration in contents schema * Add user table to db * Update backend to use new users table * Change content table user_id column to foreign key * Update env var names * Fix "question" parameter in get_semantic_matches() to match its decorators' expectation * Hardcode QA endpoints to use "user1"s data. Will make dynamic in next PR. * Disable WhatsApp pytests - WhatsApp endpoint is broken due to no access to auth information * Make initial user-loading script standalone and use it in dev setup and update Dockerfile deployment * Make usernames environment variables too * Add user addition in DB to pytests * update default usernames to user1 and user2 * create_content() description fix * Use `.one()` instead of `.scalar_one()` and add MultipleResultsFound exception * Change "user-queries" table to "query". Prevents confusion with AAQ users. * Table "user-query-responses" -> "query-response" * Table "user-query-response-errors" -> "query-response-error" * Table "response_feedback" -> "query-response-feedback" * Table "content_feedback" -> "content-feedback" * Standardise migration file messages * Stardise migration file names (no functionality change) * Fix feedback tables index col names * Remove "User" prefix from Query, QueryResponse, QueryResponseError table models * Remove "User" prefix from content schemas * Add "retrieval_key" column to user table and update QA endpoints to be user-aware * Update typebot flow with "RETRIEVAL_KEY" wording * Update pytest * Add user_id column to query table and store which user's account each query is associated with * Update feedback endpoints to be user-aware * Catch rogue outdated "UserQueryBase" * Implementing hashing of keys and update DB and tests * update migration filename * add key updation endpoint * Make keys 32 bytes and remove unnecessary character count check * Remove unnecessary spaces in Edit page * BUGFIX: Background on playground is always white even after scroll * Add tags to WhatsApp and Auth endpoint routers * Add temporary password column and move auth env vars to main config.py * [temp] disable new key route to avoid circular import * Temp: Add non-generator async session maker * MAJOR: Auth now checks DB for user info and returns user_db if found. Fullaccess and readonly removed. * Remove mentions of access levels from docs * correctly close db sessions in auth * Remove "readonly" tests and test constructions * organise imports * Make "/key" rotator endpoint functional again (avoiding circular imports 😭) * change KeyResponse parameter * Give tests their own user id/name/password/retrieval key * Remove readonly as an accepted option for access_level * Move number of bytes to top of file * Remove leftover comments * Move username-password-key env vars to loading script instead of configs.py * Don't use catch-all "except Exception" * Use `get_sqlalchemy_async_engine()` with `with` directly in auth code to ensure sessions are closed correctly * Make username and key columns unique and remove MultipleResults errors * Remove leftover .aclose() statements * Make UD multi-user and update tests * add user_id to contentdb pretty print * Cleanup UD parameters and add keywords to function calls * fix migration version after rebase * add line length for ruff * Rename authentication functions * Combine migrations (#197) * Combine pre-multiuser migrations that could be combined * Combine multiuser migrations * standardise wording of migration * add date template for migration filenames * Add dates to migration filenames * Fix "NEXT_PUBLIC_BACKEND_URL" in api.ts (UD merge issue) * Fix merge issues * add names to foreign key migrations * fix auth on page * Google login (#205) * first go at google auth * fixed env vars * updated tests * removed print statement * updated script to add users * added stubs to requirements * deployment updates * Update admin_app/src/app/login/page.tsx Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * fixes from PR * fixes from PR * skipping type checking for google auth --------- Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * HOTFIX: Bring unsalted hashing back for retrieval keys * HOTFIX: Mention Google login client ID env var in dev docs * HOTFIX: env var name in api.ts * Key generation UI (#211) * Correct usage of "startIcon" in New buttons * Add API key generation to front-end * Move modals to components file and other improvements * Add link to integrations page in Playground API key popup * Remove mentions of "current key" for now * Make copy button visually responsive too * Improve spacing on new key modal * Clean up modal button margins * fix format * Add user pytests (#206) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> * Make dashboard multi-user + some admin app cleanup (#213) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture * Playground: Add type of search to user message display * Make dashboard functions filter on user_id * Playground: change "JSON" to "<json>" in error message response. * UD page: Make background white for now * move key_management tests to run last :) * Remove incorrect retrieval tests * improve query type formatting and use save button for ud rule --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * Add pytests to check user1-user2 overlap in retrieval and urgency detect * Update AWS terraform and secret loading (#217) * Change all instances of "retrieval key" to "api key" * Add new user and google client ID env vars to terraform and bootstrap * fix spacing error * [AAQ-482] Add custom embeddings as optional components (#201) * add embeddings * Update docker-compose * update embeddings app * Add make command * Add default embedding * Add docstring * add as an optional component * Fix UD migration issue * add embeddings endpoint to llm proxy * Update optional_components/embeddings/requirements.txt Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * update docker-compose * Remove completion endpoint * fix linting * Fix PR comments * change size of vector --------- Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * add workflow dispatch force redeployment to admin app cicd * fix command * add manual force creation of task def to all other cicd scripts --------- Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> Co-authored-by: lickem22 <44327443+lickem22@users.noreply.github.com> --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> Co-authored-by: lickem22 <44327443+lickem22@users.noreply.github.com>
* add postgres vars to template.env for clarity of use * remove deprecated "version" tag from local docker-compose scripts * change fullaccess and readonly users to user1 and user2 with fullaccess permissions * clarify `NEXT_PUBLIC_BACKEND_URL` variable in api.ts * Add user_id column to ContentDB and update content endpoints. NOTE: user_id hardcoded into QA and WhatsApp endpoints - to be inferred from bearer token later. * Admin app: Show username in profile dropdown * Disable "readonly" tests. Will add back in next PR. * Fix mismatch between get_llm_answer() and its decorators' expectation of a "question" parameter * Undo dropping of the `content_idx` index. Fix source issue later. * Remove duplicated unused AccessLevel declaration in contents schema * Add user table to db * Update backend to use new users table * Change content table user_id column to foreign key * Update env var names * Fix "question" parameter in get_semantic_matches() to match its decorators' expectation * Hardcode QA endpoints to use "user1"s data. Will make dynamic in next PR. * Disable WhatsApp pytests - WhatsApp endpoint is broken due to no access to auth information * Make initial user-loading script standalone and use it in dev setup and update Dockerfile deployment * Make usernames environment variables too * Add user addition in DB to pytests * update default usernames to user1 and user2 * create_content() description fix * Use `.one()` instead of `.scalar_one()` and add MultipleResultsFound exception * Change "user-queries" table to "query". Prevents confusion with AAQ users. * Table "user-query-responses" -> "query-response" * Table "user-query-response-errors" -> "query-response-error" * Table "response_feedback" -> "query-response-feedback" * Table "content_feedback" -> "content-feedback" * Standardise migration file messages * Stardise migration file names (no functionality change) * Fix feedback tables index col names * Remove "User" prefix from Query, QueryResponse, QueryResponseError table models * Remove "User" prefix from content schemas * Add "retrieval_key" column to user table and update QA endpoints to be user-aware * Update typebot flow with "RETRIEVAL_KEY" wording * Update pytest * Add user_id column to query table and store which user's account each query is associated with * Update feedback endpoints to be user-aware * Catch rogue outdated "UserQueryBase" * Implementing hashing of keys and update DB and tests * update migration filename * add key updation endpoint * Make keys 32 bytes and remove unnecessary character count check * Remove unnecessary spaces in Edit page * BUGFIX: Background on playground is always white even after scroll * Add tags to WhatsApp and Auth endpoint routers * Add temporary password column and move auth env vars to main config.py * [temp] disable new key route to avoid circular import * Temp: Add non-generator async session maker * MAJOR: Auth now checks DB for user info and returns user_db if found. Fullaccess and readonly removed. * Remove mentions of access levels from docs * correctly close db sessions in auth * Remove "readonly" tests and test constructions * organise imports * Make "/key" rotator endpoint functional again (avoiding circular imports 😭) * change KeyResponse parameter * Give tests their own user id/name/password/retrieval key * Remove readonly as an accepted option for access_level * Move number of bytes to top of file * Remove leftover comments * Move username-password-key env vars to loading script instead of configs.py * Don't use catch-all "except Exception" * Use `get_sqlalchemy_async_engine()` with `with` directly in auth code to ensure sessions are closed correctly * Make username and key columns unique and remove MultipleResults errors * Remove leftover .aclose() statements * Make UD multi-user and update tests * add user_id to contentdb pretty print * Cleanup UD parameters and add keywords to function calls * fix migration version after rebase * add line length for ruff * Rename authentication functions * Combine migrations (#197) * Combine pre-multiuser migrations that could be combined * Combine multiuser migrations * standardise wording of migration * add date template for migration filenames * Add dates to migration filenames * Fix "NEXT_PUBLIC_BACKEND_URL" in api.ts (UD merge issue) * Fix merge issues * add names to foreign key migrations * fix auth on page * Google login (#205) * first go at google auth * fixed env vars * updated tests * removed print statement * updated script to add users * added stubs to requirements * deployment updates * Update admin_app/src/app/login/page.tsx Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * fixes from PR * fixes from PR * skipping type checking for google auth --------- Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * HOTFIX: Bring unsalted hashing back for retrieval keys * HOTFIX: Mention Google login client ID env var in dev docs * HOTFIX: env var name in api.ts * Key generation UI (#211) * Correct usage of "startIcon" in New buttons * Add API key generation to front-end * Move modals to components file and other improvements * Add link to integrations page in Playground API key popup * Remove mentions of "current key" for now * Make copy button visually responsive too * Improve spacing on new key modal * Clean up modal button margins * fix format * Add user pytests (#206) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> * Make dashboard multi-user + some admin app cleanup (#213) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture * Playground: Add type of search to user message display * Make dashboard functions filter on user_id * Playground: change "JSON" to "<json>" in error message response. * UD page: Make background white for now * move key_management tests to run last :) * Remove incorrect retrieval tests * improve query type formatting and use save button for ud rule --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * Add pytests to check user1-user2 overlap in retrieval and urgency detect * Update AWS terraform and secret loading (#217) * Change all instances of "retrieval key" to "api key" * Add new user and google client ID env vars to terraform and bootstrap * fix spacing error * [AAQ-482] Add custom embeddings as optional components (#201) * add embeddings * Update docker-compose * update embeddings app * Add make command * Add default embedding * Add docstring * add as an optional component * Fix UD migration issue * add embeddings endpoint to llm proxy * Update optional_components/embeddings/requirements.txt Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * update docker-compose * Remove completion endpoint * fix linting * Fix PR comments * change size of vector --------- Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * add workflow dispatch force redeployment to admin app cicd * fix command * add manual force creation of task def to all other cicd scripts --------- Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> Co-authored-by: lickem22 <44327443+lickem22@users.noreply.github.com> --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> Co-authored-by: lickem22 <44327443+lickem22@users.noreply.github.com>
* add postgres vars to template.env for clarity of use * remove deprecated "version" tag from local docker-compose scripts * change fullaccess and readonly users to user1 and user2 with fullaccess permissions * clarify `NEXT_PUBLIC_BACKEND_URL` variable in api.ts * Add user_id column to ContentDB and update content endpoints. NOTE: user_id hardcoded into QA and WhatsApp endpoints - to be inferred from bearer token later. * Admin app: Show username in profile dropdown * Disable "readonly" tests. Will add back in next PR. * Fix mismatch between get_llm_answer() and its decorators' expectation of a "question" parameter * Undo dropping of the `content_idx` index. Fix source issue later. * Remove duplicated unused AccessLevel declaration in contents schema * Add user table to db * Update backend to use new users table * Change content table user_id column to foreign key * Update env var names * Fix "question" parameter in get_semantic_matches() to match its decorators' expectation * Hardcode QA endpoints to use "user1"s data. Will make dynamic in next PR. * Disable WhatsApp pytests - WhatsApp endpoint is broken due to no access to auth information * Make initial user-loading script standalone and use it in dev setup and update Dockerfile deployment * Make usernames environment variables too * Add user addition in DB to pytests * update default usernames to user1 and user2 * create_content() description fix * Use `.one()` instead of `.scalar_one()` and add MultipleResultsFound exception * Change "user-queries" table to "query". Prevents confusion with AAQ users. * Table "user-query-responses" -> "query-response" * Table "user-query-response-errors" -> "query-response-error" * Table "response_feedback" -> "query-response-feedback" * Table "content_feedback" -> "content-feedback" * Standardise migration file messages * Stardise migration file names (no functionality change) * Fix feedback tables index col names * Remove "User" prefix from Query, QueryResponse, QueryResponseError table models * Remove "User" prefix from content schemas * Add "retrieval_key" column to user table and update QA endpoints to be user-aware * Update typebot flow with "RETRIEVAL_KEY" wording * Update pytest * Add user_id column to query table and store which user's account each query is associated with * Update feedback endpoints to be user-aware * Catch rogue outdated "UserQueryBase" * Implementing hashing of keys and update DB and tests * update migration filename * add key updation endpoint * Make keys 32 bytes and remove unnecessary character count check * Remove unnecessary spaces in Edit page * BUGFIX: Background on playground is always white even after scroll * Add tags to WhatsApp and Auth endpoint routers * Add temporary password column and move auth env vars to main config.py * [temp] disable new key route to avoid circular import * Temp: Add non-generator async session maker * MAJOR: Auth now checks DB for user info and returns user_db if found. Fullaccess and readonly removed. * Remove mentions of access levels from docs * correctly close db sessions in auth * Remove "readonly" tests and test constructions * organise imports * Make "/key" rotator endpoint functional again (avoiding circular imports 😭) * change KeyResponse parameter * Give tests their own user id/name/password/retrieval key * Remove readonly as an accepted option for access_level * Move number of bytes to top of file * Remove leftover comments * Move username-password-key env vars to loading script instead of configs.py * Don't use catch-all "except Exception" * Use `get_sqlalchemy_async_engine()` with `with` directly in auth code to ensure sessions are closed correctly * Make username and key columns unique and remove MultipleResults errors * Remove leftover .aclose() statements * Make UD multi-user and update tests * add user_id to contentdb pretty print * Cleanup UD parameters and add keywords to function calls * fix migration version after rebase * add line length for ruff * Rename authentication functions * Combine migrations (#197) * Combine pre-multiuser migrations that could be combined * Combine multiuser migrations * standardise wording of migration * add date template for migration filenames * Add dates to migration filenames * Fix "NEXT_PUBLIC_BACKEND_URL" in api.ts (UD merge issue) * Add content tag models * Fix merge issues * add names to foreign key migrations * fix auth on page * Google login (#205) * first go at google auth * fixed env vars * updated tests * removed print statement * updated script to add users * added stubs to requirements * deployment updates * Update admin_app/src/app/login/page.tsx Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * fixes from PR * fixes from PR * skipping type checking for google auth --------- Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * HOTFIX: Bring unsalted hashing back for retrieval keys * HOTFIX: Mention Google login client ID env var in dev docs * HOTFIX: env var name in api.ts * Key generation UI (#211) * Correct usage of "startIcon" in New buttons * Add API key generation to front-end * Move modals to components file and other improvements * Add link to integrations page in Playground API key popup * Remove mentions of "current key" for now * Make copy button visually responsive too * Improve spacing on new key modal * Clean up modal button margins * fix format * Add user pytests (#206) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> * Add tags bar * Make dashboard multi-user + some admin app cleanup (#213) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture * Playground: Add type of search to user message display * Make dashboard functions filter on user_id * Playground: change "JSON" to "<json>" in error message response. * UD page: Make background white for now * move key_management tests to run last :) * Remove incorrect retrieval tests * improve query type formatting and use save button for ud rule --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * Fix rebase issues * Fix linting * Fix PR comments * Update setup.md * Add additional tests * Fix linting --------- Co-authored-by: amir_emami <amirali1376@gmail.com> Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com>
* add postgres vars to template.env for clarity of use * remove deprecated "version" tag from local docker-compose scripts * change fullaccess and readonly users to user1 and user2 with fullaccess permissions * clarify `NEXT_PUBLIC_BACKEND_URL` variable in api.ts * Add user_id column to ContentDB and update content endpoints. NOTE: user_id hardcoded into QA and WhatsApp endpoints - to be inferred from bearer token later. * Admin app: Show username in profile dropdown * Disable "readonly" tests. Will add back in next PR. * Fix mismatch between get_llm_answer() and its decorators' expectation of a "question" parameter * Undo dropping of the `content_idx` index. Fix source issue later. * Remove duplicated unused AccessLevel declaration in contents schema * Add user table to db * Update backend to use new users table * Change content table user_id column to foreign key * Update env var names * Fix "question" parameter in get_semantic_matches() to match its decorators' expectation * Hardcode QA endpoints to use "user1"s data. Will make dynamic in next PR. * Disable WhatsApp pytests - WhatsApp endpoint is broken due to no access to auth information * Make initial user-loading script standalone and use it in dev setup and update Dockerfile deployment * Make usernames environment variables too * Add user addition in DB to pytests * update default usernames to user1 and user2 * create_content() description fix * Use `.one()` instead of `.scalar_one()` and add MultipleResultsFound exception * Change "user-queries" table to "query". Prevents confusion with AAQ users. * Table "user-query-responses" -> "query-response" * Table "user-query-response-errors" -> "query-response-error" * Table "response_feedback" -> "query-response-feedback" * Table "content_feedback" -> "content-feedback" * Standardise migration file messages * Stardise migration file names (no functionality change) * Fix feedback tables index col names * Remove "User" prefix from Query, QueryResponse, QueryResponseError table models * Remove "User" prefix from content schemas * Add "retrieval_key" column to user table and update QA endpoints to be user-aware * Update typebot flow with "RETRIEVAL_KEY" wording * Update pytest * Add user_id column to query table and store which user's account each query is associated with * Update feedback endpoints to be user-aware * Catch rogue outdated "UserQueryBase" * Implementing hashing of keys and update DB and tests * update migration filename * add key updation endpoint * Make keys 32 bytes and remove unnecessary character count check * Remove unnecessary spaces in Edit page * BUGFIX: Background on playground is always white even after scroll * Add tags to WhatsApp and Auth endpoint routers * Add temporary password column and move auth env vars to main config.py * [temp] disable new key route to avoid circular import * Temp: Add non-generator async session maker * MAJOR: Auth now checks DB for user info and returns user_db if found. Fullaccess and readonly removed. * Remove mentions of access levels from docs * correctly close db sessions in auth * Remove "readonly" tests and test constructions * organise imports * Make "/key" rotator endpoint functional again (avoiding circular imports 😭) * change KeyResponse parameter * Give tests their own user id/name/password/retrieval key * Remove readonly as an accepted option for access_level * Move number of bytes to top of file * Remove leftover comments * Move username-password-key env vars to loading script instead of configs.py * Don't use catch-all "except Exception" * Use `get_sqlalchemy_async_engine()` with `with` directly in auth code to ensure sessions are closed correctly * Make username and key columns unique and remove MultipleResults errors * Remove leftover .aclose() statements * Make UD multi-user and update tests * add user_id to contentdb pretty print * Cleanup UD parameters and add keywords to function calls * fix migration version after rebase * add line length for ruff * Rename authentication functions * Combine migrations (#197) * Combine pre-multiuser migrations that could be combined * Combine multiuser migrations * standardise wording of migration * add date template for migration filenames * Add dates to migration filenames * Fix "NEXT_PUBLIC_BACKEND_URL" in api.ts (UD merge issue) * Fix merge issues * add names to foreign key migrations * fix auth on page * Google login (#205) * first go at google auth * fixed env vars * updated tests * removed print statement * updated script to add users * added stubs to requirements * deployment updates * Update admin_app/src/app/login/page.tsx Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * fixes from PR * fixes from PR * skipping type checking for google auth --------- Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * HOTFIX: Bring unsalted hashing back for retrieval keys * HOTFIX: Mention Google login client ID env var in dev docs * HOTFIX: env var name in api.ts * Key generation UI (#211) * Correct usage of "startIcon" in New buttons * Add API key generation to front-end * Move modals to components file and other improvements * Add link to integrations page in Playground API key popup * Remove mentions of "current key" for now * Make copy button visually responsive too * Improve spacing on new key modal * Clean up modal button margins * fix format * Add user pytests (#206) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> * Make dashboard multi-user + some admin app cleanup (#213) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture * Playground: Add type of search to user message display * Make dashboard functions filter on user_id * Playground: change "JSON" to "<json>" in error message response. * UD page: Make background white for now * move key_management tests to run last :) * Remove incorrect retrieval tests * improve query type formatting and use save button for ud rule --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * Add pytests to check user1-user2 overlap in retrieval and urgency detect * Update AWS terraform and secret loading (#217) * Change all instances of "retrieval key" to "api key" * Add new user and google client ID env vars to terraform and bootstrap * fix spacing error * [AAQ-482] Add custom embeddings as optional components (#201) * add embeddings * Update docker-compose * update embeddings app * Add make command * Add default embedding * Add docstring * add as an optional component * Fix UD migration issue * add embeddings endpoint to llm proxy * Update optional_components/embeddings/requirements.txt Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * update docker-compose * Remove completion endpoint * fix linting * Fix PR comments * change size of vector --------- Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * add workflow dispatch force redeployment to admin app cicd * fix command * add manual force creation of task def to all other cicd scripts --------- Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> Co-authored-by: lickem22 <44327443+lickem22@users.noreply.github.com> --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> Co-authored-by: lickem22 <44327443+lickem22@users.noreply.github.com>
* add postgres vars to template.env for clarity of use * remove deprecated "version" tag from local docker-compose scripts * change fullaccess and readonly users to user1 and user2 with fullaccess permissions * clarify `NEXT_PUBLIC_BACKEND_URL` variable in api.ts * Add user_id column to ContentDB and update content endpoints. NOTE: user_id hardcoded into QA and WhatsApp endpoints - to be inferred from bearer token later. * Admin app: Show username in profile dropdown * Disable "readonly" tests. Will add back in next PR. * Fix mismatch between get_llm_answer() and its decorators' expectation of a "question" parameter * Undo dropping of the `content_idx` index. Fix source issue later. * Remove duplicated unused AccessLevel declaration in contents schema * Add user table to db * Update backend to use new users table * Change content table user_id column to foreign key * Update env var names * Fix "question" parameter in get_semantic_matches() to match its decorators' expectation * Hardcode QA endpoints to use "user1"s data. Will make dynamic in next PR. * Disable WhatsApp pytests - WhatsApp endpoint is broken due to no access to auth information * Make initial user-loading script standalone and use it in dev setup and update Dockerfile deployment * Make usernames environment variables too * Add user addition in DB to pytests * update default usernames to user1 and user2 * create_content() description fix * Use `.one()` instead of `.scalar_one()` and add MultipleResultsFound exception * Change "user-queries" table to "query". Prevents confusion with AAQ users. * Table "user-query-responses" -> "query-response" * Table "user-query-response-errors" -> "query-response-error" * Table "response_feedback" -> "query-response-feedback" * Table "content_feedback" -> "content-feedback" * Standardise migration file messages * Stardise migration file names (no functionality change) * Fix feedback tables index col names * Remove "User" prefix from Query, QueryResponse, QueryResponseError table models * Remove "User" prefix from content schemas * Add "retrieval_key" column to user table and update QA endpoints to be user-aware * Update typebot flow with "RETRIEVAL_KEY" wording * Update pytest * Add user_id column to query table and store which user's account each query is associated with * Update feedback endpoints to be user-aware * Catch rogue outdated "UserQueryBase" * Implementing hashing of keys and update DB and tests * update migration filename * add key updation endpoint * Make keys 32 bytes and remove unnecessary character count check * Remove unnecessary spaces in Edit page * BUGFIX: Background on playground is always white even after scroll * Add tags to WhatsApp and Auth endpoint routers * Add temporary password column and move auth env vars to main config.py * [temp] disable new key route to avoid circular import * Temp: Add non-generator async session maker * MAJOR: Auth now checks DB for user info and returns user_db if found. Fullaccess and readonly removed. * Remove mentions of access levels from docs * correctly close db sessions in auth * Remove "readonly" tests and test constructions * organise imports * Make "/key" rotator endpoint functional again (avoiding circular imports 😭) * change KeyResponse parameter * Give tests their own user id/name/password/retrieval key * Remove readonly as an accepted option for access_level * Move number of bytes to top of file * Remove leftover comments * Move username-password-key env vars to loading script instead of configs.py * Don't use catch-all "except Exception" * Use `get_sqlalchemy_async_engine()` with `with` directly in auth code to ensure sessions are closed correctly * Make username and key columns unique and remove MultipleResults errors * Remove leftover .aclose() statements * Make UD multi-user and update tests * add user_id to contentdb pretty print * Cleanup UD parameters and add keywords to function calls * fix migration version after rebase * add line length for ruff * Rename authentication functions * Combine migrations (#197) * Combine pre-multiuser migrations that could be combined * Combine multiuser migrations * standardise wording of migration * add date template for migration filenames * Add dates to migration filenames * Fix "NEXT_PUBLIC_BACKEND_URL" in api.ts (UD merge issue) * Add content tag models * Fix merge issues * add names to foreign key migrations * fix auth on page * Google login (#205) * first go at google auth * fixed env vars * updated tests * removed print statement * updated script to add users * added stubs to requirements * deployment updates * Update admin_app/src/app/login/page.tsx Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * fixes from PR * fixes from PR * skipping type checking for google auth --------- Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * HOTFIX: Bring unsalted hashing back for retrieval keys * HOTFIX: Mention Google login client ID env var in dev docs * HOTFIX: env var name in api.ts * Key generation UI (#211) * Correct usage of "startIcon" in New buttons * Add API key generation to front-end * Move modals to components file and other improvements * Add link to integrations page in Playground API key popup * Remove mentions of "current key" for now * Make copy button visually responsive too * Improve spacing on new key modal * Clean up modal button margins * fix format * Add user pytests (#206) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> * Add tags bar * Make dashboard multi-user + some admin app cleanup (#213) * Add key management endpoint pytest * TEMP: Add test for user functions (not working due to async issue) * fix scope of asession in test_urgency_detect (future-proofing) * Fix user tests with async session * Add where to set/find login credentials to docs * Temporary fix for rotation endpoint test * Fix scope mismatch (some UD tests break) * Add multi-user tests for content CRUD * Add multi-user tests for UD CRUD + add fetch check first in delete endpoint * Add user2 token denial test to retrieval and UD detect * Put multi-user tests under a different class * fixed async tests in session scope issue * Make test user_ids integers to match new schema * Fix handling of user_ids in pytest * Separate content CRUD multi-user tests and use fixture * Separate UD CRUD multi-user tests and use fixture * Playground: Add type of search to user message display * Make dashboard functions filter on user_id * Playground: change "JSON" to "<json>" in error message response. * UD page: Make background white for now * move key_management tests to run last :) * Remove incorrect retrieval tests * improve query type formatting and use save button for ud rule --------- Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com> * Fix rebase issues * Add tags filter to landing * Fix position of tags in landing * merge main * Fix tags models * Update setup.md * Update setup.md * Add doc * Update admin_app/src/app/content/edit/page.tsx Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> * Fix tag add warning * Fix tags bar issues * Update add_content_to_db script * Update page.tsx * Add tags * remove changes from script --------- Co-authored-by: amir_emami <amirali1376@gmail.com> Co-authored-by: Amir Emami <41763233+amiraliemami@users.noreply.github.com> Co-authored-by: Sid Ravinutala <sid.ravi1@gmail.com> Co-authored-by: Suzin You <7042047+suzinyou@users.noreply.github.com>
Reviewer: @suzinyou
Estimate: 30mins
Ticket
Fixes: 518
Description
Goal
Add pytests for
How has this been tested?
make tests
in core_backendChecklist
Fill with
x
for completed. Delete any lines that are not relevant