示例#1
0
def test_create_customer_with_required_params_only():
    bearer_token = IVR.take_token(data['login'], data['password'])
    new_customer = {
        'name': 'testIVR_' + str(int(time.time())),
        'status': '1',
        'login': '******' + str(int(time.time())),
        'password': '******' + str(random.uniform(1, 2000000)),
        'email': str(int(time.time())) + '@gg.ru',
        'phone': '79777777777'
    }
    r = IVR.create_customer(bearer_token, new_customer)
    assert r.status_code == 201
    response = r.json()
    assert response['id']
    assert new_customer['name'] == response['name']
    assert new_customer['status'] == response['status']
    assert new_customer['login'] == response['login']
    assert new_customer['password'] == response['password']
    assert new_customer['email'] == response['email']
    assert new_customer['phone'] == response['phone']
    # Проверка наличия кастомера в Porta
    r = connectors.get_customer_info(response['name'])
    assert r is not False
    assert new_customer['name'] == r['customer_info']['name']
    # Проверка наличия кастомера в базе CMAPI
    r = connectors.search_record_postgres(
        'SELECT * FROM customer_mgt.customer_mgt.customer WHERE name = %(name)s',
        {'name': new_customer['name']})
    assert response['name'] == r[0][4]
示例#2
0
def test_delete_resource_to_customer():
    params = {
        "orderName": random_generator(255),
        "orderDescription": random_generator(255),
        "orderItemNumber": random_generator(128),
        "orderItemDescription": random_generator(255)
    }
    r = IVR.add_resource(data['login'], data['password'], customer_id, params)
    assert r.status_code == 201
    bearer_token = IVR.take_token(data['login'], data['password'])
    r = IVR.get_customer_numbers(bearer_token, customer_id)
    assert r.status_code == 206
    response = r.json()
    id_number = 0
    for number in response:
        if number['number'] == params["orderItemNumber"]:
            id_number = number["id"]
            break
    r = IVR.delete_customer_numbers(data['login'], data['password'],
                                    customer_id, id_number)
    assert r.status_code == 204
    r = IVR.get_customer_numbers(bearer_token, customer_id)
    response = r.json()
    for number in response:
        if number['number'] == params["orderItemNumber"]:
            assert 1 == 0
        break
    r = IVR.delete_customer_numbers(data['login'], data['password'],
                                    customer_id, id_number)
    assert r.status_code == 404
示例#3
0
def test_create_customer_with_valid_token():
    bearer_token = IVR.take_token(data['login'], data['password'])
    new_customer = {
        'name': 'testIVR_' + str(int(time.time())),
        'status': '1',
        'description': '1',
        'login': '******' + str(int(time.time())),
        'password': '******' + str(random.uniform(1, 2000000)),
        'email': str(int(time.time())) + '@gg.ru',
        'phone': '79777777777'
    }
    r = IVR.create_customer(bearer_token, new_customer)
    assert r.status_code == 201
    response = r.json()
    assert response['id']
    assert new_customer['name'] == response['name']
    assert new_customer['status'] == response['status']
    assert new_customer['description'] == response['description']
    assert new_customer['login'] == response['login']
    assert new_customer['password'] == response['password']
    assert new_customer['email'] == response['email']
    assert new_customer['phone'] == response['phone']
    # Проверка наличия кастомера в Porta
    r = connectors.get_customer_info(response['name'])
    assert r is not False
    assert new_customer['name'] == r['customer_info']['name']
示例#4
0
def test_wrong_filters():
    bearer_token = IVR.take_token(data['login'], data['password'])
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer_token
    }
    base_url = data['ivr_url'] + '/state-templates?name=limonad'
    r = requests.get(base_url, headers=headers)
    assert r.status_code == 200
    response = r.json()
    assert response is None
示例#5
0
def test_get_all_scenarios_templates():
    bearer_token = IVR.take_token(data['login'], data['password'])
    r = IVR.get_templates_scenario(bearer_token)
    assert r.status_code == 200
    response = r.json()
    found_scenarios = []
    for schema in response:
        if schema['Name'] in scenarios_types:
            found_scenarios.append(schema['Name'])
    assert scenarios_types == found_scenarios
    assert len(scenarios_types) == len(found_scenarios)
示例#6
0
def test_update_scenario_with_restricted_params():
    bearer_token = IVR.take_token(data['login'], data['password'])
    params = {
        'title': random_generator(size=129),
        'comment': 'HEH',
        'States':
        json.loads(json.JSONEncoder().encode(data['States_4_update'])),
        'CommonScript': data['CommonScript']
    }
    r = IVR.update_scenario(bearer_token, customer_a_id, customer_a_scenario,
                            params)
    assert r.status_code == 400
示例#7
0
def test_not_exist_scenario_id():
    bearer_token = IVR.take_token(data['login'], data['password'])
    params = {
        'title': random_generator(size=70),
        'comment': 'HEH',
        'States':
        json.loads(json.JSONEncoder().encode(data['States_4_update'])),
        'CommonScript': data['CommonScript']
    }
    r = IVR.update_scenario(bearer_token, customer_a_id, '1000000', params)
    assert r.status_code == 404
    response = r.json()
    assert response['message'] == 'resource not found'
示例#8
0
def test_numbers_without_filtering_number():
    bearer_token = IVR.take_token('Creep', 'Walk')
    start = 1
    end = 10
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer_token,
        'Range': 'numbers=' + str(start) + '-' + str(end)
    }
    r = IVR.get_numbers(headers=headers, params=None)
    assert r.status_code == 206
    response = r.json()
    assert len(response) > 0
示例#9
0
def test_get_scenario_with_filters():
    bearer_token = IVR.take_token(data['login'], data['password'])
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer_token
    }
    for scenario in scenarios_types:
        base_url = data['ivr_url'] + '/state-templates?name=' + scenario
        r = requests.get(base_url, headers=headers)
        assert r.status_code == 200
        response = r.json()
        assert len(response) == 1
        assert response[0]['Name'] == scenario
示例#10
0
def test_update_foreign_scenario():
    bearer_token = IVR.take_token(data['login'], data['password'])
    params = {
        'title': random_generator(size=70),
        'comment': 'HEH',
        'States':
        json.loads(json.JSONEncoder().encode(data['States_4_update'])),
        'CommonScript': data['CommonScript']
    }
    r = IVR.update_scenario(bearer_token, customer_a_id, customer_b_scenario,
                            params)
    assert r.status_code == 403
    response = r.json()
    assert response['message'] == 'access forbidden'
示例#11
0
def test_get_not_existing_customer():
    bearer_token = IVR.take_token(data['login'], data['password'])
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer_token
    }
    base_url = data['ivr_url'] + '/customers?id=9999999'
    r = requests.get(base_url, headers=headers)
    assert r.status_code == 404
    id = '999999'

    # Проверка наличия кастомера в базе CMAPI
    r = connectors.search_record_postgres(
        'SELECT * FROM customer_mgt.customer_mgt.customer WHERE id = %(id)s',
        {'id': id})
    assert r == []
示例#12
0
def test_create_customer_with_restricted_params():
    bearer_token = IVR.take_token(data['login'], data['password'])
    data_customer = [
        {
            'name': random_generator(42),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': random_generator(256),
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': random_generator(256),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': random_generator(256),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': random_generator(256, "1234567980")
        },
    ]
    for case in data_customer:
        r = IVR.create_customer(bearer_token, params=case)
        assert r.status_code == 500
示例#13
0
def test_get_numbers_with_missing_start_range():
    bearer_token = IVR.take_token('Creep', 'Walk')
    end = 15
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer_token,
        'Range': 'numbers=-' + str(end)
    }
    params = {
        'category': random.choice(data['category']),
        'owner': random.choice(data['owner']),
        'regionCode': random.choice(data['regionCode']),
        'type': random.choice(data['number_type']),
        # 'mask': random.choice(mask)
    }
    r = IVR.get_numbers(headers=headers, params=params)
    assert r.status_code == 416
示例#14
0
def test_get_numbers_with_filter():
    bearer_token = IVR.take_token('Creep', 'Walk')
    start = 1
    end = 10
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + bearer_token,
        'Range': 'numbers=' + str(start) + '-' + str(end)
    }
    i = 0
    numbers_found = False
    while i < 50:
        params = {
            'category': random.choice(data['category']),
            'owner': random.choice(data['owner']),
            'regionCode': random.choice(data['regionCode']),
            'type': random.choice(data['number_type']),
            # 'mask': random.choice(mask)
        }
        r = IVR.get_numbers(headers=headers, params=params)
        assert r.status_code == 206
        response = r.json()
        if response != []:
            assert len(response) <= (end - (start - 1))
            print(response)
            for element in response:
                assert element['owner'] == params['owner']
                assert element['category'] == params['category']
                assert element['regionCode'] == params['regionCode']
                assert element['type'] == params['type']
                assert element['state'] == 'FREE'
            numbers_found = True
            break
        else:
            print('Trying found: ' + params['category'] + ' ' +
                  params['owner'] + ' ' + params['regionCode'] + ' ' +
                  params['type'])
            i += 1
    assert numbers_found is True
示例#15
0
def test_create_customer_without_required_params():
    bearer_token = IVR.take_token(data['login'], data['password'])
    data_customer = [
        {
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '77777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '77777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '77777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '77777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'phone': '77777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru'
        },
        # пустые значения
        {
            'name': '',
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '',
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '',
            'email': str(int(time.time())) + '@gg.ru',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': '',
            'phone': '79777777777'
        },
        {
            'name': 'testIVR_' + str(int(time.time())),
            'status': '1',
            'login': '******' + str(int(time.time())),
            'password': '******' + str(random.uniform(1, 2000000)),
            'email': str(int(time.time())) + '@gg.ru',
            'phone': ''
        }
    ]
    for case in data_customer:
        r = IVR.create_customer(bearer_token, params=case)
        assert r.status_code == 400
示例#16
0
from tests import helperIVRKit as IVR
from tests.devconfig import setUpConfig

data = setUpConfig()
customer_id = data['customer_id']
bearer_token = IVR.take_token(data['login'], data['password'])


def test_get_scenarios():
    r = IVR.get_scenarios(bearer_token, customer_id)
    assert r.status_code == 206
    response = r.json()
    assert response != []


def test_get_scenarios_for_not_exist_customer():
    r = IVR.get_scenarios(bearer_token, '9999999999')
    assert r.status_code == 400


def test_get_scenarios_with_invalid_customer_input():
    r = IVR.get_scenarios(bearer_token, 'vcz')
    assert r.status_code == 400