-
Notifications
You must be signed in to change notification settings - Fork 138
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
Adding repeat instance to the model for repeat #380
Conversation
@lognaturel 2 failed tests. The tests is counting number of elements in the model which obviously going to fail because we're adding new elements to the model. I'm just wondering if this is what we're looking for. |
Codecov Report
@@ Coverage Diff @@
## master #380 +/- ##
==========================================
+ Coverage 82.71% 82.75% +0.03%
==========================================
Files 23 23
Lines 3304 3323 +19
Branches 776 781 +5
==========================================
+ Hits 2733 2750 +17
- Misses 429 430 +1
- Partials 142 143 +1
Continue to review full report at Codecov.
|
result.appendChild(child.xml_instance(append_template=append_template)) | ||
if append_template and repeating_template: | ||
append_template = not append_template | ||
result.insertBefore(repeating_template, result._get_lastChild()) |
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.
result._get_lastChild()
vs result.childNodes[-1]
?
section_template = '<section jr:template="">' | ||
self.assertEqual(1, survey_xml.count(section_template)) | ||
repeat_a_template = '<repeat_a jr:template="">' | ||
self.assertEqual(1, survey_xml.count(repeat_a_template)) | ||
repeat_b_template = '<repeat_b jr:template="">' | ||
self.assertEqual(1, survey_xml.count(repeat_b_template)) | ||
|
||
section_instance = "<section>" | ||
self.assertEqual(1, survey_xml.count(section_instance)) | ||
repeat_a_instance = "<repeat_a>" | ||
self.assertEqual(1, survey_xml.count(repeat_a_instance)) | ||
repeat_b_instance = "<repeat_b>" | ||
self.assertEqual(1, survey_xml.count(repeat_b_instance)) | ||
|
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.
pyxform/pyxform/tests_v1/pyxform_test_case.py
Line 298 in 077972c
def assertContains(self, content, text, count=None, msg_prefix=""): |
PyxformTestCase.assertContains()
does accept a count
parameter that does achieve the same result:
self.assertContains(survey_xml, "<repeat_b>", 1)
This works, it's fine too.
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.
Ah I didn't know about that. I just assume to use the equality assertion 👯♂
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've only had a chance for a really surface look so far but the tests look great!
@@ -104,11 +120,11 @@ def xml_control(self): | |||
|
|||
# I'm anal about matching function signatures when overriding a function, |
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 comment is no longer relevant, right?
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.
Remove it?
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 was about overriding xml_instance
and the name has now changed, right? So yes, the comment should be removed. It's also looking to me like neither this method nor generate_repeating_template
need to have a **kwargs
parameter, is that right?
I talked to @seadowg about this who pointed out that it's quite likely form designers are currently using repeats in Collect to represent 0 or more of a thing (rather than 1 or more). For example, if the desire is to collect information about children or siblings, it's quite likely that the flow of getting prompted initially about whether or not to add a repeat and potentially saying no is actually the right flow. I don't know exactly what to do about this now. Marking as |
This would also need input from @MartijnR. |
Enketo creates the first repeat automatically (and has been since 2012). In the past users have expressed a desire to have 0, but I believe this has been addressed sufficiently by introducing support for repeat-count and allowing the first repeat to be deleted manually (which initially wasn't possible). Since then, here have been no issues reported. If it is important to (be able to) start with 0, I agree we need to address that though. |
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.
We have agreed in #182 to issue a warning about the behavior change and link out to some documentation.
- @lognaturel draft documentation
- @nribeka add warning when a form definition contains one or more repeat
We've agreed to add a warning and some documentation.
@lognaturel or @ukanga do you guys aware of way to do warning assertions in the v1? There's an old test that assert the warning, but it's the old unit test. |
I think you can see an example of verifying warnings with v1 tests in the |
@lognaturel I just checked that unit tests and the warning testing will not work on this use case because the warning is generated when we parse the xls to json, but the v1 tests doesn't use the same function. It's using custom function to convert the md to json. |
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'm comfortable not having an explicit test for the warning. I think we'll remove it in a few months anyway and it's very easy to manually verify.
Fix #182.
This will add instance for repeat section.