def unlink_ice_entry_from_study(self, strain, study): """ Task runs the code to de-register a link between an ICE entry and an EDD study. :param strain: the primary key of the EDD main.models.Strain in the former link :param study: the primary key of the EDD main.models.Study in the former link :throws Exception: for any errors other than communication errors to ICE instance """ query = models.Strain.objects.filter(pk=strain, line__study__pk=study) if not query.exists(): try: record = models.Strain.objects.get(pk=strain) study_obj = models.Study.objects.get(pk=study) url = build_study_url(study_obj.slug) # always running as configured admin account ice = AdminRegistry() with ice.login(): entry = ice.get_entry(record.registry_id) for link in entry.list_links(): # first item is ID, third item is the link URL if link[2] == url: entry.remove_link(link[0]) except Exception as e: # Retry when there are errors communicating with ICE raise self.retry(exc=e, countdown=delay_calculation(self), max_retries=10)
def test_ice_admin_create_user(self): user = UserFactory() admin_ice = AdminRegistry() with admin_ice.login(): created_id = admin_ice.create_user(user) found_id = admin_ice.get_user_id(user) assert created_id == found_id
def link_ice_entry_to_study(self, strain, study): """ Task runs the code to register a link between an ICE entry and an EDD study. :param strain: the primary key of the EDD main.models.Strain in the link :param study: the primary key of the EDD main.models.Study in the link :throws Exception: for any errors other than communication errors to ICE instance """ # check that strain and study are still linked query = models.Strain.objects.filter(pk=strain, line__study__pk=study) if query.exists(): try: # query the slug and name in use when this task runs record = ( query.annotate( study_slug=F("line__study__slug"), study_name=F("line__study__name") ) .distinct() .get() ) # always running as configured admin account ice = AdminRegistry() with ice.login(): entry = ice.get_entry(record.registry_id) entry.add_link(record.study_name, build_study_url(record.study_slug)) except Exception as e: # Retry when there are errors communicating with ICE raise self.retry(exc=e, countdown=delay_calculation(self), max_retries=10)
def test_ice_admin_bulk_upload_upstream_failure(self): admin_ice = AdminRegistry() with admin_ice.login(): admin_failure = patch.object( admin_ice.session, "send", side_effect=ValueError("Dummy Exception"), ) with admin_failure, self.assertRaises(RegistryError): admin_ice.bulk_upload(BytesIO(b""))
def test_ice_admin_get_user_upstream_failure(self): admin_ice = AdminRegistry() with admin_ice.login(): admin_failure = patch.object( admin_ice.session, "send", side_effect=ValueError("Dummy Exception"), ) with admin_failure, self.assertRaises(RegistryError): admin_ice.get_user_id(self.admin_ice_user)
def setUpClass(cls): super().setUpClass() registry = AdminRegistry() with registry.login(): try: # make sure ICE has users matching EDD users cls._ensureTestUsers(registry) # populate ICE with some strains entries = cls._populateTestStrains(registry) # add strains to a folder cls._populateTestFolder(registry, entries) except Exception as e: cls.tearDownClass() raise e
def test_ice_admin_create_user_twice(self): admin_ice = AdminRegistry() with admin_ice.login(), self.assertRaises(RegistryError): admin_ice.create_user(self.admin_ice_user)
def test_ice_admin_unknown_user(self): user = UserFactory() admin_ice = AdminRegistry() with admin_ice.login(): found_id = admin_ice.get_user_id(user) assert found_id is None