Chemical-Curation / chemcurator_django

Backend services for chemical curation
https://api.chemreg.epa.gov
MIT License
1 stars 0 forks source link

232 resolution data sync #266

Closed michael-barbour closed 3 years ago

michael-barbour commented 3 years ago

closes #232

Django changes for sync.

New Endpoints to Resolver

Considered out of scope

Added new environment variable

This is going to be the location of the resolution url. We may also need a way to refer to the uri's but for now those are hardcoded strings (should probably be moved to chemreg/config/settings.py).

RESOLUTION_URL=

Testing

These tests will require you to verify both your resolver and chemreg databases are synced. You'll need access to resolver's db, as you will be performing direct operations to simulate desyncs as well as verify changes have succeeded.

Signals

To test sync functionality, any shell commands should work. Feel welcome to do these commands from postman or however you'd prefer to test. I will try to write up a less comprehensive collection of requests for the sake of demoing this on sprint review Thursday. Here is a good example of some commands to use:

from chemreg.substance.tests.factories import *
from chemreg.substance.models import *

SubstanceFactory.create_batch(10)  # verify 10 substances got synced
Substance.objects.first().delete()       # should be 9 substances
Substance.objects.filter().delete()      # should be no substances

SynonymFactory.create_batch(3)      # 3 substances, 3 synonyms
SynonymFactory.create(substance={"type": "substance", "id": Substance.objects.first().pk})  # 1 substance with 2 synonyms, 2 with 1
Synonym.objects.last().delete()        # 3 synonyms again (1 sub with None most likely)

syn = Synonym.objects.last()           # Rename a synonym identifier (should be reflected in resolver DB)
syn.identifier="barfoo"
syn.save()

Synonym.objects.filter().delete()       # No synonyms

sub = Substance.objects.first()         # Rename a substance
sub.preferred_name = "Foobar"
sub.save()

Management

To test management commands, desync your resolver and chemreg dbs. These commands performed on a clean db. If you need to clear your db tables run model.objects.filter().delete()

Test positive sync:

SynonymFactory.create_batch(3)

- Clear your resolver db. (use whatever you like.  pgadmin, flask shell, etc...)
- Run `python manage.py sync` on your chemreg command line
- Confirm 3 substances and 3 synonyms are in your resolver db

**Test negative sync:**
- Add 3 synonyms and 3 substances then `_raw_delete()` them (no signals sent):
```python
from chemreg.substance.tests.factories import *
from chemreg.substance.models import *

SynonymFactory.create_batch(3)
Synonym.objects.filter()._raw_delete(using='default')
Substance.objects.filter()._raw_delete(using='default')