Ejemplo n.º 1
0
def test_model_init_by_kwargs():
    x = Campaign(id=42)
    assert x.id == 42
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def test_model_init_by_dict():
    x = Campaign({"id": 42})
    assert x.id == 42
Ejemplo n.º 5
0
def test_connect():
    x = Campaign()
    credentials = {"username": "******", "password": "******"}
    x.connect(**credentials)
    assert x.client
Ejemplo n.º 6
0
def test_string_representation():
    x = Campaign(id=21)
    assert "21" in str(x)
    assert x.service_name in str(x).lower()
Ejemplo n.º 7
0
def test_setitem():
    x = Campaign(field=1)
    x.field = 42
    assert x.field == 42
    x.new_field = 23
    assert x.new_field == 23
Ejemplo n.º 8
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
Ejemplo n.º 9
0
def test_model_save_missing_id(mocker):
    mocker.patch.object(Campaign.client, 'create')
    Campaign().save()
    assert Campaign.client.create.called