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

Fix issues #9 and #11 #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 11 additions & 8 deletions clients/directory_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,17 @@ def get_all_directory_services(biobanks: list[OrganizationDirectoryDTO]):
}
'''
results = requests.post(DIRECTORY_API_URL, json={'query': emx2_services_query}).json()
for service in results['data']['Services']:
service_biobank = get_biobank_by_service(biobanks, service['id'])
service_resource_directory = ResourceDirectoryDTO(id=service['id'], name=service['name'],
description=service['description'], biobank=service_biobank,
contactEmail=service['contactInformation'][
'email'] if 'contactInformation' in service else '')
parsed_services.append(service_resource_directory)
return parsed_services
if('Services' in results['data'].keys()):
print(results['data'])
for service in results['data']['Services']:
service_biobank = get_biobank_by_service(biobanks, service['id'])
service_resource_directory = ResourceDirectoryDTO(id=service['id'], name=service['name'],
description=service['description'], biobank=service_biobank,
contactEmail=service['contactInformation'][
'email'] if 'contactInformation' in service else '')
parsed_services.append(service_resource_directory)
return parsed_services
return []


def get_biobank_by_service(biobanks: list[OrganizationDirectoryDTO], service_id):
Expand Down
4 changes: 2 additions & 2 deletions clients/negotiator_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def get_all_negotiator_networks(self):
def add_organizations(self, organizations: list[OrganizationDirectoryDTO]):
self.post('organizations', data=json.dumps(organizations))

def update_organization_info(self, id, name, external_id, description, contact_email, uri):
def update_organization_info(self, id, name, external_id, description, contact_email, uri, withdrawn):
self.put(f'organizations/{id}', data=json.dumps({'name': name, 'externalId': external_id,
'description': description, 'contactEmail': contact_email,
'uri': uri}))
'uri': uri, 'withdrawn': withdrawn}))

def add_resources(self, resources: list):
added_resources = self.post('resources', data=json.dumps(resources))
Expand Down
1 change: 1 addition & 0 deletions models/dto/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class NegotiatorOrganizationDTO(BaseModel):
description: Optional[str] = Field(default='')
contactEmail: Optional[str] = Field(default='')
uri: Optional[str] = Field(default='')
withdrawn: Optional[bool] = Field(default=False)

@staticmethod
def parse(negotiator_data):
Expand Down
8 changes: 5 additions & 3 deletions synchronization/sync_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ def sync_organizations(negotiator_client: NegotiatorAPIClient, directory_organzi
check_fields(negotiation_organization.description, directory_organization.description) or
(directory_organization.contact is not None and check_fields(negotiation_organization.contactEmail,
directory_organization.contact.email)) or
check_fields(negotiation_organization.uri, directory_organization.url)):
check_fields(negotiation_organization.uri, directory_organization.url) or
check_fields(negotiation_organization.withdrawn, directory_organization.withdrawn)):
LOG.info(
f'Updating name and/or description and/or contact email and/or uri for organization: {external_id}')
f'Updating name and/or description and/or contact email and/or uri and/or withdrawn for organization: {external_id}')
LOG.info(f'Current organization name is: {negotiation_organization.name}')
LOG.info(f'New organization name is: {directory_organization.name}')
negotiator_client.update_organization_info(negotiation_organization.id, directory_organization.name,
external_id, directory_organization.description,
directory_organization.contact.email,
directory_organization.url)
directory_organization.url,
directory_organization.withdrawn)
else:
LOG.info(
f'Organization with external id {external_id} not found, including it to the list of organizations to add')
Expand Down
21 changes: 16 additions & 5 deletions tests/integration/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_networks_initial_sync_ok():
def test_organization_sync_when_new_added_and_then_updated():
add_or_update_biobank("test_negotiator_sync", "test_negotiator_sync", "test negotiator sync",
"test negotiator sync", 'bbmri-eric:contactID:EU_network',
"http://test_negotiator_sync.org", 'insert')
"http://test_negotiator_sync.org", 'false', 'insert')

biobanks_after_add = get_all_biobanks()
assert len(biobanks_after_add) == len(pytest.directory_organizations) + 1
Expand All @@ -50,7 +50,7 @@ def test_organization_sync_when_new_added_and_then_updated():

add_or_update_biobank("test_negotiator_sync", "test_negotiator_sync", "test negotiator sync newname",
"test negotiator sync", 'bbmri-eric:contactID:EU_network',
"http://test_negotiator_sync.org", 'update')
"http://test_negotiator_sync.org", 'false', 'update')
biobanks_after_update_name = get_all_biobanks()
sync_organizations(pytest.negotiator_client, biobanks_after_update_name,
negotiator_organizations_after_bb_add_and_sync)
Expand All @@ -61,7 +61,7 @@ def test_organization_sync_when_new_added_and_then_updated():
assert organization_with_name_upd.name == "test negotiator sync newname"
add_or_update_biobank("test_negotiator_sync", "test_negotiator_sync", "test negotiator sync newname",
"test negotiator sync newdesc", 'bbmri-eric:contactID:EU_network',
"http://test_negotiator_sync.org", 'update')
"http://test_negotiator_sync.org", 'false', 'update')
biobanks_after_update_desc = get_all_biobanks()
sync_organizations(pytest.negotiator_client, biobanks_after_update_desc,
negotiator_organizations_after_update_name)
Expand All @@ -73,7 +73,7 @@ def test_organization_sync_when_new_added_and_then_updated():
assert organization_with_desc_upd.description == "test negotiator sync newdesc"
add_or_update_biobank("test_negotiator_sync", "test_negotiator_sync", "test negotiator sync newname",
"test negotiator sync newdesc", 'bbmri-eric:contactID:EU_network',
"http://test_negotiator_sync.org", 'update')
"http://test_negotiator_sync.org", 'false', 'update')
update_person_email_contact('[email protected]')
biobanks_after_update_email = get_all_biobanks()

Expand All @@ -87,7 +87,7 @@ def test_organization_sync_when_new_added_and_then_updated():
assert organization_with_email_upd.contactEmail == '[email protected]'
add_or_update_biobank("test_negotiator_sync", "test_negotiator_sync", "test negotiator sync newname",
"test negotiator sync newdesc", 'bbmri-eric:contactID:EU_network',
"http://test_negotiator_sync_newurl.org", 'update')
"http://test_negotiator_sync_newurl.org", 'false', 'update')
biobanks_after_update_url = get_all_biobanks()
sync_organizations(pytest.negotiator_client, biobanks_after_update_url,
negotiator_organizations_after_update_email)
Expand All @@ -96,6 +96,17 @@ def test_organization_sync_when_new_added_and_then_updated():
organization_with_url_upd = \
[org for org in negotiator_organizations_after_update_url if org.externalId == "test_negotiator_sync"][0]
assert organization_with_url_upd.uri == "http://test_negotiator_sync_newurl.org"
add_or_update_biobank("test_negotiator_sync", "test_negotiator_sync", "test negotiator sync newname",
"test negotiator sync newdesc", 'bbmri-eric:contactID:EU_network',
"http://test_negotiator_sync_newurl.org", 'true', 'update')
biobanks_after_update_withdrawn = get_all_biobanks()
sync_organizations(pytest.negotiator_client, biobanks_after_update_withdrawn,
negotiator_organizations_after_update_url)
negotiator_organizations_after_update_withdrawn = pytest.negotiator_client.get_all_organizations()
assert len(negotiator_organizations_after_update_withdrawn) == len(negotiator_organizations_after_update_withdrawn)
organization_with_withdrawn_upd = \
[org for org in negotiator_organizations_after_update_withdrawn if org.externalId == "test_negotiator_sync"][0]
assert organization_with_withdrawn_upd.withdrawn == True
delete_object_from_directory("test_negotiator_sync", "Biobanks")


Expand Down
4 changes: 2 additions & 2 deletions tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@


def add_or_update_biobank(biobank_id, biobank_pid, biobank_name, biobank_description, biobank_contact, biobank_url,
operation=Literal['insert', 'update']):
biobank_withdrawn, operation=Literal['insert', 'update']):
session = pytest.directory_session
query = f'mutation {operation}($value:[BiobanksInput]){{{operation}(Biobanks:$value){{message}}}}'
variables = {
"value": [
{
"withdrawn": "false",
"withdrawn": biobank_withdrawn,
"id": biobank_id,

"pid": biobank_pid,
Expand Down
5 changes: 4 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ def check_fields(negotiator_field, directory_field):
else:
if negotiator_field is None:
return True
return negotiator_field.strip() != directory_field.strip()
if isinstance(negotiator_field, str) and isinstance(directory_field, str):
return negotiator_field.strip() != directory_field.strip()
else:
return negotiator_field != directory_field
Loading