Example #1
0
def test_model_find_one_uses_representation(mocker, response2):
    from appnexus.representations import raw

    mocker.patch.object(Campaign.client, 'get')
    Campaign.client.get.return_value = response2
    Campaign.client.representation = raw
    assert isinstance(Campaign.find_one(), dict)
Example #2
0
def test_model_count(mocker, response):
    mocker.patch.object(Campaign.client, 'get')
    Campaign.client.get.return_value = response
    assert Campaign.count(id=21975591) == response["count"]
Example #3
0
def test_model_find_one_returns_model_instance(mocker, response2):
    mocker.patch.object(Campaign.client, 'get')
    Campaign.client.get.return_value = response2
    assert isinstance(Campaign.find_one(), Campaign)
Example #4
0
def test_model_can_have_class_and_instance_client():
    Model.client = AppNexusClient('dumb', 'test')
    x = Campaign()
    x.client = AppNexusClient('dumbo', 'elephant')
    assert Campaign.client is not x.client
Example #5
0
def test_model_find_returns_cursor(mocker, response):
    mocker.patch.object(Campaign.client, 'get')
    Campaign.client.get.return_value = response
    assert isinstance(Campaign.find(), Cursor)
Example #6
0
def test_model_init_by_dict():
    x = Campaign({"id": 42})
    assert x.id == 42
Example #7
0
def test_model_init_by_kwargs():
    x = Campaign(id=42)
    assert x.id == 42
Example #8
0
def test_modify(mocker):
    mocker.patch.object(Campaign.client, "modify")
    Campaign.modify({"field": 42})
    assert Campaign.client.modify.called
Example #9
0
def test_changelog():
    x = Campaign(id=42)
    changelogs_cursor = x.changelog
    assert isinstance(changelogs_cursor, Cursor)
    assert changelogs_cursor.specs.get("resource_id") == x.id
    assert changelogs_cursor.specs.get("service") == x.service_name
Example #10
0
def test_connect():
    x = Campaign()
    credentials = {"username": "******", "password": "******"}
    x.connect(**credentials)
    assert x.client
Example #11
0
def test_create(mocker):
    mocker.patch.object(Campaign.client, "create")
    Campaign.create({"field": 42})
    assert Campaign.client.create.called
Example #12
0
def test_string_representation():
    x = Campaign(id=21)
    assert "21" in str(x)
    assert x.service_name in str(x).lower()
Example #13
0
def test_setitem():
    x = Campaign(field=1)
    x.field = 42
    assert x.field == 42
    x.new_field = 23
    assert x.new_field == 23
Example #14
0
def test_meta_call_client_meta(mocker):
    mocker.patch.object(Campaign.client, 'meta')
    Campaign.meta()
    assert Campaign.client.meta.called
Example #15
0
def test_model_save_with_id(mocker):
    mocker.patch.object(Campaign.client, 'modify')
    x = Campaign(id=42)
    x.attr = True
    x.save()
    assert Campaign.client.modify.called
Example #16
0
def test_model_save_missing_id(mocker):
    mocker.patch.object(Campaign.client, 'create')
    Campaign().save()
    assert Campaign.client.create.called