-
Notifications
You must be signed in to change notification settings - Fork 51
Add unit tests for Meter Reading DocType #59
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
base: develop
Are you sure you want to change the base?
Add unit tests for Meter Reading DocType #59
Conversation
muruthigitau
left a comment
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.
Hey @Levinmunyelele,
I had a look at the Meter Reading tests and wanted to share some feedback and suggestions. Overall, things look pretty solid, but there are a few spots where we could tidy up the code and improve readability.
Happy to discuss or help out with any changes whenever you want!
🧩 General Observations
- ✅ Structure: The test suite is generally well-organized. Use of
setUpClassfor shared test setup is appropriate. - ✅ Testing Approach: A good balance between unit and integration tests is observed.
- ✅ Documentation: Docstrings are present and helpful, providing clear insight into the test intent.
Code Issues and Fixes
1. Syntax Error, Misplaced Logic, serial_no Handling & Missing customer Definition
def create_warranty_claim(...):
...
if not frappe.db.exists("Warranty Claim", ...):
create_warranty_claim(...)Issues:
- ❌ Syntax Error: Misplaced logic and conditional calls inside the function leads to infinite recursion and unreachable code.
- ❌
serial_noHandling:Noneor empty string values aren't handled, which may cause issues with validation or database constraints. - ❌ Missing
customerDefinition: Thecustomervariable is referenced but never initialized or passed into the function.
✅ Fixes:
- Move the
create_warranty_claim(...)calls outside the function to avoid logical/syntax errors. - Safely handle
serial_nowith:
"serial_no": serial_no or ""
# or
if serial_no:
doc.serial_no = serial_no- Define a
customerbefore using it:
2. Manual Setting of name Field
"name": "WC-001-TEST-MULTIPLE"Issue:
Manually setting name risks collisions since it's usually system-generated.
✅ Fix:
Avoid this unless:
- You're using
set_name=True - You ensure it's unique
3. ⚠️ Use of ignore_links=True
.insert(ignore_permissions=True, ignore_links=True)Issue:
Suppressing link validation may lead to inconsistent or invalid references in data.
✅ Fix:
Only use this in isolated tests. Prefer:
.insert(ignore_permissions=True)4. Improper Multi-line serial_no Usage
"serial_no": "SN001\nSN002\nSN004"Issue:
serial_no is likely a single Link field. Multi-line strings won’t work.
✅ Fix:
Use only a single valid serial number per warranty claim.
5. ⚠️ Missing Test Cleanup (tearDownClass)
Issue:
Without cleanup, tests leave behind residual data, which may cause interference between test runs.
✅ Fix:
Add cleanup logic
|
Hi @muruthigitau, I've implemented all your feedback:
Kindly review when you get a chance. Thank you |
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.
NOTE: 'crm' should not be removed from required_apps as it is used in the app
|
All updates done. Let me know if any further changes are needed. Thanks again. |
This PR adds unit tests for the Meter Reading DocType to ensure functionality and data integrity. Covers basic validations and business logic.