page_cache not working in test_missing_pre_or_code_query
What happened:
Fork and clone the repository to local. I ran the test with python3 -m test_howdoi. I get the following result.
Traceback (most recent call last):
File "/Users/XXX/Projects/howdoi/test_howdoi.py", line 270, in test_missing_pre_or_code_query
self.assertIn('XML elements present in a XML', output)
AssertionError: 'XML elements present in a XML' not found in '<people>\n <student>\n <name>John</name>\n </student>\n</people>\n'
What you expected to happen:
If the page_cache was working, the test should pass. However, for some reason, it is not using page_cache and fetching the latest answer from stackoverflow, which has different order compared to cached_html, resulting in test failure.
I believe the issue is that we are not properly patching the _get_result function during tests.
If you put print statements in the mocked function and also within the original _get_result call you will see this.
Run python -m nose test_howdoi:HowdoiTestCase.test_missing_pre_or_code_query and you'll see that the first time _get_result is called for the Google search it will use the page_cache, but the second time when we call it for the Stack Overflow answer the mocked function is not used.
My guess is that something about how we mock the function is not correct.
We may want to go back to the old way of mocking the function
https://github.com/gleitz/howdoi/commit/71c6809d2dc08e5db8fa1666a06ac976928d31e4#diff-9484a47cc2a1a27c6407e851130f059966530293a60a4093e0c2868fe6974206L55
Resolved the duckduckgo not found issue in the test_howdoi.py file by updating the old pacakges of duckduckgo to duckduckpy and now the duckduckgo issue in the testing file is gone, still having issue with the XML file like some parameters are being missing...