Skip to content
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

Merged
merged 13 commits into from
Dec 19, 2019

Conversation

nribeka
Copy link
Contributor

@nribeka nribeka commented Oct 1, 2019

Fix #182.

This will add instance for repeat section.

@nribeka
Copy link
Contributor Author

nribeka commented Oct 1, 2019

@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-io
Copy link

codecov-io commented Oct 2, 2019

Codecov Report

Merging #380 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
pyxform/xls2json.py 78.71% <100%> (+0.13%) ⬆️
pyxform/section.py 96.22% <100%> (-1.58%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c131e55...8503d1b. Read the comment docs.

@nribeka nribeka marked this pull request as ready for review October 2, 2019 12:49
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())
Copy link
Contributor Author

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]?

ukanga
ukanga previously approved these changes Oct 2, 2019
Comment on lines +117 to +130
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))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

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 👯‍♂

Copy link
Contributor

@lognaturel lognaturel left a 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,
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it?

Copy link
Contributor

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?

@lognaturel
Copy link
Contributor

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 needs discussion.

@nribeka
Copy link
Contributor Author

nribeka commented Oct 3, 2019

This would also need input from @MartijnR.

@MartijnR
Copy link
Contributor

MartijnR commented Oct 3, 2019

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.

@craigappl
Copy link

@ukanga , note that we need to review the comments from today's session. Link

Copy link
Contributor

@lognaturel lognaturel left a 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.

@nribeka
Copy link
Contributor Author

nribeka commented Oct 24, 2019

@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.

@lognaturel lognaturel self-requested a review November 5, 2019 21:55
@lognaturel lognaturel dismissed their stale review November 5, 2019 21:55

Warning added

@lognaturel
Copy link
Contributor

I think you can see an example of verifying warnings with v1 tests in the test_language_warnings test.

@nribeka nribeka requested a review from lognaturel November 6, 2019 20:34
@nribeka
Copy link
Contributor Author

nribeka commented Nov 6, 2019

@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.

lognaturel
lognaturel previously approved these changes Nov 6, 2019
Copy link
Contributor

@lognaturel lognaturel left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a first repeat instance in addition to the template
7 participants