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

[#197] Klanten API migration command #263

Merged
merged 48 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
89f19ea
[#197] initial commit
SonnyBA Oct 9, 2024
52d1c91
[#197] add help text
SonnyBA Oct 9, 2024
1e7621d
[#197] add subject & partij/digitaal adress classes
SonnyBA Oct 9, 2024
062757c
[#197] increase logging & set subject fields explicitly
Oct 10, 2024
f87f221
[#197] update clients & retrieve external subjects
Oct 10, 2024
cbd4bd0
[#197] remove URL validator
Oct 11, 2024
a17b990
[#197] fix pagination
SonnyBA Oct 11, 2024
6ad9c6b
[#197] include `voorletters` for `Persoon`
SonnyBA Oct 11, 2024
621119b
[#197] handle various `subjectIdentificatie` situations
SonnyBA Oct 11, 2024
3a8b18b
[#197] add URL validation
SonnyBA Oct 11, 2024
ff6c6f0
[#197] add integration tests
SonnyBA Oct 11, 2024
278a44d
[#197] use `VCRMixin` instead of separate decorators
SonnyBA Oct 11, 2024
2b712c6
[#197] apply formatting
SonnyBA Oct 11, 2024
18131d8
[#197] remove unused field
SonnyBA Oct 14, 2024
246d734
[#197] create `VCRMixin`
SonnyBA Oct 18, 2024
cc491e1
[#197] add Klanten API klant fixtures
SonnyBA Oct 18, 2024
567e98b
[#197] move Klanten API fixtures
SonnyBA Oct 18, 2024
dda699e
[#197] move cassete files
SonnyBA Oct 18, 2024
6e820a0
[#197] update tests
SonnyBA Oct 18, 2024
62e3f10
[#197] move fixtures
SonnyBA Oct 18, 2024
b2e451d
[#197] add a docker compose setup for testing a migration
SonnyBA Oct 18, 2024
cb03741
[#197] add TODO's
SonnyBA Oct 25, 2024
10b438a
[#197] use separate migration folder
Nov 14, 2024
15bd52d
[#197] add fixture for test_digitaal_adres
Nov 14, 2024
0dc45c2
[197] remove postgres volume
Nov 14, 2024
ce47f61
[#197] add helper function to generate encoded JWT token
Nov 14, 2024
992c9b8
[#197] add fixture to load V1 credentials
Nov 14, 2024
9ff8bd3
[#197] remove previous vcr cassettes
Nov 14, 2024
ad2d5cd
[#197] set subject_identificatie from external subject
Nov 14, 2024
fe26cd1
[#197] add example dummy server
Nov 14, 2024
ba61c07
[#197] update test fixtures
Nov 14, 2024
b3ad275
[#197] update tests & add new cassettes
Nov 14, 2024
738cbcd
[#197] apply formatting
Nov 14, 2024
a27cd85
[#197] use `SoortDigitaalAdres` wherever applicable
Nov 14, 2024
926c856
[#197] raise `CommandError` when invalid URLs are given
Nov 14, 2024
e6f0849
[#197] move `klant_fields` definition
Nov 14, 2024
057e53d
[#197] move path definitions
Nov 14, 2024
e59c5cf
[#197] remove absolete code
Nov 14, 2024
b885671
[#197] show klant data in error log
Nov 14, 2024
61d0b4e
[#197] add documentation for creating cassettes
Nov 14, 2024
f274de1
Update docs/development/migration.rst
SonnyBA Nov 21, 2024
74ac0e3
[#197] Update docs/development/migration.rst
SonnyBA Nov 21, 2024
293156e
[#197] call `_get_dummy_token` once
SonnyBA Nov 22, 2024
847a431
[#197] split migration documentation
SonnyBA Nov 22, 2024
264b6a1
[#197] apply formatting
SonnyBA Nov 22, 2024
d524388
[#197] add example to user migration documentation
SonnyBA Nov 22, 2024
6828b30
[#197] update CHANGELOG
SonnyBA Nov 22, 2024
6bc2633
[#197] fix documentation code block
SonnyBA Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Change history
**New features**

* Updated OAF version to 0.9.0. This upgrade allows admin users managing their sessions through the admin.
* [#197] Added a ``migrate_to_v2`` management command which allows users of version ``1.0.0`` to migrate to version ``2.4.0``
More information can be found in the `documentation <https://open-klant.readthedocs.io/en/latest/installation/migration.html>`

**Bugfixes/QoL**:

Expand Down
13 changes: 13 additions & 0 deletions docs/development/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _development_index:

Development
============

**Open Klant** is open-source software. We'd love to have you
contribute!

.. toctree::
:maxdepth: 1
:caption: Further reading

migration
41 changes: 41 additions & 0 deletions docs/development/migration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. _migration_developer_docs:

Migration
=========

To test the migration command, tests are written using VCR, which records the (relevant)
outgoing requests to cassette files. Whenever tests need to be updated, consider
re-recording the corresponding cassettes.

To re-record tests, a separate docker compose file is available to run a
version ``1.0.0`` Open Klant instance next to the ``StaticLiveServer`` (which
sets up a live server) which runs version ``2.0.0``. The `web` container from the
docker compose setup should load the corresponding fixture which reside in the
``migration/fixtures`` folder. A typical workflow, to re-record cassettes,
could look like the following:

.. code-block:: bash

# Start the docker compose setup
$ docker compose up --detach

# Load a fixture for a certain test
$ docker compose exec -it web \
./src/manage.py loaddata migration/credentials migration/test_digitaal_adres

# Run the corresponding test
$ ./src/manage.py test openklant.tests.test_migrate.MigrateTestCase.test_digitaal_adres

# Stop and destroy the containers (to start with a clean slate on the next run)
$ docker compose down


After running the test a cassette should be created (with the test name as filename)
in the ``migration/cassettes`` folder.

Note that the docker compose setup, with its fixtures are only needed to (re)create
cassettes for VCR. The migration tests can be ran without the docker compose setup.

Some tests require custom responses, for example to retrieve the ``subjectIdentificatie``
when a ``subject`` URL is supplied. For these cases a ``test_server.py`` file is added
that can be modified as needed to create a response for a cassette.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ Open Klant `is`_ and only uses open source.
:hidden:

installation/index
development/index
1 change: 1 addition & 0 deletions docs/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ this.
:caption: Further reading

config
migration
21 changes: 21 additions & 0 deletions docs/installation/migration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. _migration_user_docs:

Migration
=========

Users of Open Klant version ``1.0.0`` willing to migrate to version ``2.4.0`` or higher
can make use of the ``migrate_to_v2`` management command. This command **only** migrates
``Klant`` instances from version ``1.0.0``. The command expects two URLs; a URL for the
Open Klant instance of version ``1.0.0`` and a URL for version ``2.0.0``.

The command also expects a ``ACCESS_TOKEN`` environment variable to be set, to authenticate to
the Open Klant ``1.0.0`` instance. For the ``2.0.0`` instance a dummy token will be
created. This dummy token will be removed after the command ran (be it successfully or not).

An example of how one might want to run this command can be seen below:

```
Copy link
Collaborator

Choose a reason for hiding this comment

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

formatting is off for this:

image

you might have to use .. code-block:: bash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! That fixed it:

image

$ ACCESS_TOKEN="openklant-v1-token" ./src/manage.py migrate_to_v2 \
https://example.openklant.nl \
https://example.klantinteracties.nl
```
38 changes: 38 additions & 0 deletions migration/cassettes/test_digitaal_adres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/dbfdb3f2-e153-49ea-9e26-e55220605c14","bronorganisatie":"215906846","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"","voorvoegselAchternaam":"","achternaam":"","telefoonnummer":"","emailadres":"[email protected]","adres":null,"subject":"","subjectType":"natuurlijk_persoon","aanmaakkanaal":"","geverifieerd":false,"subjectIdentificatie":{"inpBsn":"","anpIdentificatie":"0","inpANummer":"","geslachtsnaam":"Greene","voorvoegselGeslachtsnaam":"","voorletters":"","voornamen":"Lori","geslachtsaanduiding":"","geboortedatum":"1981-04-15","verblijfsadres":null,"subVerblijfBuitenland":null}}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '726'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
38 changes: 38 additions & 0 deletions migration/cassettes/test_existing_dummy_tokens.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/7853958c-4ff1-4b62-bb81-1277346692bf","bronorganisatie":"719250341","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"Harry","voorvoegselAchternaam":"","achternaam":"Potter","telefoonnummer":"","emailadres":"","adres":null,"subject":"","subjectType":"natuurlijk_persoon","aanmaakkanaal":"","geverifieerd":false,"subjectIdentificatie":{"inpBsn":"024325818","anpIdentificatie":"0","inpANummer":"","geslachtsnaam":"Huffman","voorvoegselGeslachtsnaam":"","voorletters":"H","voornamen":"Frank","geslachtsaanduiding":"","geboortedatum":"2005-09-30","verblijfsadres":null,"subVerblijfBuitenland":null}}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '727'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
38 changes: 38 additions & 0 deletions migration/cassettes/test_incorrect_subject_url.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/c59c00b3-3445-4731-8a6b-ee26992a5358","bronorganisatie":"892036175","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"","voorvoegselAchternaam":"","achternaam":"","telefoonnummer":"","emailadres":"","adres":null,"subject":"","subjectType":null,"aanmaakkanaal":"","geverifieerd":false}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '416'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
38 changes: 38 additions & 0 deletions migration/cassettes/test_natuurlijk_persoon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/c29538c1-98b8-4773-8ac1-f0af110d92f9","bronorganisatie":"620357848","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"Harry","voorvoegselAchternaam":"","achternaam":"Potter","telefoonnummer":"","emailadres":"","adres":null,"subject":"","subjectType":"natuurlijk_persoon","aanmaakkanaal":"","geverifieerd":false,"subjectIdentificatie":{"inpBsn":"024325818","anpIdentificatie":"0","inpANummer":"","geslachtsnaam":"Williams","voorvoegselGeslachtsnaam":"","voorletters":"H","voornamen":"Nicole","geslachtsaanduiding":"","geboortedatum":"1973-02-23","verblijfsadres":null,"subVerblijfBuitenland":null}}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '729'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
40 changes: 40 additions & 0 deletions migration/cassettes/test_niet_natuurlijk_persoon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/abd7a618-1177-4d17-a9d9-a3b6f9ee8606","bronorganisatie":"613907826","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"","voorvoegselAchternaam":"","achternaam":"","telefoonnummer":"","emailadres":"","adres":null,"subject":"","subjectType":"niet_natuurlijk_persoon","aanmaakkanaal":"","geverifieerd":false,"subjectIdentificatie":{"innNnpId":"807371440","annIdentificatie":"","statutaireNaam":"Foobar
Inc.","innRechtsvorm":"vereniging_van_eigenaars","bezoekadres":"Masonhof 351\n6335
OX\nMetslawier","subVerblijfBuitenland":null}}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '660'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/c59c00b3-3445-4731-8a6b-ee26992a5358","bronorganisatie":"892036175","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"","voorvoegselAchternaam":"","achternaam":"","telefoonnummer":"","emailadres":"","adres":null,"subject":"","subjectType":null,"aanmaakkanaal":"","geverifieerd":false}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '416'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
38 changes: 38 additions & 0 deletions migration/cassettes/test_no_subject_and_subject_identificatie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.32.3
method: GET
uri: http://localhost:8000/klanten/api/v1/klanten
response:
body:
string: '{"count":1,"next":null,"previous":null,"results":[{"url":"http://localhost:8000/klanten/api/v1/klanten/c29538c1-98b8-4773-8ac1-f0af110d92f9","bronorganisatie":"620357848","klantnummer":"0","bedrijfsnaam":"","functie":"","websiteUrl":"","voornaam":"Harry","voorvoegselAchternaam":"","achternaam":"Potter","telefoonnummer":"","emailadres":"","adres":null,"subject":"","subjectType":"natuurlijk_persoon","aanmaakkanaal":"","geverifieerd":false,"subjectIdentificatie":{"inpBsn":"024325818","anpIdentificatie":"0","inpANummer":"","geslachtsnaam":"Williams","voorvoegselGeslachtsnaam":"","voorletters":"H","voornamen":"Nicole","geslachtsaanduiding":"","geboortedatum":"1973-02-23","verblijfsadres":null,"subVerblijfBuitenland":null}}]}'
headers:
API-version:
- 1.0.0
Allow:
- GET, POST, HEAD, OPTIONS
Content-Length:
- '729'
Content-Type:
- application/json
Referrer-Policy:
- same-origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- DENY
X-XSS-Protection:
- 1; mode=block
status:
code: 200
message: OK
version: 1
74 changes: 74 additions & 0 deletions migration/cassettes/test_pagination.yaml

Large diffs are not rendered by default.

Loading
Loading