| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2019 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
|
| 10 |
import logging |
| 11 |
import pytest |
| 12 |
import os |
| 13 |
|
| 14 |
from lib389._constants import * |
| 15 |
from test389.topologies import topology_st |
| 16 |
from lib389.idm.user import UserAccounts |
| 17 |
|
| 18 |
pytestmark = pytest.mark.tier3 |
| 19 |
|
| 20 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.skipif(os.getenv('MIGRATION') is None, reason="This test is meant to execute in specific test environment") |
| 25 |
def test_import_data_to_target_host(topology_st): |
| 26 |
"""Import file created in export_data_test.py using a single instance of Directory Server |
| 27 |
|
| 28 |
:id: 7e896b0c-6838-49c7-8e1d-5e8114f5fb02 |
| 29 |
:setup: Standalone |
| 30 |
:steps: |
| 31 |
1. Check that attribute values are present in input file |
| 32 |
2. Import input file |
| 33 |
3. Check imported user data |
| 34 |
:expectedresults: |
| 35 |
1. Success |
| 36 |
2. Success |
| 37 |
3. Success |
| 38 |
""" |
| 39 |
|
| 40 |
standalone = topology_st.standalone |
| 41 |
input_file = os.path.join(topology_st.standalone.ds_paths.ldif_dir, "migration_export.ldif") |
| 42 |
|
| 43 |
log.info("Check that value of attribute is present in the exported file") |
| 44 |
with open(input_file, 'r') as ldif_file: |
| 45 |
ldif = ldif_file.read() |
| 46 |
assert 'employeeNumber: 1000' in ldif |
| 47 |
assert 'telephoneNumber: 1234567890' in ldif |
| 48 |
assert 'uid: \\#\\,\\+"\\\\>:\\=\\<\\<\\>\\;/' in ldif |
| 49 |
|
| 50 |
log.info('Stopping the server and running offline import...') |
| 51 |
standalone.stop() |
| 52 |
assert standalone.ldif2db(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], encrypt=None, excludeSuffixes=None, |
| 53 |
import_file=input_file) |
| 54 |
standalone.start() |
| 55 |
|
| 56 |
log.info("Check imported user data") |
| 57 |
users = UserAccounts(standalone, DEFAULT_SUFFIX) |
| 58 |
test_user = users.get('testuser') |
| 59 |
assert test_user.present('employeeNumber', value='1000') |
| 60 |
assert test_user.present('telephoneNumber', value='1234567890') |
| 61 |
test_user = users.get('\\#\\,\\+"\\\\>:\\=\\<\\<\\>\\;/') |
| 62 |
assert test_user.present('cn', value='tuser2') |
| 63 |
assert test_user.present('uid', value='\\#\\,\\+"\\\\>:\\=\\<\\<\\>\\;/') |
| 64 |
|
| 65 |
|
| 66 |
if __name__ == '__main__': |
| 67 |
# Run isolated |
| 68 |
# -s for DEBUG mode |
| 69 |
CURRENT_FILE = os.path.realpath(__file__) |
| 70 |
pytest.main(["-s", CURRENT_FILE]) |