class SubstanceIndex(Index) for substance specific handling.
post-save & post-delete signals for Substance and Synonym
New Endpoints to Resolver
POST/api/v1/substances/_index to add or update substances
DELETE/api/v1/substances/_index to remove all substances
Considered out of scope
Error handling and logging. Failed requests currently fail silently.
Async. Currently indexing several substances will take RTT * # of substances
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:
Add 3 synonyms and 3 substances:
from chemreg.substance.tests.factories import *
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')
Verify there are 3 substances with 3 synonyms in resolver and 0 substances and 0 synonyms in chemreg
Run python manage.py sync on your chemreg command line
closes #232
Django changes for sync.
class Index
for general handling of syncingclass SubstanceIndex(Index)
for substance specific handling.post-save
&post-delete
signals for Substance and SynonymNew Endpoints to Resolver
/api/v1/substances/_index
to add or update substances/api/v1/substances/_index
to remove all substancesConsidered out of scope
RTT * # of substances
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
).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:
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)
python manage.py sync
on your chemreg command line