Add import_metadata method#145
Conversation
|
Thanks for your contribution. I'll take a look tomorrow 👍 |
pwildenhain
left a comment
There was a problem hiding this comment.
Thanks for jumping in the project! 🙇🏻♂️
See the comments below 👁️ for potential changes.
Lastly, if you run pip install -r dev-requirements.txt and then run pytest it should point out the exact styling/linting issues you're running into here. If you can address those as well, then this will be good to merge 💪🏻
| self.assertIn("error", exc.args[0]) | ||
|
|
||
| @responses.activate | ||
| def test_import_metadata(self): |
There was a problem hiding this comment.
I'm happy with this test 👍🏻
There was a problem hiding this comment.
I have been experimenting with additional tests and found some weird behavior, of which I suspect is is due to the test setup as it works with other redcap servers. Do you have an idea why the following test might fail?
@responses.activate
def test_import_reduced_metadata(self):
"Test import of a reduced set of metadata"
self.add_normalproject_response()
data = self.reg_proj.export_metadata()
# reducing the metadata
data = data[0:1]
d = self.reg_proj.import_metadata(data)
# this should return the reduced set of metadata, but instead returns the full set of metadata when running on the test server
self.assertEqual(len(d), len(data))| if hasattr(to_import, "to_csv"): | ||
| # We'll assume it's a df | ||
| buf = StringIO() | ||
| to_import.to_csv(buf, index=False) | ||
| payload["data"] = buf.getvalue() | ||
| buf.close() | ||
| format = "csv" | ||
| elif format == "json": | ||
| payload["data"] = json.dumps(to_import, separators=(",", ":")) | ||
| else: | ||
| # don't do anything to csv/xml | ||
| payload["data"] = to_import |
There was a problem hiding this comment.
Thanks for being consistent with how the Project.import_records imports data.
Would you be open to adding a private helper method Project._add_import_data (or something to that effect) that basically accomplishes the highlighted section above? Since the code is exactly the same, it probably makes sense to abstract it at this point.
There was a problem hiding this comment.
I did add a utility method do initialize the payload for record and metadata. However since the code was not 100% identical i had to add the data type as another input to that helper function. What do you think about this?
|
Thanks for pointing out the next steps to resolve the test issues. One of them seems to be the number of lines in the |
If you don't mind, that would be great! As for the test failure....this is such great work, I really wouldn't want to hold it up. Do you know if there is a way that we can mark this test as expected to fail? Even just commenting it out for now would be fine. As long as we file an issue to address it later. |
To be honest I am not sure how you would do this in a good manner as it would require splitting the |
I added the test and configured unittest to skip it as I don't think it should be marked as expected to fail. |
Totally acceptable 👍
🤦♂️ duh haha, thanks for bringing that up. Thanks so much for this contribution. Do you also need a release to PyPi? |
|
Thanks for the quick merge. |
|
Got it 👍
Releasing isn't a big deal, I'll take care of that on Tuesday
…On Fri, Mar 26, 2021, 4:34 AM Julia Sprenger ***@***.***> wrote:
Thanks for the quick merge.
A new release is not essential for us, but would make the version tracking
much more transparent. I think it depends how much effort a new release is
on your side.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#145 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIMQSAEKIZK6PWOMIXRZJVTTFRBK3ANCNFSM4ZTGHULA>
.
|
|
🚀 Check out the new release |
Adding a method to import metadata into an existing RedCap project.
This allows to use PyCap to upload a DataDictionary in csv / json format.
The new code is mostly based on the
import_recordsmethod.I would be happy to add more tests, but would need some advise on the test setup used.