feat: trigger Open Food Facts lookup on manual barcode text search#2351
Open
Ewin7 wants to merge 3 commits into
Open
feat: trigger Open Food Facts lookup on manual barcode text search#2351Ewin7 wants to merge 3 commits into
Ewin7 wants to merge 3 commits into
Conversation
- Added logic to `search_name_fulltext` to detect 8,12,13,14 digit numeric strings - Searches through the existing `search_barcode` method - Fallback to standard full-text search if no barcode match is found - Added unit tests
| Searching for an 8-14 digit number in the name field should trigger the OFF API lookup | ||
| """ | ||
| self.client.get(self.url + '?name__search=1300000000000') | ||
| mock_fetch.assert_called_once_with('1300000000000') |
Member
There was a problem hiding this comment.
we could simplify the tests here, just mock search_barcode and only test that the correct parameters are passed, that search_barcode itself works is already tested somewhere else (plus one that checks that the search directly returns if the search found an ingredient)
Contributor
Author
There was a problem hiding this comment.
I updated the tests to mock search_barcode. I also updated the first test to verify the correct arguments are passed, and added a test to check if a barcode match is returned in the search response.
- Mock the search_barcode function instead of fetch_ingredient_from_off. - Assert barcode search is called with expected arguments - Added a test ensuring a barcode match is returned directly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Changes
search_name_fulltextinnutrition/api/filtersets.py. If the input is numeric and matches standard retail barcode lengths (8, 12, 13, 14 digits) the query is passed tosearch_barcode.nutrition/tests/test_search_api.py.Related Issue(s)