Esempio n. 1
0
 def test_add_remove_experiment_link(self):
     admin_auth = HmacAuth("edd", self.admin_ice_user.email)
     ice = IceApi(admin_auth)
     ice.write_enabled = True
     study = factory.StudyFactory()
     study_url = f"https://edd.example.org/s/{study.slug}/"
     for entry_id in self.db_ids:
         ice.add_experiment_link(entry_id, study.name, study_url)
     # verify link exists on a given entry
     found_links = list(ice.fetch_experiment_links(self.db_ids[3]))
     self.assertEqual(len(found_links), 1)
     # verify that removal works
     ice.unlink_entry_from_study(self.db_ids[3], study_url)
     found_links = list(ice.fetch_experiment_links(self.db_ids[3]))
     self.assertEqual(len(found_links), 0)
Esempio n. 2
0
def create_ice_connection(user_token):
    """Creates an instance of the ICE API using common settings."""
    # Use getattr to load settings without raising AttributeError
    key_id = getattr(settings, "ICE_KEY_ID", None)
    url = getattr(settings, "ICE_URL", None)
    verify = getattr(settings, "ICE_VERIFY_CERT", False)
    timeout = getattr(settings, "ICE_REQUEST_TIMEOUT", None)
    if key_id and url:
        try:
            auth = HmacAuth(key_id=key_id, username=user_token)
            ice = IceApi(auth=auth, base_url=url, verify_ssl_cert=verify)
            if timeout:
                ice.timeout = timeout
            ice.write_enabled = True
            return ice
        except Exception as e:
            logger.error("Failed to create ICE connection: %s", e)
    return None