Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_version(version_tuple):
return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
return '.'.join(map(str, version_tuple))


init = os.path.join(os.path.dirname(__file__), 'twitter_ads', '__init__.py')
version_line = list(filter(lambda l: l.startswith('VERSION'), open(init)))[0]

Expand Down
19 changes: 9 additions & 10 deletions tests/fixtures/campaigns_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2wap7",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-12T20:26:24Z",
Expand All @@ -36,7 +36,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2wamv",
"paused": true,
"entity_status": "PAUSED",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-12T20:17:39Z",
Expand All @@ -57,7 +57,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2wai9",
"paused": true,
"entity_status": "PAUSED",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-12T19:56:10Z",
Expand All @@ -77,7 +77,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": 1000000,
"id": "2of1n",
"paused": true,
"entity_status": "PAUSED",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-06-29T22:24:17Z",
Expand All @@ -98,7 +98,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2w9n1",
"paused": true,
"entity_status": "PAUSED",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-12T18:09:28Z",
Expand All @@ -118,7 +118,6 @@
"standard_delivery": true,
"total_budget_amount_local_micro": 1000000,
"id": "2vuug",
"paused": true,
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-10T21:58:39Z",
Expand All @@ -136,7 +135,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2vuj3",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-10T21:06:04Z",
Expand All @@ -154,7 +153,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": 10000,
"id": "2v3c4",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-06T06:54:13Z",
Expand All @@ -174,7 +173,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": 100000000,
"id": "2uubq",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-04T23:20:11Z",
Expand All @@ -194,7 +193,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2ttv3",
"paused": true,
"entity_status": "PAUSED",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-07-29T23:05:56Z",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/campaigns_load.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"standard_delivery": true,
"total_budget_amount_local_micro": null,
"id": "2wap7",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"currency": "USD",
"created_at": "2015-08-12T20:26:24Z",
Expand Down
20 changes: 10 additions & 10 deletions tests/fixtures/line_items_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "bw2",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -50,7 +50,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "c4m",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -78,7 +78,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "c5c",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -106,7 +106,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "fhu",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -134,7 +134,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "fxd",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -162,7 +162,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "fxt",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -190,7 +190,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "fya",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -218,7 +218,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "ghj",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -246,7 +246,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "gra",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down Expand Up @@ -274,7 +274,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "gsw",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/line_items_load.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"total_budget_amount_local_micro": null,
"objective": "CUSTOM",
"id": "bw2",
"paused": false,
"entity_status": "ACTIVE",
"account_id": "2iqph",
"optimization": "DEFAULT",
"categories": [],
Expand Down
105 changes: 105 additions & 0 deletions tests/test_campaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import responses
import unittest

from tests.support import with_resource, with_fixture, characters

from twitter_ads.account import Account
from twitter_ads.campaign import Campaign
from twitter_ads.client import Client
from twitter_ads.cursor import Cursor
from twitter_ads import API_VERSION


@responses.activate
def test_campaigns_all():
responses.add(
responses.GET,
with_resource('/' + API_VERSION + '/accounts/2iqph'),
body=with_fixture('accounts_load'),
content_type='application/json',
)

responses.add(
responses.GET,
with_resource('/' + API_VERSION + '/accounts/2iqph/campaigns'),
body=with_fixture('campaigns_all'),
content_type='application/json',
)

client = Client(
characters(40),
characters(40),
characters(40),
characters(40)
)

account = Account.load(client, '2iqph')

cursor = account.campaigns()

assert cursor is not None
assert isinstance(cursor, Cursor)
assert cursor.count == 10


@responses.activate
def test_campaign_load():
responses.add(
responses.GET,
with_resource('/' + API_VERSION + '/accounts/2iqph'),
body=with_fixture('accounts_load'),
content_type='application/json',
)

responses.add(
responses.GET,
with_resource(
'/' + API_VERSION + '/accounts/2iqph/campaigns/2wap7'),
body=with_fixture('campaigns_load'),
content_type='application/json',
)

client = Client(
characters(40),
characters(40),
characters(40),
characters(40)
)

account = Account.load(client, '2iqph')

campaign = Campaign.load(account, '2wap7')

assert campaign


@responses.activate
def test_campaign_entity_status_exists():
responses.add(
responses.GET,
with_resource('/' + API_VERSION + '/accounts/2iqph'),
body=with_fixture('accounts_load'),
content_type='application/json',
)

responses.add(
responses.GET,
with_resource(
'/' + API_VERSION + '/accounts/2iqph/campaigns/2wap7'),
body=with_fixture('campaigns_load'),
content_type='application/json',
)

client = Client(
characters(40),
characters(40),
characters(40),
characters(40)
)

account = Account.load(client, '2iqph')

campaign = Campaign.load(account, '2wap7')

assert campaign.entity_status
assert campaign.entity_status == 'ACTIVE'
Loading