def test_schema(base_get_mock): client = CadcTapClient(net.Subject()) # default format client.schema() base_get_mock.assert_called_with( (TABLES_CAPABILITY_ID, None))
def test_schema(caps_get_mock, base_get_mock): caps_get_mock.return_value = BASE_URL base_get_mock.return_value.text = \ open(os.path.join(TESTDATA_DIR, 'db_schema.xml'), 'r').read() client = CadcTapClient(net.Subject()) # default schema db_schema = client.get_schema() assert 3 == len(db_schema) for schema in db_schema: assert 'DB schema' == schema.description assert ['Table', 'Description'] == schema.columns if 'ivoa' == schema.name: assert 3 == len(schema.rows) elif 'caom2' in schema.name: assert 14 == len(schema.rows) elif 'tap_schema' == schema.name: assert 5 == len(schema.rows) else: assert False, 'Unexpected schema' base_get_mock.assert_called_with((TABLES_CAPABILITY_ID, None), params={'detail': 'min'}) # table schema table_schema_mock = Mock() base_get_mock.reset_mock() table_schema_mock.text = open(os.path.join(TESTDATA_DIR, 'table_schema.xml'), 'r').read() permission_mock = Mock() permission_mock.text = 'owner=someone\npublic=true\nr-group=\n' \ 'rw-group=ivo://cadc.nrc.ca/gms?CADC' base_get_mock.side_effect = [table_schema_mock, permission_mock] tb_schema = client.get_table_schema('caom2.Observation') assert 3 == len(tb_schema) assert 'caom2.Observation' == tb_schema[0].name assert 'the main CAOM Observation table' == tb_schema[0].description assert ['Name', 'Type', 'Index', 'Description'] == tb_schema[0].columns assert 45 == len(tb_schema[0].rows) assert 'Foreign Keys' == tb_schema[1].name assert 'Foreign Keys for table' == tb_schema[1].description assert ['Target Table', 'Target Col', 'From Column', 'Description'] == \ tb_schema[1].columns assert 1 == len(tb_schema[1].rows) assert 'caom2.ObservationMember' == tb_schema[1].rows[0][0] assert 1 == len(tb_schema[2].rows) assert ['Owner', 'Others Read', 'Group Read', 'Group Write'] == \ tb_schema[2].columns assert 'Permissions' == tb_schema[2].name assert 'Permissions for caom2.Observation' == \ tb_schema[2].description assert 'someone' == tb_schema[2].rows[0][0] assert 'true' == tb_schema[2].rows[0][1] assert '-' == tb_schema[2].rows[0][2] assert 'CADC' == tb_schema[2].rows[0][3] calls = [call(('ivo://ivoa.net/std/VOSI#tables-1.1', 'caom2.Observation'), params={'detail': 'min'}), call(('ivo://ivoa.net/std/VOSI#table-permissions-1.x', 'caom2.Observation'))] base_get_mock.assert_has_calls(calls) # check displays are also working although the visual part not tested client.get_schema = Mock(return_value=db_schema) client.schema('foo') client.get_table_schema = Mock(return_value=tb_schema) client.schema('caom2.Observation') # test get_schema now client = CadcTapClient(net.Subject()) client._db_schemas = {'tap': 'Schema goes in here'} client.get_permissions = Mock(return_value='Permissions go in here') assert not client.get_schema('foo') assert ['Schema goes in here', 'Permissions go in here'] == \ client.get_schema('tap')