diff --git a/datawrapper/__main__.py b/datawrapper/__main__.py index 296d1dd..5d2a3a4 100644 --- a/datawrapper/__main__.py +++ b/datawrapper/__main__.py @@ -654,7 +654,7 @@ def create_chart( assert isinstance(obj, dict) # Add data, if provided - if data: + if data is not None: self.add_data(chart_id=obj["id"], data=data) # Return the result @@ -734,7 +734,7 @@ def update_chart( _query["metadata"] = metadata # If there's nothing there to update, raise an exception - if not _query and not data: + if not _query and data is None: msg = "No updates submitted." logger.error(msg) raise InvalidRequest(msg) @@ -1005,7 +1005,7 @@ def export_chart( "transparent": transparent, } - response = self.get( + content = self.get( f"{self._CHARTS_URL}/{chart_id}/export/{output}", params=_query ) @@ -1015,7 +1015,7 @@ def export_chart( # Write the file to the file path with open(_filepath, "wb") as fh: - fh.write(response.content) + fh.write(content) # Display the image if requested if display: @@ -1102,6 +1102,7 @@ def add_data(self, chart_id: str, data: pd.DataFrame | str) -> bool: return self.put( f"{self._CHARTS_URL}/{chart_id}/data", data=_data.encode("utf-8"), + extra_headers={"content-type": "text/csv"}, dump_data=False, ) diff --git a/tests/test_users.py b/tests/test_users.py index 86b6db0..1ced3b6 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -21,13 +21,11 @@ def test_get_user(): assert user["id"] == my_id # Get recently edited and published charts - charts = dw.get_recently_edited_charts() + charts = dw.get_recently_edited_charts(user["id"]) assert isinstance(charts, dict) - assert isinstance(charts["charts"], list) - charts = dw.get_recently_published_charts() + charts = dw.get_recently_published_charts(user["id"]) assert isinstance(charts, dict) - assert isinstance(charts["charts"], list) def test_edit_user():