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)
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"]
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)
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
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)
def test_model_init_by_dict(): x = Campaign({"id": 42}) assert x.id == 42
def test_model_init_by_kwargs(): x = Campaign(id=42) assert x.id == 42
def test_modify(mocker): mocker.patch.object(Campaign.client, "modify") Campaign.modify({"field": 42}) assert Campaign.client.modify.called
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
def test_connect(): x = Campaign() credentials = {"username": "******", "password": "******"} x.connect(**credentials) assert x.client
def test_create(mocker): mocker.patch.object(Campaign.client, "create") Campaign.create({"field": 42}) assert Campaign.client.create.called
def test_string_representation(): x = Campaign(id=21) assert "21" in str(x) assert x.service_name in str(x).lower()
def test_setitem(): x = Campaign(field=1) x.field = 42 assert x.field == 42 x.new_field = 23 assert x.new_field == 23
def test_meta_call_client_meta(mocker): mocker.patch.object(Campaign.client, 'meta') Campaign.meta() assert Campaign.client.meta.called
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
def test_model_save_missing_id(mocker): mocker.patch.object(Campaign.client, 'create') Campaign().save() assert Campaign.client.create.called