def get_auth_manager(self): # Auth types that don't require a username: if self.auth_type is None: return AuthManager() if self.auth_type == OAUTH1: return OAuth1Manager( client_id=self.client_id, client_secret=self.plaintext_client_secret, api_endpoints=self._get_oauth1_api_endpoints(), connection_settings=self, ) if self.auth_type == OAUTH2_CLIENT: return OAuth2ClientGrantManager( self.url, client_id=self.client_id, client_secret=self.plaintext_client_secret, token_url=self.token_url, refresh_url=self.refresh_url, connection_settings=self, ) # Auth types that require a username: if not isinstance(self.username, str): return AuthManager() if self.auth_type == BASIC_AUTH: return BasicAuthManager( self.username, self.plaintext_password, ) if self.auth_type == DIGEST_AUTH: return DigestAuthManager( self.username, self.plaintext_password, ) if self.auth_type == BEARER_AUTH: return BearerAuthManager( self.username, self.plaintext_password, ) if self.auth_type == OAUTH2_PWD: return OAuth2PasswordGrantManager( self.url, self.username, self.plaintext_password, client_id=self.client_id, client_secret=self.plaintext_client_secret, token_url=self.token_url, refresh_url=self.refresh_url, pass_credentials_in_header=self.pass_credentials_in_header, connection_settings=self, ) raise ValueError(f'Unknown auth type {self.auth_type!r}')
def get_auth_manager(self): if self.auth_type is None: return AuthManager() if self.auth_type == BASIC_AUTH: return BasicAuthManager( self.username, self.plaintext_password, ) if self.auth_type == DIGEST_AUTH: return DigestAuthManager( self.username, self.plaintext_password, ) if self.auth_type == OAUTH1: return OAuth1Manager( client_id=self.client_id, client_secret=self.plaintext_client_secret, api_endpoints=self._get_oauth1_api_endpoints(), connection_settings=self, ) if self.auth_type == BEARER_AUTH: return BearerAuthManager( self.username, self.plaintext_password, ) if self.auth_type == OAUTH2_PWD: return OAuth2PasswordGrantManager( self.url, self.username, self.plaintext_password, client_id=self.client_id, client_secret=self.plaintext_client_secret, api_settings=self._get_oauth2_api_settings(), connection_settings=self, )
def get_auth_manager(self): if self.auth_type is None: return AuthManager() if self.auth_type == BASIC_AUTH: return BasicAuthManager( self.username, self.plaintext_password, ) if self.auth_type == DIGEST_AUTH: return DigestAuthManager( self.username, self.plaintext_password, ) if self.auth_type == OAUTH1: raise NotImplementedError( _('OAuth1 authentication workflow not yet supported.')) if self.auth_type == BEARER_AUTH: return BearerAuthManager( self.username, self.plaintext_password, )
def test_no_auth(self): auth_manager = AuthManager() auth = auth_manager.get_auth() self.assertIsNone(auth)
def test_requests(self): repeater = Mock() repeater.dhis2_entity_config = Dhis2EntityConfig( case_configs=[self.subcase_config, self.supercase_config] ) requests = Requests( DOMAIN, 'https://dhis2.example.com/', auth_manager=AuthManager(), ) value_source_configs = [ {'case_property': 'external_id'}, {'case_property': 'first_name'}, {'case_property': 'last_name'}, {'case_property': 'date_of_birth'}, {'case_property': 'dhis2_org_unit_id'}, ] case_trigger_infos = [ get_case_trigger_info_for_case(self.parent_case, value_source_configs), get_case_trigger_info_for_case(self.child_case, value_source_configs) ] send_dhis2_entities(requests, repeater, case_trigger_infos) calls = [ call( '/api/trackedEntityInstances/', json={ 'trackedEntityType': 'person12345', 'orgUnit': 'abcdef12345', 'attributes': [ {'attribute': 'w75KJ2mc4zz', 'value': 'Alice'}, {'attribute': 'zDhUuAYrxNC', 'value': 'Appleseed'} ] }, raise_for_status=True, ), call( '/api/trackedEntityInstances/', json={ 'trackedEntityType': 'person12345', 'orgUnit': 'abcdef12345', 'attributes': [ {'attribute': 'w75KJ2mc4zz', 'value': 'Johnny'}, {'attribute': 'zDhUuAYrxNC', 'value': 'Appleseed'}, {'attribute': 'iESIqZ0R0R0', 'value': '2021-08-27'}, ] }, raise_for_status=True, ), call( '/api/relationships/', json={ 'relationshipType': 'a2b12345678', 'from': {'trackedEntityInstance': {'trackedEntityInstance': 'ParentTEI12'}}, 'to': {'trackedEntityInstance': {'trackedEntityInstance': 'ChildTEI123'}}, }, raise_for_status=True, ), call( '/api/relationships/', json={ 'relationshipType': 'b2a12345678', 'from': {'trackedEntityInstance': {'trackedEntityInstance': 'ChildTEI123'}}, 'to': {'trackedEntityInstance': {'trackedEntityInstance': 'ParentTEI12'}}, }, raise_for_status=True, ) ] self.post_func.assert_has_calls(calls)
def setUp(self): self.no_auth = AuthManager()