-
Notifications
You must be signed in to change notification settings - Fork 50
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
[REF] tests : Refactoring of the tests #296
base: master
Are you sure you want to change the base?
Conversation
714bd14
to
3cd2b53
Compare
Enhance Testing Framework, Refactor XML Parsing with etree, and Enforce Field Constraints. To streamline the testing process and reduce the burden of code reviews, this commit introduces a multitude of enhancements and refactors within the codebase. Key improvements include: - New tests for manifests and xml - A shift from regex-based to etree-based XML parsing - Implementation of strict field constraints - Added Extensive Tests: - Implemented numerous new tests to simplify testing and reduce review complexity. - Expanded coverage across multiple modules to ensure robustness. - Refactored XML Parsing: - Replaced regex-based parsing with `etree` from the `lxml` library for improved accuracy and maintainability. - Enhanced error handling and logging for XML processing. - Implemented `check_fields` and `FIELDS_NOT_TO_SET_DIRECTLY`: - Introduced the `check_fields` function to validate that certain fields are not set directly in XML data because those are readonly fields computed fields. - Defined `FIELDS_NOT_TO_SET_DIRECTLY` to specify fields across various model fields that should be defined in their related model. - Updated Manifest Validation: - Strengthened manifest checks to include mandatory keys and correct dependency ordering. - Ensured theme dependencies are listed last and dependencies are alphabetically sorted. These changes significantly improve the maintainability and reliability of the codebase by enhancing test coverage, ensuring proper XML handling, and enforcing strict field constraints. The refactored XML parsing with `etree` provides a more robust solution, while the `check_fields` mechanism safeguards against improper data manipulation. Enhanced manifest validations and logging facilitate smoother development and deployment processes.
3cd2b53
to
97142ec
Compare
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.
First pass 😴
@@ -78,7 +78,7 @@ def test_cloc_exclude_view(self): | |||
for module in self.installed_modules: | |||
for cloc_entry in c.modules.get(module, {}): | |||
message = "The view '%s' is counted in the maintenance lines. " % cloc_entry | |||
message += "Please add a '__cloc_exclude__' entry in 'ir_model_data'." | |||
message += "Please add a '__cloc_exclude__' entry in 'manifest'." |
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.
useless diff (still wrong and easier for possible conflicts aftewards)
"Wrong %s '%r' in manifest, it should be %s" % (key, value, expected_value), | ||
) | ||
self.assertIsInstance(value, expected_type, f"Wrong type for '{key}' in {module}, expected {expected_type}") | ||
if expected_value and key not in ['description']: |
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.
expected_value of description falsy (empty string). Why do you need it?
if expected_value and key not in ['description']: | |
if expected_value: |
) | ||
self.assertIsInstance(value, expected_type, f"Wrong type for '{key}' in {module}, expected {expected_type}") | ||
if expected_value and key not in ['description']: | ||
self.assertEqual(value, expected_value, f"Incorrect value for '{key}' in {module}") |
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.
self.assertEqual(value, expected_value, f"Incorrect value for '{key}' in {module}") | |
self.assertEqual(value, expected_value, f"Incorrect value for '{key}' in manifest of {module}") |
def _test_manifest_keys(self, module, manifest_data): | ||
super()._test_manifest_keys(module, manifest_data) | ||
for key in MANDATORY_KEYS: | ||
self.assertIn(key, manifest_data, "Missing key %s in manifest" % key) |
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.
This test was checking that the key was defined + the super was checking that no other unknown key is defined
def _validate_manifest(self, module, manifest_data): | ||
# Check manifest keys and values | ||
for key, expected_value in MANDATORY_KEYS.items(): | ||
value = manifest_data.get(key) |
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.
if not value, missing key
# if s.count("x_studio"): | ||
# _logger.warning("Please remove 'studio' from 'x_studio' in %s.", file_name) |
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.
This would be nice to restore, now that the fix of company_id is merged
field_models = root.xpath(f"//field[@model='{model}']") | ||
function_models = root.xpath(f"//function[@model='{model}']") | ||
if records and not field_models and not function_models and noupdate: |
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.
field_models = root.xpath(f"//field[@model='{model}']") | |
function_models = root.xpath(f"//function[@model='{model}']") | |
if records and not field_models and not function_models and noupdate: | |
if records and noupdate: |
for model in MODELS_NOT_TO_UPDATE: | ||
records = root.xpath(f"//record[@model='{model}']") | ||
field_models = root.xpath(f"//field[@model='{model}']") | ||
function_models = root.xpath(f"//function[@model='{model}']") | ||
if records and not field_models and not function_models and not noupdate: |
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.
I wonder if we shouldn't remove the MODELS_NOT_TO_UPDATE list and assume everything else should be noupdate (no huge list to maintain).
We just need to find records that are not from a model in the other list and not noupdate.
try: | ||
root = etree.fromstring(xml_content.encode('utf-8')) | ||
except etree.XMLSyntaxError as e: | ||
_logger.error("XML syntax error in file %s: %s", filename, e) | ||
return |
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.
Since we're using etree in almost all methods, this could be done once in the main one.
_logger.warning( | ||
"Model %s should not be updated, please add 'noupdate=\"1\"' in the header of %s.", | ||
model, | ||
filename, | ||
) | ||
|
||
def _check_useless_models(self, s, filename): | ||
def _check_useless_models(self, xml_content, filename): |
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.
This method can be removed in my opinion
Enhance Testing Framework, Refactor XML Parsing with etree, and Enforce Field Constraints. To streamline the testing process and reduce the burden of code reviews, this commit introduces a multitude of enhancements and refactors within the codebase. Key improvements include:
New tests for manifests and xml
A shift from regex-based to etree-based XML parsing
Implementation of strict field constraints
Added Extensive Tests:
Refactored XML Parsing:
etree
from thelxml
library for improved accuracy and maintainability.Implemented
check_fields
andFIELDS_NOT_TO_SET_DIRECTLY
:check_fields
function to validate that certain fields are not set directly in XML data because those are readonly fields computed fields.FIELDS_NOT_TO_SET_DIRECTLY
to specify fields across various model fields that should be defined in their related model.Updated Manifest Validation:
These changes significantly improve the maintainability and reliability of the codebase by enhancing test coverage, ensuring proper XML handling, and enforcing strict field constraints. The refactored XML parsing with
etree
provides a more robust solution, while thecheck_fields
mechanism safeguards against improper data manipulation. Enhanced manifest validations and logging facilitate smoother development and deployment processes.