-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix SDK unit tests and add UTC conversion to WazuhDBQueryGroupByVulnerability
class
#13230
Comments
Apart from the error I have already fixed in this issue's related PR (vulnerability unittest + UTC conversion), a new error appeared in the checks: output.txt
The It is only appearing in the CI machines. The test is passing in my local machine. I first supposed that the error could be related to dependencies, so I installed the same Wazuh and unittest requirements used by the CI machine in a clean Python virtual environment. Localhost: metadata: {'Python': '3.9.2', 'Platform': 'Linux-5.13.0-40-generic-x86_64-with-glibc2.31', 'Packages': {'pytest': '5.4.3', 'py': '1.11.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '2.1.1', 'aiohttp': '0.3.0', 'asyncio': '0.15.1', 'metadata': '2.0.1', 'trio': '0.7.0'}} CI: metadata: {'Python': '3.9.2', 'Platform': 'Linux-4.14.268-(...)x86_64-x86_64-with-glibc2.28', 'Packages': {'pytest': '5.4.3', 'py': '1.11.0', 'pluggy': '0.13.1'}, 'Plugins': {'aiohttp': '0.3.0', 'trio': '0.7.0', 'metadata': '2.0.1', 'html': '2.1.1', 'asyncio': '0.15.1'}} As we can see, the dependencies are the same and the test is failing in the CI machine and passing in my host. I have tested this again in my local host but using the same docker image used in the CI machine. This time, the error also appeared in local. After investigating this deeper, I have realized that some dependencies are missing or changed in the docker image (after https://github.com/wazuh/wazuh-jenkins/pull/3438). One of these changes has been the update of the As I said, the test only fails with the @pytest.mark.asyncio
async def test_response_init():
"""Test for the 'init' method that belongs to the Response class"""
event = asyncio.Event(loop=loop)
with patch('asyncio.Event', return_value=event):
response = cluster_common.Response()
assert response.received_response == event
assert response.content is None
async def test_response_read():
"""Test for the 'read' method that belongs to the Response class. This method waits until a response is received."""
with patch('asyncio.Event.wait') as wait_mock:
response = cluster_common.Response()
response.content = 'Testing'
assert await response.read() == 'Testing'
wait_mock.assert_called_once()
async def test_response_write():
"""Test for the 'write' method that belongs to the Response class. It sets the content of a response and its
availability."""
with patch('asyncio.Event.wait') as wait_mock:
with patch('asyncio.Event.set') as set_mock:
response = cluster_common.Response()
await response.read()
response.write(b"some content")
assert response.content == b"some content"
wait_mock.assert_called_once()
set_mock.assert_called_once() I saw that there were no With the previous conclusion, the test is fixed, but why was the test failing after the I have seen that the test was also failing when using
If we have a look at the pull request that closes the issue mentioned (issue 4700), we see that
This means that from version 3.8.0, there is no need to use the The Because of all these changes, our test case can fail, as its behavior has changed and now the As I said, adding the |
After merging 4.3 into master, the new
WazuhDBQueryGroupByVulnerability
class is using the old "timestamp to date" conversion.We should use the
get_date_from_timestamp
ofwazuh/core/utils.py
instead so new dates are indatetime
format and UTC timezone.Apart from this change, we also need to fix 2 framework unit tests that are failing in the master branch.
One of these errors is caused by the merge of 4.3 into master (vulnerability). The other error has to do with the enhancement of the Docker environment used to pass the framework's unit tests, as it was only tested on the 4.3 branch: https://github.com/wazuh/wazuh-jenkins/issues/3265.
Tests result:
B29956_pytest_framework.txt
Checks
Issue
WazuhDBQueryGroupByVulnerability
classwazuh/wazuh
framework/wazuh/core/cluster/tests/
&framework/wazuh/core/cluster/dapi/tests/
)framework/wazuh/core/tests/
)framework/wazuh/tests/
)framework/wazuh/rbac/tests/
)api/api/tests/
)api/test/integration/
):api/test/integration/mapping/integration_test_api_endpoints.json
)api/api/spec/spec.yaml
)framework/wazuh/core/exception.py
)CHANGELOG.md
)wazuh/wazuh-documentation
source/user-manual/api/equivalence.rst
)source/user-manual/api/rbac/reference.rst
)The text was updated successfully, but these errors were encountered: