Esempio n. 1
0
def test_update_customer_properties(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_tracking.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    response = exponea.tracking.update_customer_properties(
        {'registered': 'foo'}, {'foo': 'bar'})
    assert response is True
Esempio n. 2
0
def test_get_customer_consents(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_customer_consents.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    consents = exponea.customer.get_customer_consents({"registered": "test"},
                                                      ["newsletter"])
    assert consents["newsletter"] == False
Esempio n. 3
0
def test_add_event(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_tracking.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    response = exponea.tracking.add_event({'registered': 'foo'},
                                          {'foo': 'bar'})
    assert response is True
Esempio n. 4
0
def test_get_customer_consents(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_customer_consents.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    consents = exponea.customer.get_customer_consents({'registered': 'test'},
                                                      ['newsletter'])
    assert consents['newsletter'] is False
Esempio n. 5
0
def test_access_key_not_found_exception(mocker, mock_request):
    exponea = Exponea('test')
    response = {'error': 'access key not found', 'success': False}
    mocker.patch('requests.request', mock_request(response))
    with pytest.raises(APIException) as exception:
        exponea.analyses.get_report('test')
    assert 'access key not found' in str(exception.value)
Esempio n. 6
0
def test_no_permission_to_retrieve_attribute(mocker, mock_request):
    exponea = Exponea('test')
    response = {
        'results': [{
            'value': 'Lukas',
            'success': True
        }, {
            'error': 'No permission',
            'success': False
        }, {
            'value': 'not bought',
            'success': True
        }],
        'success':
        True
    }
    mocker.patch('requests.request', mock_request(response))
    attributes = exponea.customer.get_customer_attributes(
        {'registered': 'test'},
        ids=['test'],
        properties=['name'],
        expressions=['test'])
    assert attributes['ids']['test'] is None
    assert attributes['properties']['name'] == 'Lukas'
    assert attributes['expressions']['test'] == 'not bought'
def test_create_catalog(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_create_catalog.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    catalog_id = exponea.catalog.create_catalog("test",
                                                ["field_one", "field_two"])
    assert catalog_id == "5bfawefds3a0015e7f0b5"
Esempio n. 8
0
def test_create_catalog(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_create_catalog.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    catalog_id = exponea.catalog.create_catalog('test',
                                                ['field_one', 'field_two'])
    assert catalog_id == '5bfawefds3a0015e7f0b5'
def test_access_key_not_found_exception(mocker, mock_request):
    exponea = Exponea("test")
    response = {
        "error": "access key not found",
        "success": False
    }
    mocker.patch("requests.request", mock_request(response))
    with pytest.raises(APIException) as exception:
        exponea.analyses.get_report("test")
    assert "access key not found" in str(exception.value)
def test_errors_global_exception(mocker, mock_request):
    exponea = Exponea("test")
    response = {
        "errors": {"_global": ["Customer does not exist"]}, 
        "success": False
    }
    mocker.patch("requests.request", mock_request(response))
    with pytest.raises(APIException) as exception:
        exponea.customer.get_customer({"registered": "test"})
    assert "Customer does not exist" in str(exception.value)
def test_not_authorized_exception(mocker, mock_request):
    exponea = Exponea("test")
    response = {
        "errors": ["not authorized to update specified customer properties"],
        "success": False
    }
    mocker.patch("requests.request", mock_request(response))
    with pytest.raises(APIException) as exception:
        exponea.analyses.get_report("test")
    assert "not authorized to update specified customer properties" in str(exception.value)
def test_no_permission_to_retrieve_attribute(mocker, mock_request):
    exponea = Exponea("test")
    response = {
        'results': [{'value': 'Lukas', 'success': True}, {'error': 'No permission', 'success': False}, {'value': 'not bought', 'success': True}],
        'success': True
    }
    mocker.patch("requests.request", mock_request(response))
    attributes = exponea.customer.get_customer_attributes({"registered": "test"}, ids=["test"], properties=["name"], expressions=["test"])
    assert attributes["ids"]["test"] == None
    assert attributes["properties"]["name"] == "Lukas"
    assert attributes["expressions"]["test"] == "not bought"
Esempio n. 13
0
def test_not_authorized_exception(mocker, mock_request):
    exponea = Exponea('test')
    response = {
        'errors': ['not authorized to update specified customer properties'],
        'success': False
    }
    mocker.patch('requests.request', mock_request(response))
    with pytest.raises(APIException) as exception:
        exponea.analyses.get_report('test')
    assert 'not authorized to update specified customer properties' in str(
        exception.value)
Esempio n. 14
0
def test_get_events(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_events.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    events = exponea.customer.get_events({"registered": "test"}, ["test"])
    assert events[0] == {
        "properties": {
            "test": "foo"
        },
        "timestamp": 1533495529.9268496,
        "type": "test"
    }
def test_batch_commands(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_batch_command.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    response = exponea.tracking.batch_commands([
        exponea.tracking.add_event({ "registered": "test" }, "test", batch=True),
        exponea.tracking.update_customer_properties({ "registered": "test" }, { "first_name": "test" }, batch=True),
        exponea.tracking.get_system_time(batch=True)
    ])
    assert response[0] == True
    assert response[1] == True
    assert response[2] == 1533833360.2316685
Esempio n. 16
0
def test_errors_global_exception(mocker, mock_request):
    exponea = Exponea('test')
    response = {
        'errors': {
            '_global': ['Customer does not exist']
        },
        'success': False
    }
    mocker.patch('requests.request', mock_request(response))
    with pytest.raises(APIException) as exception:
        exponea.customer.get_customer({'registered': 'test'})
    assert 'Customer does not exist' in str(exception.value)
Esempio n. 17
0
def test_get_events(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_events.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    events = exponea.customer.get_events({'registered': 'test'}, ['test'])
    assert events[0] == {
        'properties': {
            'test': 'foo'
        },
        'timestamp': 1533495529.9268496,
        'type': 'test'
    }
Esempio n. 18
0
def test_get_customer_attributes(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_customer_attributes.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    customer = exponea.customer.get_customer_attributes({"registered": "test"},
                                                        ids=["id"],
                                                        segmentations=["segm"],
                                                        aggregations=["aggr"],
                                                        properties=["prop"])
    assert customer["properties"]["prop"] == "Lukas"
    assert customer["ids"]["id"] == ["123"]
    assert customer["aggregations"]["aggr"] == 0
    assert customer["segmentations"]["segm"] == "not_bought"
Esempio n. 19
0
def test_get_customer_attributes(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_customer_attributes.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    customer = exponea.customer.get_customer_attributes({'registered': 'test'},
                                                        ids=['id'],
                                                        segmentations=['segm'],
                                                        aggregations=['aggr'],
                                                        properties=['prop'])
    assert customer['properties']['prop'] == 'Lukas'
    assert customer['ids']['id'] == ['123']
    assert customer['aggregations']['aggr'] == 0
    assert customer['segmentations']['segm'] == 'not_bought'
Esempio n. 20
0
def test_get_customer(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_customer.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    customer = exponea.customer.get_customer({'registered': 'test'})
    assert customer['properties']['first_name'] == 'Lukas'
    assert customer['ids']['registered'] == 'test'
    assert customer['events'][0] == {
        'properties': {
            'foo': 'bar'
        },
        'timestamp': 1533495544.343536,
        'type': 'test'
    }
Esempio n. 21
0
def test_get_report(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_report.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    report = exponea.analyses.get_report("test")
    assert report["name"] == "test_report"
    assert report["data"][0] == {
        "cookie id": "test1",
        "count(customer)": 1
    }
    assert report["data"][1] == {
        "cookie id": "test2",
        "count(customer)": 2
    }
Esempio n. 22
0
def test_get_customer(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_customer.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    customer = exponea.customer.get_customer({"registered": "test"})
    assert customer["properties"]["first_name"] == "Lukas"
    assert customer["ids"]["registered"] == "test"
    assert customer["events"][0] == {
        "properties": {
            "foo": "bar"
        },
        "timestamp": 1533495544.343536,
        "type": "test"
    }
Esempio n. 23
0
def test_get_segmentation(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_segmentation.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    segmentation = exponea.analyses.get_segmentation('test')
    assert segmentation['name'] == 'test_segmentation'
    assert segmentation['data'][0] == {
        'segment': 'already_bought',
        '#': 0
    }
    assert segmentation['data'][1] == {
        'segment': 'not_bought',
        '#': 4
    }
Esempio n. 24
0
def test_get_report(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_report.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    report = exponea.analyses.get_report('test')
    assert report['name'] == 'test_report'
    assert report['data'][0] == {
        'cookie id': 'test1',
        'count(customer)': 1
    }
    assert report['data'][1] == {
        'cookie id': 'test2',
        'count(customer)': 2
    }
Esempio n. 25
0
def test_batch_commands(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_batch_command.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    response = exponea.tracking.batch_commands([
        exponea.tracking.add_event({'registered': 'test'}, 'test', batch=True),
        exponea.tracking.update_customer_properties({'registered': 'test'},
                                                    {'first_name': 'test'},
                                                    batch=True),
        exponea.tracking.get_system_time(batch=True)
    ])
    assert response[0] is True
    assert response[1] is True
    assert response[2] == 1533833360.2316685
Esempio n. 26
0
def test_get_customers(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_customers.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    customers = exponea.customer.get_customers()
    assert customers[0] == {
        'ids': {
            'registered': 'test',
            'cookie': ['cookie']
        },
        'properties': {
            'first_name': 'Lukas',
            'last_name': 'Cerny'
        }
    }
Esempio n. 27
0
def test_get_customers(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_customers.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    customers = exponea.customer.get_customers()
    assert customers[0] == {
        "ids": {
            "registered": "test",
            "cookie": ["cookie"]
        },
        "properties": {
            "first_name": "Lukas",
            "last_name": "Cerny"
        }
    }
Esempio n. 28
0
def test_get_segmentation(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_segmentation.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    segmentation = exponea.analyses.get_segmentation("test")
    assert segmentation["name"] == "test_segmentation"
    assert segmentation["data"][0] == {
        "segment": "already_bought",
        "#": 0
    }
    assert segmentation["data"][1] == {
        "segment": "not_bought",
        "#": 4
    }
            
def test_get_catalog_items(mocker, load_data, mock_request):
    exponea = Exponea("test")
    mock_exponea_response = load_data("test_catalog_items.json")
    mocker.patch("requests.request", mock_request(mock_exponea_response))
    catalog = exponea.catalog.get_catalog_items("catalog_id")
    assert catalog["matched"] == 1
    assert catalog["matched_limited"] == False
    assert catalog["total"] == 1
    assert catalog["limit"] == 20
    assert catalog["skip"] == 0
    assert catalog["data"][0] == {
        "item_id": "1",
        "properties": {
            "one": "foo",
            "two": "bar"
        }
    }
Esempio n. 30
0
def test_get_catalog_items(mocker, load_data, mock_request):
    exponea = Exponea('test')
    mock_exponea_response = load_data('test_catalog_items.json')
    mocker.patch('requests.request', mock_request(mock_exponea_response))
    catalog = exponea.catalog.get_catalog_items('catalog_id')
    assert catalog['matched'] == 1
    assert catalog['matched_limited'] is False
    assert catalog['total'] == 1
    assert catalog['limit'] == 20
    assert catalog['skip'] == 0
    assert catalog['data'][0] == {
        'item_id': '1',
        'properties': {
            'one': 'foo',
            'two': 'bar'
        }
    }