def _create_data(cls): conn = ConnectionSettings(domain=cls.domain, name="motech_conn", url="url", auth_type="Bearer Token", api_auth_settings="", username="", password="", client_id="", client_secret="", skip_cert_verify=False) conn.save() cls.connection_setting = conn sql_dsm = SQLDataSetMap(domain=cls.domain, connection_settings=conn, day_to_send=1, description="This is a description", ucr_id="1234") sql_dsm.save() cls.dataset_map = sql_dsm sql_dvm = SQLDataValueMap(dataset_map=sql_dsm, column="My column", data_element_id="D1234567891", comment="Testy comment") sql_dvm.save() cls.data_value_map = sql_dvm
class ConnectionSettingsAuthManagerTests(TestCase): username = '******' password = '******' def setUp(self): self.connx = ConnectionSettings( domain='meaning-of-life', name='Mr. Creosote', url='https://restaurant.fr/api/', auth_type=BASIC_AUTH, username=self.username, notify_addresses_str='*****@*****.**', ) self.connx.plaintext_password = self.password self.connx.save() def tearDown(self): self.connx.delete() def test_connection_settings_auth_manager(self): auth_manager = self.connx.get_auth_manager() self.assertIsInstance(auth_manager, BasicAuthManager) self.assertEqual(auth_manager.username, self.username) self.assertEqual(auth_manager.password, self.password) self.assertNotEqual(auth_manager.password, self.connx.password) self.assertTrue(self.connx.password.startswith(f'${ALGO_AES}$'))
class TestApiSettingsMigration(TestCase): username = '******' password = '******' def setUp(self): self.connx_dhis2 = ConnectionSettings( domain='meaning-of-life', name='Mr. Creosote', url='https://restaurant.fr/api/', auth_type=OAUTH2_PWD, username=self.username, notify_addresses_str='*****@*****.**', api_auth_settings='dhis2_auth_settings', ) self.connx_dhis2.plaintext_password = self.password self.connx_dhis2.save() def test_dhis2_connection_updated(self): copy_api_auth_settings(self.connx_dhis2) self.assertEqual(self.connx_dhis2.token_url, "https://restaurant.fr/api/uaa/oauth/token") self.assertEqual( self.connx_dhis2.refresh_url, "https://restaurant.fr/api/uaa/oauth/token", )
def connection_fixture(domain_name): connx = ConnectionSettings( domain=domain_name, name='example.com', url='https://example.com/forwarding', ) connx.save() try: yield connx finally: connx.delete()
def create_conn_settings(dhis2_conn: Dhis2Connection) -> ConnectionSettings: """ Creates and returns a ConnectionSettings instance for ``dhis2_conn``. """ url = strip_api(dhis2_conn.server_url) conn_settings = ConnectionSettings( domain=dhis2_conn.domain, name=url, url=url, auth_type=BASIC_AUTH, username=dhis2_conn.username, skip_cert_verify=dhis2_conn.skip_cert_verify, notify_addresses_str="") conn_settings.plaintext_password = dhis2_conn.plaintext_password conn_settings.save() return conn_settings
def create_connection_settings(self): if self.connection_settings_id: return # Nothing to do conn = ConnectionSettings( domain=self.domain, name=self.url, url=self.url, auth_type=self.auth_type, username=self.username, skip_cert_verify=self.skip_cert_verify, notify_addresses_str=self.notify_addresses_str or '', ) # Allow ConnectionSettings to encrypt old Repeater passwords: conn.plaintext_password = self.plaintext_password conn.save() self.connection_settings_id = conn.id self.save() return conn
def test_connection_settings_auth_manager(self): connx = ConnectionSettings( domain=DOMAIN, name='Mr. Creosote', url=URL, auth_type=BASIC_AUTH, username=USERNAME, password='', notify_addresses_str=ADMIN, ) connx.plaintext_password = PASSWORD connx.save() try: auth_manager = connx.get_auth_manager() self.assertIsInstance(auth_manager, BasicAuthManager) self.assertEqual(auth_manager.username, USERNAME) self.assertEqual(auth_manager.password, PASSWORD) self.assertNotEqual(auth_manager.password, connx.password) self.assertTrue(connx.password.startswith(f'${ALGO_AES}$')) finally: connx.delete()
def test_get_programs_by_id(self): program_id = 'test program' form = { "domain": DOMAIN, "form": { "@xmlns": "test_xmlns", "event_date": "2017-05-25T21:06:27.012000", "completed_date": "2017-05-25T21:06:27.012000", "event_location": "-33.6543213 19.12344312 abcdefg", "name": "test event", "meta": { "location": 'test location', "timeEnd": "2017-05-25T21:06:27.012000", "timeStart": "2017-05-25T21:06:17.739000", "userID": self.user.user_id, "username": self.user.username } }, "received_on": "2017-05-26T09:17:23.692083Z", } config = { 'form_configs': json.dumps([{ 'xmlns': 'test_xmlns', 'program_id': program_id, 'event_status': 'COMPLETED', 'event_location': { 'form_question': '/data/event_location' }, 'completed_date': { 'doc_type': 'FormQuestion', 'form_question': '/data/completed_date', 'external_data_type': DHIS2_DATA_TYPE_DATE }, 'org_unit_id': { 'doc_type': 'FormUserAncestorLocationField', 'form_user_ancestor_location_field': LOCATION_DHIS_ID }, 'datavalue_maps': [ { 'data_element_id': 'dhis2_element_id', 'value': { 'doc_type': 'FormQuestion', 'form_question': '/data/name' } } ] }]) } config_form = Dhis2ConfigForm(data=config) self.assertTrue(config_form.is_valid()) data = config_form.cleaned_data repeater = Dhis2Repeater(domain=DOMAIN) conn = ConnectionSettings(domain=DOMAIN, url="http://dummy.com") conn.save() repeater.dhis2_config.form_configs = [Dhis2FormConfig.wrap(fc) for fc in data['form_configs']] repeater.connection_settings_id = conn.id repeater.save() info = CaseTriggerInfo( domain=DOMAIN, case_id=None, owner_id='test_location', form_question_values=get_form_question_values(form), ) programs = get_programs_by_id(info, repeater.dhis2_config) self.assertDictEqual( programs[program_id]['geometry'], {'type': 'Point', 'coordinates': [-33.6543, 19.1234]} )