udata 9.2.2.dev31762__py2.py3-none-any.whl → 9.2.2.dev31769__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of udata might be problematic. Click here for more details.

@@ -1,3 +1,5 @@
1
+ import mongoengine
2
+
1
3
  from udata.api import API, api
2
4
  from udata.api.parsers import ModelApiParser
3
5
 
@@ -29,7 +31,10 @@ class ContactPointsListAPI(API):
29
31
  def post(self):
30
32
  """Creates a contact point"""
31
33
  form = api.validate(ContactPointForm)
32
- contact_point = form.save()
34
+ try:
35
+ contact_point = form.save()
36
+ except mongoengine.errors.ValidationError as e:
37
+ api.abort(400, e.message)
33
38
  return contact_point, 201
34
39
 
35
40
 
@@ -12,6 +12,9 @@ class ContactPointForm(ModelForm):
12
12
  _("Name"),
13
13
  [validators.DataRequired(), validators.NoURLs(_("URLs not allowed in this field"))],
14
14
  )
15
- email = fields.StringField(_("Email"), [validators.DataRequired(), validators.Email()])
15
+ email = fields.StringField(_("Email"), [validators.optional(), validators.Email()])
16
+ contact_form = fields.URLField(
17
+ _("Contact form"), description=_("The organization web contact form")
18
+ )
16
19
  owner = fields.CurrentUserField()
17
20
  organization = fields.PublishAsField(_("Publish as"))
@@ -5,7 +5,15 @@ __all__ = ("ContactPoint",)
5
5
 
6
6
 
7
7
  class ContactPoint(db.Document, Owned):
8
- email = db.StringField(max_length=255, required=True)
9
8
  name = db.StringField(max_length=255, required=True)
9
+ email = db.StringField(max_length=255)
10
+ contact_form = db.URLField()
10
11
 
11
12
  meta = {"queryset_class": OwnedQuerySet}
13
+
14
+ def validate(self, clean=True):
15
+ if not self.email and not self.contact_form:
16
+ raise db.ValidationError(
17
+ "At least an email or a contact form is required for a contact point"
18
+ )
19
+ return super().validate(clean=clean)
@@ -2,8 +2,10 @@ import pytest
2
2
  from flask import url_for
3
3
 
4
4
  from udata.core.contact_point.factories import ContactPointFactory
5
+ from udata.i18n import gettext as _
5
6
  from udata.models import ContactPoint
6
- from udata.tests.helpers import assert200, assert204
7
+ from udata.tests.helpers import assert200, assert201, assert204, assert400
8
+ from udata.utils import faker
7
9
 
