django-party 0.1.0__tar.gz
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.
- django_party-0.1.0/.pre-commit-config.yaml +52 -0
- django_party-0.1.0/CHANGELOG.rst +9 -0
- django_party-0.1.0/CODEOWNERS +2 -0
- django_party-0.1.0/LICENSE +9 -0
- django_party-0.1.0/MANIFEST.in +10 -0
- django_party-0.1.0/PKG-INFO +96 -0
- django_party-0.1.0/README.md +48 -0
- django_party-0.1.0/party_tests/settings.py +35 -0
- django_party-0.1.0/party_tests/test_consent.py +60 -0
- django_party-0.1.0/party_tests/test_contacts.py +23 -0
- django_party-0.1.0/party_tests/test_external_identity.py +32 -0
- django_party-0.1.0/party_tests/test_party_account.py +45 -0
- django_party-0.1.0/party_tests/urls.py +4 -0
- django_party-0.1.0/pyproject.toml +120 -0
- django_party-0.1.0/requirements/py310-django42.txt +22 -0
- django_party-0.1.0/requirements/py310-django52.txt +22 -0
- django_party-0.1.0/requirements/py311-django42.txt +18 -0
- django_party-0.1.0/requirements/py311-django52.txt +18 -0
- django_party-0.1.0/requirements/py312-django42.txt +18 -0
- django_party-0.1.0/requirements/py312-django52.txt +18 -0
- django_party-0.1.0/requirements/py313-django52.txt +18 -0
- django_party-0.1.0/requirements/py314-django52.txt +18 -0
- django_party-0.1.0/requirements/runtime.in +2 -0
- django_party-0.1.0/setup.cfg +4 -0
- django_party-0.1.0/src/django_party.egg-info/PKG-INFO +96 -0
- django_party-0.1.0/src/django_party.egg-info/SOURCES.txt +46 -0
- django_party-0.1.0/src/django_party.egg-info/dependency_links.txt +1 -0
- django_party-0.1.0/src/django_party.egg-info/not-zip-safe +1 -0
- django_party-0.1.0/src/django_party.egg-info/requires.txt +15 -0
- django_party-0.1.0/src/django_party.egg-info/top_level.txt +1 -0
- django_party-0.1.0/src/party/__init__.py +10 -0
- django_party-0.1.0/src/party/admin.py +58 -0
- django_party-0.1.0/src/party/apps.py +8 -0
- django_party-0.1.0/src/party/migrations/0001_initial.py +199 -0
- django_party-0.1.0/src/party/migrations/__init__.py +0 -0
- django_party-0.1.0/src/party/models/__init__.py +16 -0
- django_party-0.1.0/src/party/models/account.py +70 -0
- django_party-0.1.0/src/party/models/consent.py +73 -0
- django_party-0.1.0/src/party/models/contact.py +76 -0
- django_party-0.1.0/src/party/models/identity.py +44 -0
- django_party-0.1.0/src/party/models/merge.py +36 -0
- django_party-0.1.0/src/party/models/party.py +56 -0
- django_party-0.1.0/src/party/services/__init__.py +21 -0
- django_party-0.1.0/src/party/services/accounts.py +92 -0
- django_party-0.1.0/src/party/services/consent.py +76 -0
- django_party-0.1.0/src/party/services/contacts.py +104 -0
- django_party-0.1.0/src/party/services/identity.py +49 -0
- django_party-0.1.0/tox.ini +20 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v6.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: check-added-large-files
|
|
6
|
+
- id: check-case-conflict
|
|
7
|
+
- id: check-json
|
|
8
|
+
- id: check-merge-conflict
|
|
9
|
+
- id: check-symlinks
|
|
10
|
+
- id: check-toml
|
|
11
|
+
- id: end-of-file-fixer
|
|
12
|
+
- id: trailing-whitespace
|
|
13
|
+
- repo: https://github.com/asottile/pyupgrade
|
|
14
|
+
rev: v3.21.2
|
|
15
|
+
hooks:
|
|
16
|
+
- id: pyupgrade
|
|
17
|
+
args: [--py36-plus]
|
|
18
|
+
- repo: https://github.com/psf/black-pre-commit-mirror
|
|
19
|
+
rev: 26.3.1
|
|
20
|
+
hooks:
|
|
21
|
+
- id: black
|
|
22
|
+
- repo: https://github.com/asottile/blacken-docs
|
|
23
|
+
rev: 1.20.0
|
|
24
|
+
hooks:
|
|
25
|
+
- id: blacken-docs
|
|
26
|
+
additional_dependencies:
|
|
27
|
+
- black>=22.12.0
|
|
28
|
+
- repo: https://github.com/pycqa/isort
|
|
29
|
+
rev: 8.0.1
|
|
30
|
+
hooks:
|
|
31
|
+
- id: isort
|
|
32
|
+
args: ["--profile", "black"]
|
|
33
|
+
- repo: https://github.com/PyCQA/flake8
|
|
34
|
+
rev: 7.3.0
|
|
35
|
+
hooks:
|
|
36
|
+
- id: flake8
|
|
37
|
+
additional_dependencies:
|
|
38
|
+
- flake8-pyproject
|
|
39
|
+
- flake8-bugbear
|
|
40
|
+
- flake8-comprehensions
|
|
41
|
+
- flake8-tidy-imports
|
|
42
|
+
- flake8-typing-imports
|
|
43
|
+
- repo: https://github.com/mgedmin/check-manifest
|
|
44
|
+
rev: "0.51"
|
|
45
|
+
hooks:
|
|
46
|
+
- id: check-manifest
|
|
47
|
+
args: [--no-build-isolation]
|
|
48
|
+
additional_dependencies:
|
|
49
|
+
- Django>=3.2
|
|
50
|
+
- build
|
|
51
|
+
- setuptools>=77
|
|
52
|
+
- wheel
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) DLRSP
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
include LICENSE
|
|
2
|
+
include README.md
|
|
3
|
+
include CHANGELOG.rst
|
|
4
|
+
include CODEOWNERS
|
|
5
|
+
include tox.ini
|
|
6
|
+
include .pre-commit-config.yaml
|
|
7
|
+
recursive-include requirements *.in *.txt
|
|
8
|
+
recursive-include src/party/migrations *
|
|
9
|
+
recursive-include party_tests *
|
|
10
|
+
global-exclude __pycache__ *.py[cod]
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-party
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Django party identity hub: contacts, external ids, consent, thin account codes.
|
|
5
|
+
Author-email: DLRSP <dlrsp.dev@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/DLRSP/django-party
|
|
8
|
+
Project-URL: Documentation, https://github.com/DLRSP/django-party/
|
|
9
|
+
Project-URL: Repository, https://github.com/DLRSP/django-party
|
|
10
|
+
Project-URL: Issues, https://github.com/DLRSP/django-party/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/DLRSP/django-party/blob/main/CHANGELOG.rst
|
|
12
|
+
Keywords: django,party,identity,crm,consent,contacts
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Web Environment
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Framework :: Django :: 4.2
|
|
17
|
+
Classifier: Framework :: Django :: 5.2
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
28
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
29
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
30
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
31
|
+
Requires-Python: >=3.10
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
License-File: LICENSE
|
|
34
|
+
Requires-Dist: Django>=4.2
|
|
35
|
+
Provides-Extra: testing
|
|
36
|
+
Requires-Dist: coverage; extra == "testing"
|
|
37
|
+
Requires-Dist: pytest; extra == "testing"
|
|
38
|
+
Requires-Dist: pytest-django; extra == "testing"
|
|
39
|
+
Provides-Extra: linting
|
|
40
|
+
Requires-Dist: flake8; extra == "linting"
|
|
41
|
+
Requires-Dist: flake8-pyproject; extra == "linting"
|
|
42
|
+
Requires-Dist: flake8-bugbear; extra == "linting"
|
|
43
|
+
Requires-Dist: flake8-comprehensions; extra == "linting"
|
|
44
|
+
Requires-Dist: flake8-tidy-imports; extra == "linting"
|
|
45
|
+
Requires-Dist: flake8-typing-imports; extra == "linting"
|
|
46
|
+
Requires-Dist: pylint; extra == "linting"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# django-party
|
|
50
|
+
|
|
51
|
+
[](https://github.com/DLRSP/django-party/actions/workflows/ci.yaml)
|
|
52
|
+
[](https://opensource.org/licenses/MIT)
|
|
53
|
+
[](https://pypi.org/project/django-party/)
|
|
54
|
+
|
|
55
|
+
Shared party (person/organization) identity for Django sites: contacts, external ids, append-only consent ledger, and thin counterpart account codes.
|
|
56
|
+
|
|
57
|
+
Not a sales CRM. Not a double-entry ledger.
|
|
58
|
+
|
|
59
|
+
## Requirements
|
|
60
|
+
|
|
61
|
+
- Python 3.10+
|
|
62
|
+
- Django 4.2+
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install django-party
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
INSTALLED_APPS = [
|
|
72
|
+
# ...
|
|
73
|
+
"party",
|
|
74
|
+
# ...
|
|
75
|
+
]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then migrate:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
python manage.py migrate party
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Concepts
|
|
85
|
+
|
|
86
|
+
| Model | Role |
|
|
87
|
+
|-------|------|
|
|
88
|
+
| `Party` | Canonical person or organization |
|
|
89
|
+
| `ExternalIdentity` | Multi-source ids (`beddy`+`customer\|company\|contact`, `fiscal`+`cedente`, …) |
|
|
90
|
+
| `ContactPoint` / `PostalAddress` | Channels and addresses with validity |
|
|
91
|
+
| `ConsentRecord` | Append-only privacy/marketing ledger (`null` ≠ granted) |
|
|
92
|
+
| `PartyAccount` | Thin studio “Codice conto” metadata (no balances) |
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# django-party
|
|
2
|
+
|
|
3
|
+
[](https://github.com/DLRSP/django-party/actions/workflows/ci.yaml)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://pypi.org/project/django-party/)
|
|
6
|
+
|
|
7
|
+
Shared party (person/organization) identity for Django sites: contacts, external ids, append-only consent ledger, and thin counterpart account codes.
|
|
8
|
+
|
|
9
|
+
Not a sales CRM. Not a double-entry ledger.
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Python 3.10+
|
|
14
|
+
- Django 4.2+
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install django-party
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
INSTALLED_APPS = [
|
|
24
|
+
# ...
|
|
25
|
+
"party",
|
|
26
|
+
# ...
|
|
27
|
+
]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then migrate:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
python manage.py migrate party
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Concepts
|
|
37
|
+
|
|
38
|
+
| Model | Role |
|
|
39
|
+
|-------|------|
|
|
40
|
+
| `Party` | Canonical person or organization |
|
|
41
|
+
| `ExternalIdentity` | Multi-source ids (`beddy`+`customer\|company\|contact`, `fiscal`+`cedente`, …) |
|
|
42
|
+
| `ContactPoint` / `PostalAddress` | Channels and addresses with validity |
|
|
43
|
+
| `ConsentRecord` | Append-only privacy/marketing ledger (`null` ≠ granted) |
|
|
44
|
+
| `PartyAccount` | Thin studio “Codice conto” metadata (no balances) |
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
SECRET_KEY = "party-test-secret"
|
|
2
|
+
USE_TZ = True
|
|
3
|
+
INSTALLED_APPS = [
|
|
4
|
+
"django.contrib.auth",
|
|
5
|
+
"django.contrib.contenttypes",
|
|
6
|
+
"django.contrib.sessions",
|
|
7
|
+
"django.contrib.admin",
|
|
8
|
+
"django.contrib.messages",
|
|
9
|
+
"party",
|
|
10
|
+
]
|
|
11
|
+
DATABASES = {
|
|
12
|
+
"default": {
|
|
13
|
+
"ENGINE": "django.db.backends.sqlite3",
|
|
14
|
+
"NAME": ":memory:",
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
MIDDLEWARE = [
|
|
18
|
+
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
19
|
+
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
20
|
+
"django.contrib.messages.middleware.MessageMiddleware",
|
|
21
|
+
]
|
|
22
|
+
ROOT_URLCONF = "party_tests.urls"
|
|
23
|
+
TEMPLATES = [
|
|
24
|
+
{
|
|
25
|
+
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
26
|
+
"APP_DIRS": True,
|
|
27
|
+
"OPTIONS": {
|
|
28
|
+
"context_processors": [
|
|
29
|
+
"django.contrib.auth.context_processors.auth",
|
|
30
|
+
"django.contrib.messages.context_processors.messages",
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Consent append-only + deny-by-default marketing."""
|
|
2
|
+
from django.test import TestCase
|
|
3
|
+
from django.utils import timezone
|
|
4
|
+
|
|
5
|
+
from party.models import ConsentRecord, Party
|
|
6
|
+
from party.services import marketing_allowed, record_consent, refuse_beddy_consent_mapping
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ConsentLedgerTests(TestCase):
|
|
10
|
+
def setUp(self):
|
|
11
|
+
self.party = Party.objects.create(
|
|
12
|
+
kind=Party.Kind.PERSON, given_name="Ada", family_name="Lovelace"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def test_delete_raises(self):
|
|
16
|
+
row = record_consent(
|
|
17
|
+
self.party,
|
|
18
|
+
purpose=ConsentRecord.Purpose.MARKETING,
|
|
19
|
+
decision=ConsentRecord.Decision.GRANTED,
|
|
20
|
+
source="hitl",
|
|
21
|
+
)
|
|
22
|
+
with self.assertRaises(ValueError):
|
|
23
|
+
row.delete()
|
|
24
|
+
|
|
25
|
+
def test_queryset_update_raises(self):
|
|
26
|
+
record_consent(
|
|
27
|
+
self.party,
|
|
28
|
+
purpose=ConsentRecord.Purpose.MARKETING,
|
|
29
|
+
decision=ConsentRecord.Decision.GRANTED,
|
|
30
|
+
source="hitl",
|
|
31
|
+
)
|
|
32
|
+
with self.assertRaises(ValueError):
|
|
33
|
+
ConsentRecord.objects.filter(party=self.party).update(
|
|
34
|
+
decision=ConsentRecord.Decision.WITHDRAWN
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def test_withdraw_after_grant_denies_marketing(self):
|
|
38
|
+
from datetime import timedelta
|
|
39
|
+
|
|
40
|
+
now = timezone.now()
|
|
41
|
+
record_consent(
|
|
42
|
+
self.party,
|
|
43
|
+
purpose=ConsentRecord.Purpose.MARKETING,
|
|
44
|
+
decision=ConsentRecord.Decision.GRANTED,
|
|
45
|
+
source="hitl",
|
|
46
|
+
recorded_at=now,
|
|
47
|
+
)
|
|
48
|
+
self.assertTrue(marketing_allowed(self.party))
|
|
49
|
+
record_consent(
|
|
50
|
+
self.party,
|
|
51
|
+
purpose=ConsentRecord.Purpose.MARKETING,
|
|
52
|
+
decision=ConsentRecord.Decision.WITHDRAWN,
|
|
53
|
+
source="hitl",
|
|
54
|
+
recorded_at=now + timedelta(seconds=1),
|
|
55
|
+
)
|
|
56
|
+
self.assertFalse(marketing_allowed(self.party))
|
|
57
|
+
|
|
58
|
+
def test_refuse_beddy_consent_mapping(self):
|
|
59
|
+
with self.assertRaises(ValueError):
|
|
60
|
+
refuse_beddy_consent_mapping({"privacy_check": 1})
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""ContactPoint upsert helpers."""
|
|
2
|
+
from django.test import TestCase
|
|
3
|
+
from django.utils import timezone
|
|
4
|
+
|
|
5
|
+
from party.models import ContactPoint, Party
|
|
6
|
+
from party.services import upsert_contact_point
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ContactUpsertTests(TestCase):
|
|
10
|
+
def test_upsert_same_value_is_idempotent(self):
|
|
11
|
+
party = Party.objects.create(kind=Party.Kind.PERSON, given_name="Ada", family_name="Lovelace")
|
|
12
|
+
now = timezone.now()
|
|
13
|
+
a = upsert_contact_point(
|
|
14
|
+
party, channel=ContactPoint.Channel.EMAIL, value="ada@example.com", valid_from=now
|
|
15
|
+
)
|
|
16
|
+
b = upsert_contact_point(
|
|
17
|
+
party, channel=ContactPoint.Channel.EMAIL, value="ada@example.com", valid_from=now
|
|
18
|
+
)
|
|
19
|
+
self.assertEqual(a.pk, b.pk)
|
|
20
|
+
self.assertEqual(
|
|
21
|
+
ContactPoint.objects.filter(party=party, channel="email", valid_to__isnull=True).count(),
|
|
22
|
+
1,
|
|
23
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.utils import timezone
|
|
3
|
+
|
|
4
|
+
from party.models import Party
|
|
5
|
+
from party.services.identity import upsert_external_identity
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@pytest.mark.django_db
|
|
9
|
+
def test_contact_and_customer_namespaces_are_distinct():
|
|
10
|
+
p_contact = Party.objects.create(
|
|
11
|
+
kind=Party.Kind.PERSON, given_name="C", family_name="Ontact"
|
|
12
|
+
)
|
|
13
|
+
p_customer = Party.objects.create(
|
|
14
|
+
kind=Party.Kind.PERSON, given_name="C", family_name="Ustomer"
|
|
15
|
+
)
|
|
16
|
+
upsert_external_identity(
|
|
17
|
+
p_contact, namespace="beddy", scheme="contact", value="12345"
|
|
18
|
+
)
|
|
19
|
+
upsert_external_identity(
|
|
20
|
+
p_customer, namespace="beddy", scheme="customer", value="12345"
|
|
21
|
+
)
|
|
22
|
+
assert p_contact.external_identities.filter(scheme="contact").count() == 1
|
|
23
|
+
assert p_customer.external_identities.filter(scheme="customer").count() == 1
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.django_db
|
|
27
|
+
def test_same_scheme_value_cannot_bind_two_parties():
|
|
28
|
+
a = Party.objects.create(kind=Party.Kind.PERSON, given_name="A", family_name="A")
|
|
29
|
+
b = Party.objects.create(kind=Party.Kind.PERSON, given_name="B", family_name="B")
|
|
30
|
+
upsert_external_identity(a, namespace="beddy", scheme="customer", value="99")
|
|
31
|
+
with pytest.raises(ValueError):
|
|
32
|
+
upsert_external_identity(b, namespace="beddy", scheme="customer", value="99")
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from django.core.exceptions import ValidationError
|
|
3
|
+
from django.utils import timezone
|
|
4
|
+
|
|
5
|
+
from party.models import Party, PartyAccount
|
|
6
|
+
from party.services.accounts import get_default_party_account, upsert_party_account
|
|
7
|
+
from party.services.consent import marketing_allowed
|
|
8
|
+
from party.models import ConsentRecord
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.django_db
|
|
12
|
+
def test_upsert_and_default_account():
|
|
13
|
+
party = Party.objects.create(
|
|
14
|
+
kind=Party.Kind.PERSON, given_name="Ada", family_name="Lovelace"
|
|
15
|
+
)
|
|
16
|
+
acc = upsert_party_account(
|
|
17
|
+
party, code="401.12", kind=PartyAccount.Kind.RECEIVABLE, is_default=True
|
|
18
|
+
)
|
|
19
|
+
assert acc.code == "401.12"
|
|
20
|
+
found = get_default_party_account(party, PartyAccount.Kind.RECEIVABLE)
|
|
21
|
+
assert found is not None
|
|
22
|
+
assert found.pk == acc.pk
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.django_db
|
|
26
|
+
def test_reject_numeric_pms_id_as_code():
|
|
27
|
+
party = Party.objects.create(kind=Party.Kind.PERSON, given_name="X", family_name="Y")
|
|
28
|
+
with pytest.raises(ValidationError):
|
|
29
|
+
upsert_party_account(
|
|
30
|
+
party, code="18856052", kind=PartyAccount.Kind.PAYABLE, is_default=True
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@pytest.mark.django_db
|
|
35
|
+
def test_marketing_allowed_requires_granted():
|
|
36
|
+
party = Party.objects.create(kind=Party.Kind.PERSON, given_name="A", family_name="B")
|
|
37
|
+
assert marketing_allowed(party) is False
|
|
38
|
+
ConsentRecord.objects.create(
|
|
39
|
+
party=party,
|
|
40
|
+
purpose=ConsentRecord.Purpose.MARKETING,
|
|
41
|
+
decision=ConsentRecord.Decision.GRANTED,
|
|
42
|
+
recorded_at=timezone.now(),
|
|
43
|
+
source="test",
|
|
44
|
+
)
|
|
45
|
+
assert marketing_allowed(party) is True
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [
|
|
3
|
+
"setuptools >= 77",
|
|
4
|
+
"wheel",
|
|
5
|
+
]
|
|
6
|
+
build-backend = "setuptools.build_meta"
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "django-party"
|
|
10
|
+
description = "Django party identity hub: contacts, external ids, consent, thin account codes."
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "DLRSP", email = "dlrsp.dev@gmail.com" },
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
dynamic = ["version"]
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
license = "MIT"
|
|
18
|
+
license-files = ["LICENSE"]
|
|
19
|
+
keywords = [
|
|
20
|
+
"django",
|
|
21
|
+
"party",
|
|
22
|
+
"identity",
|
|
23
|
+
"crm",
|
|
24
|
+
"consent",
|
|
25
|
+
"contacts",
|
|
26
|
+
]
|
|
27
|
+
classifiers = [
|
|
28
|
+
"Development Status :: 3 - Alpha",
|
|
29
|
+
"Environment :: Web Environment",
|
|
30
|
+
"Framework :: Django",
|
|
31
|
+
"Framework :: Django :: 4.2",
|
|
32
|
+
"Framework :: Django :: 5.2",
|
|
33
|
+
"Intended Audience :: Developers",
|
|
34
|
+
"Operating System :: OS Independent",
|
|
35
|
+
"Programming Language :: Python",
|
|
36
|
+
"Programming Language :: Python :: 3",
|
|
37
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
38
|
+
"Programming Language :: Python :: 3.10",
|
|
39
|
+
"Programming Language :: Python :: 3.11",
|
|
40
|
+
"Programming Language :: Python :: 3.12",
|
|
41
|
+
"Programming Language :: Python :: 3.13",
|
|
42
|
+
"Programming Language :: Python :: 3.14",
|
|
43
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
44
|
+
"Topic :: Software Development :: Libraries",
|
|
45
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
46
|
+
]
|
|
47
|
+
dependencies = [
|
|
48
|
+
"Django>=4.2",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[project.optional-dependencies]
|
|
52
|
+
testing = [
|
|
53
|
+
"coverage",
|
|
54
|
+
"pytest",
|
|
55
|
+
"pytest-django",
|
|
56
|
+
]
|
|
57
|
+
linting = [
|
|
58
|
+
"flake8",
|
|
59
|
+
"flake8-pyproject",
|
|
60
|
+
"flake8-bugbear",
|
|
61
|
+
"flake8-comprehensions",
|
|
62
|
+
"flake8-tidy-imports",
|
|
63
|
+
"flake8-typing-imports",
|
|
64
|
+
"pylint",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
[project.urls]
|
|
68
|
+
Homepage = "https://github.com/DLRSP/django-party"
|
|
69
|
+
Documentation = "https://github.com/DLRSP/django-party/"
|
|
70
|
+
Repository = "https://github.com/DLRSP/django-party"
|
|
71
|
+
Issues = "https://github.com/DLRSP/django-party/issues"
|
|
72
|
+
Changelog = "https://github.com/DLRSP/django-party/blob/main/CHANGELOG.rst"
|
|
73
|
+
|
|
74
|
+
[tool.setuptools]
|
|
75
|
+
package-dir = { "" = "src" }
|
|
76
|
+
include-package-data = true
|
|
77
|
+
zip-safe = false
|
|
78
|
+
|
|
79
|
+
[tool.setuptools.dynamic]
|
|
80
|
+
version = { attr = "party.__version__" }
|
|
81
|
+
|
|
82
|
+
[tool.setuptools.packages.find]
|
|
83
|
+
where = ["src"]
|
|
84
|
+
include = ["party*"]
|
|
85
|
+
|
|
86
|
+
[tool.setuptools.data-files]
|
|
87
|
+
"share/django-party/requirements" = [
|
|
88
|
+
"requirements/py310-django42.txt",
|
|
89
|
+
"requirements/py310-django52.txt",
|
|
90
|
+
"requirements/py311-django42.txt",
|
|
91
|
+
"requirements/py311-django52.txt",
|
|
92
|
+
"requirements/py312-django42.txt",
|
|
93
|
+
"requirements/py312-django52.txt",
|
|
94
|
+
"requirements/py313-django52.txt",
|
|
95
|
+
"requirements/py314-django52.txt",
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
[tool.distutils.bdist_wheel]
|
|
99
|
+
universal = false
|
|
100
|
+
|
|
101
|
+
[tool.black]
|
|
102
|
+
line-length = 80
|
|
103
|
+
target-version = ['py311']
|
|
104
|
+
|
|
105
|
+
[tool.isort]
|
|
106
|
+
profile = "black"
|
|
107
|
+
|
|
108
|
+
[tool.flake8]
|
|
109
|
+
max-line-length = 80
|
|
110
|
+
select = ["E", "F", "W", "B", "B950", "C", "I", "TYP"]
|
|
111
|
+
ignore = ["E203", "E501", "W503", "B950"]
|
|
112
|
+
per-file-ignores = [
|
|
113
|
+
"**/migrations/*:B950",
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
[tool.pytest.ini_options]
|
|
117
|
+
DJANGO_SETTINGS_MODULE = "party_tests.settings"
|
|
118
|
+
pythonpath = ["src", "."]
|
|
119
|
+
django_find_project = false
|
|
120
|
+
addopts = "--strict-markers"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.10
|
|
3
|
+
# by the following command:
|
|
4
|
+
#
|
|
5
|
+
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/py310-django42.txt requirements/runtime.in
|
|
6
|
+
#
|
|
7
|
+
asgiref==3.12.1 \
|
|
8
|
+
--hash=sha256:59dcb51c272ad209d59bed5708a64a333083e86017d7fcdd67498eeab7784340 \
|
|
9
|
+
--hash=sha256:fe386d1c2bff7259ea95929266d12a8cf9a8b5a1c2598402967d8792e7a7c094
|
|
10
|
+
# via django
|
|
11
|
+
django==4.2.30 \
|
|
12
|
+
--hash=sha256:4d07aaf1c62f9984842b67c2874ebbf7056a17be253860299b93ae1881faad65 \
|
|
13
|
+
--hash=sha256:4ebc7a434e3819db6cf4b399fb5b3f536310a30e8486f08b66886840be84b37c
|
|
14
|
+
# via -r requirements/runtime.in
|
|
15
|
+
sqlparse==0.6.0 \
|
|
16
|
+
--hash=sha256:113c35c75365ab9cc9c7231d68c6428fb11c085fc8e9eb1ad659b7ddbf6cd2b9 \
|
|
17
|
+
--hash=sha256:b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f
|
|
18
|
+
# via django
|
|
19
|
+
typing-extensions==4.16.0 \
|
|
20
|
+
--hash=sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8 \
|
|
21
|
+
--hash=sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5
|
|
22
|
+
# via asgiref
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.10
|
|
3
|
+
# by the following command:
|
|
4
|
+
#
|
|
5
|
+
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/py310-django52.txt requirements/runtime.in
|
|
6
|
+
#
|
|
7
|
+
asgiref==3.12.1 \
|
|
8
|
+
--hash=sha256:59dcb51c272ad209d59bed5708a64a333083e86017d7fcdd67498eeab7784340 \
|
|
9
|
+
--hash=sha256:fe386d1c2bff7259ea95929266d12a8cf9a8b5a1c2598402967d8792e7a7c094
|
|
10
|
+
# via django
|
|
11
|
+
django==5.2.17 \
|
|
12
|
+
--hash=sha256:9d4d93be539a18ab80d058eb515900e10951e04c537c5a6b394fc49528d3251f \
|
|
13
|
+
--hash=sha256:f04fb3b36ee119e1af4fa1d397d5fd6cf12700f49321e84d4f4c642c5b1973db
|
|
14
|
+
# via -r requirements/runtime.in
|
|
15
|
+
sqlparse==0.6.0 \
|
|
16
|
+
--hash=sha256:113c35c75365ab9cc9c7231d68c6428fb11c085fc8e9eb1ad659b7ddbf6cd2b9 \
|
|
17
|
+
--hash=sha256:b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f
|
|
18
|
+
# via django
|
|
19
|
+
typing-extensions==4.16.0 \
|
|
20
|
+
--hash=sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8 \
|
|
21
|
+
--hash=sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5
|
|
22
|
+
# via asgiref
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.11
|
|
3
|
+
# by the following command:
|
|
4
|
+
#
|
|
5
|
+
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/py311-django42.txt requirements/runtime.in
|
|
6
|
+
#
|
|
7
|
+
asgiref==3.12.1 \
|
|
8
|
+
--hash=sha256:59dcb51c272ad209d59bed5708a64a333083e86017d7fcdd67498eeab7784340 \
|
|
9
|
+
--hash=sha256:fe386d1c2bff7259ea95929266d12a8cf9a8b5a1c2598402967d8792e7a7c094
|
|
10
|
+
# via django
|
|
11
|
+
django==4.2.30 \
|
|
12
|
+
--hash=sha256:4d07aaf1c62f9984842b67c2874ebbf7056a17be253860299b93ae1881faad65 \
|
|
13
|
+
--hash=sha256:4ebc7a434e3819db6cf4b399fb5b3f536310a30e8486f08b66886840be84b37c
|
|
14
|
+
# via -r requirements/runtime.in
|
|
15
|
+
sqlparse==0.6.0 \
|
|
16
|
+
--hash=sha256:113c35c75365ab9cc9c7231d68c6428fb11c085fc8e9eb1ad659b7ddbf6cd2b9 \
|
|
17
|
+
--hash=sha256:b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f
|
|
18
|
+
# via django
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.11
|
|
3
|
+
# by the following command:
|
|
4
|
+
#
|
|
5
|
+
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/py311-django52.txt requirements/runtime.in
|
|
6
|
+
#
|
|
7
|
+
asgiref==3.12.1 \
|
|
8
|
+
--hash=sha256:59dcb51c272ad209d59bed5708a64a333083e86017d7fcdd67498eeab7784340 \
|
|
9
|
+
--hash=sha256:fe386d1c2bff7259ea95929266d12a8cf9a8b5a1c2598402967d8792e7a7c094
|
|
10
|
+
# via django
|
|
11
|
+
django==5.2.17 \
|
|
12
|
+
--hash=sha256:9d4d93be539a18ab80d058eb515900e10951e04c537c5a6b394fc49528d3251f \
|
|
13
|
+
--hash=sha256:f04fb3b36ee119e1af4fa1d397d5fd6cf12700f49321e84d4f4c642c5b1973db
|
|
14
|
+
# via -r requirements/runtime.in
|
|
15
|
+
sqlparse==0.6.0 \
|
|
16
|
+
--hash=sha256:113c35c75365ab9cc9c7231d68c6428fb11c085fc8e9eb1ad659b7ddbf6cd2b9 \
|
|
17
|
+
--hash=sha256:b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f
|
|
18
|
+
# via django
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This file is autogenerated by pip-compile with Python 3.12
|
|
3
|
+
# by the following command:
|
|
4
|
+
#
|
|
5
|
+
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/py312-django42.txt requirements/runtime.in
|
|
6
|
+
#
|
|
7
|
+
asgiref==3.12.1 \
|
|
8
|
+
--hash=sha256:59dcb51c272ad209d59bed5708a64a333083e86017d7fcdd67498eeab7784340 \
|
|
9
|
+
--hash=sha256:fe386d1c2bff7259ea95929266d12a8cf9a8b5a1c2598402967d8792e7a7c094
|
|
10
|
+
# via django
|
|
11
|
+
django==4.2.30 \
|
|
12
|
+
--hash=sha256:4d07aaf1c62f9984842b67c2874ebbf7056a17be253860299b93ae1881faad65 \
|
|
13
|
+
--hash=sha256:4ebc7a434e3819db6cf4b399fb5b3f536310a30e8486f08b66886840be84b37c
|
|
14
|
+
# via -r requirements/runtime.in
|
|
15
|
+
sqlparse==0.6.0 \
|
|
16
|
+
--hash=sha256:113c35c75365ab9cc9c7231d68c6428fb11c085fc8e9eb1ad659b7ddbf6cd2b9 \
|
|
17
|
+
--hash=sha256:b861c0288ce2fa56209a9a6412d2e066ac664b3873b89c26c9d8415e8e32996f
|
|
18
|
+
# via django
|