8
10
  pytestmark = [
9
11
  pytest.mark.usefixtures("clean_db"),
@@ -13,6 +15,43 @@ pytestmark = [
13
15
  class ContactPointAPITest:
14
16
  modules = []
15
17
 
18
+ def test_contact_point_api_create(self, api):
19
+ api.login()
20
+ data = {"name": faker.word(), "email": faker.email(), "contact_form": faker.url()}
21
+ response = api.post(url_for("api.contact_points"), data=data)
22
+ assert201(response)
23
+ assert ContactPoint.objects.count() == 1
24
+
25
+ def test_contact_point_api_create_email_or_contact_form(self, api):
26
+ api.login()
27
+ data = {"name": faker.word(), "contact_form": faker.url()}
28
+ response = api.post(url_for("api.contact_points"), data=data)
29
+ assert201(response)
30
+ assert ContactPoint.objects.count() == 1
31
+
32
+ data = {"name": faker.word(), "email": faker.email()}
33
+ response = api.post(url_for("api.contact_points"), data=data)
34
+ assert201(response)
35
+ assert ContactPoint.objects.count() == 2
36
+
37
+ def test_contact_point_api_invalid_email(self, api):
38
+ api.login()
39
+ data = {"name": faker.word(), "email": faker.word()}
40
+ response = api.post(url_for("api.contact_points"), data=data)
41
+ assert400(response)
42
+ assert "email" in response.json["errors"]
43
+ assert ContactPoint.objects.count() == 0
44
+
45
+ def test_contact_point_missing_contact_information(self, api):
46
+ api.login()
47
+ data = {"name": faker.word()}
48
+ response = api.post(url_for("api.contact_points"), data=data)
49
+ assert400(response)
50
+ assert response.json["message"] == _(
51
+ "At least an email or a contact form is required for a contact point"
52
+ )
53
+ assert ContactPoint.objects.count() == 0
54
+
16
55
  def test_contact_point_api_update(self, api):
17
56
  api.login()
18
57
  contact_point = ContactPointFactory()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: udata
3
- Version: 9.2.2.dev31762
3
+ Version: 9.2.2.dev31769
4
4
  Summary: Open data portal
5
5
  Home-page: https://github.com/opendatateam/udata
6
6
  Author: Opendata Team
@@ -143,6 +143,7 @@ It is collectively taken care of by members of the
143
143
  - Add a filter on organization and document sort parameters in the `/discussions` endpoint [#3147](https://github.com/opendatateam/udata/pull/3147)
144
144
  - Move discussion catalog creation and add fields [#3152](https://github.com/opendatateam/udata/pull/3152) and [#3154](https://github.com/opendatateam/udata/pull/3154)
145
145
  - Add resources formats and harvest remote_url on dataset catalog [#3159](https://github.com/opendatateam/udata/pull/3159)
146
+ - Add contact form in contact point model [#3164](https://github.com/opendatateam/udata/pull/3164)
146
147
  - Make base_api_url optional in dataservice [https://github.com/opendatateam/udata/pull/3163](#3163)
147
148
 
148
149
  ## 9.2.1 (2024-09-23)
@@ -74,11 +74,11 @@ udata/core/badges/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
74
74
  udata/core/badges/tests/test_commands.py,sha256=KrzUsW4jtiFAvq6n83MkDXc1gung0XX8ditQfOXvomI,1364
75
75
  udata/core/badges/tests/test_model.py,sha256=05bG0CLqOhedYNeqgI8oCBm7mnGMQUf1Z10OrFzcBgA,4859
76
76
  udata/core/contact_point/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
- udata/core/contact_point/api.py,sha256=MgPRiSIzujHY1Q3BCUjcYW65upTU2xn4iuiAWnHAlVs,1820
77
+ udata/core/contact_point/api.py,sha256=hK5fanw-QZvenqu2XQW5xKmhPNPGK6xplUWqaMy_Il4,1951
78
78
  udata/core/contact_point/api_fields.py,sha256=w6DyfvaIrX12mwaCLjk6ioAt81-GuRxdv69bTAhar1U,970
79
79
  udata/core/contact_point/factories.py,sha256=MWu3fbE6G84e-7_gtsM5OifZPxHFRWDjw__qjd5fwDc,248
80
- udata/core/contact_point/forms.py,sha256=uioyzAySatniPdDdoBYyHj9n-m1LkMtaJpCnyS0-IRU,572
81
- udata/core/contact_point/models.py,sha256=yB82UcZJGeVhSIsvnpAT8yao7fmAyl59WVGphP3LGHw,309
80
+ udata/core/contact_point/forms.py,sha256=ykdnfLPrY2awIis2Ms57Wj0zuhws7dNPFkLpnkq7sas,688
81
+ udata/core/contact_point/models.py,sha256=Peli1ZbNBLydbhh9kBc0gKYFMxMiwjQAIFIjNZHUqNc,600
82
82
  udata/core/dataservices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
83
83
  udata/core/dataservices/api.py,sha256=uwKSwwZEskECTzt9ePaAbfpwx6DbEP0eE3Ovopo2DPk,4750
84
84
  udata/core/dataservices/factories.py,sha256=LDk8vvG0zhW8J-ZX5LoJQDU13pqeIyjQ05muuMro_eA,876
@@ -601,7 +601,7 @@ udata/tests/api/__init__.py,sha256=y4sL7LD1-KwONHF0q_Rhk2W6BmGUlp7Uz2JnX3e27sk,1
601
601
  udata/tests/api/test_activities_api.py,sha256=RjDDeNle3T-ydVnh6BRypqxAE_244-DXaKkuUCT0HVU,2823
602
602
  udata/tests/api/test_auth_api.py,sha256=OMRlY0OQt60j5N4A-N3HdWTuffOjRlFHkz5a3jJFieI,25987
603
603
  udata/tests/api/test_base_api.py,sha256=2w_vz0eEuq3P3aN-ByvxGc3VZAo7XtgatFfcrzf2uEU,2244
604
- udata/tests/api/test_contact_points.py,sha256=pyakkKnM4lH_asuEoXq9lQyJC9to6ZxSp4QQrHh1c1U,1041
604
+ udata/tests/api/test_contact_points.py,sha256=jumil3faYa11KmSZgZgl592IrDqKcthHUjRv1zqWWn8,2702
605
605
  udata/tests/api/test_dataservices_api.py,sha256=SoiAOv3q0z41iEYXkZwnvr9KzULtfD_MlIQkLcfdf-E,15337
606
606
  udata/tests/api/test_datasets_api.py,sha256=LQAUaYY8Sj2HibHu6Qg1T46LlLxlPRa_aP0r1Z7A0jc,80614
607
607
  udata/tests/api/test_fields.py,sha256=OW85Z5MES5HeWOpapeem8OvR1cIcrqW-xMWpdZO4LZ8,1033
@@ -698,9 +698,9 @@ udata/translations/pt/LC_MESSAGES/udata.mo,sha256=WpPzAqVd2Onv_kz45ULUySKPLrpjcc
698
698
  udata/translations/pt/LC_MESSAGES/udata.po,sha256=18Op9RUITewoDRewlOdYzzq6gjsf1lsvepACV1d7zxs,44976
699
699
  udata/translations/sr/LC_MESSAGES/udata.mo,sha256=NIYRNhVoETZUvIvWm3cCW7DtMBAnS2vXzZjMF5ZzD_c,28500
700
700
  udata/translations/sr/LC_MESSAGES/udata.po,sha256=rQB-4V4WJ7bURj6g2j653vItr5TMHadcLQxec7_fDmg,51545
701
- udata-9.2.2.dev31762.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
702
- udata-9.2.2.dev31762.dist-info/METADATA,sha256=LxUIdHvAQ7upZaNMFW0a4Mnn4QTxT1oVt4QnB2vfk4w,131420
703
- udata-9.2.2.dev31762.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
704
- udata-9.2.2.dev31762.dist-info/entry_points.txt,sha256=3SKiqVy4HUqxf6iWspgMqH8d88Htk6KoLbG1BU-UddQ,451
705
- udata-9.2.2.dev31762.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
706
- udata-9.2.2.dev31762.dist-info/RECORD,,
701
+ udata-9.2.2.dev31769.dist-info/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
702
+ udata-9.2.2.dev31769.dist-info/METADATA,sha256=lb21wiV4o0sr4pvv2hSACtkciLYjTZstoxbSxDlWL8E,131519
703
+ udata-9.2.2.dev31769.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
704
+ udata-9.2.2.dev31769.dist-info/entry_points.txt,sha256=3SKiqVy4HUqxf6iWspgMqH8d88Htk6KoLbG1BU-UddQ,451
705
+ udata-9.2.2.dev31769.dist-info/top_level.txt,sha256=39OCg-VWFWOq4gCKnjKNu-s3OwFlZIu_dVH8Gl6ndHw,12
706
+ udata-9.2.2.dev31769.dist-info/RECORD,,