Skip to content

Commit 57821ff

Browse files
josephtylerjuanshishido
authored andcommitted
Add entity_status to Campaign and Line Items. (xdevplatform#135)
* added entity_status and campaign tests * Fixed flake8 issues. Fixes xdevplatform#134. * removed 'paused' from fixtures, added to line_items, added tests
1 parent feaac84 commit 57821ff

13 files changed

+260
-24
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def get_version(version_tuple):
1515
return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
1616
return '.'.join(map(str, version_tuple))
1717

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

tests/fixtures/campaigns_all.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"standard_delivery": true,
1717
"total_budget_amount_local_micro": null,
1818
"id": "2wap7",
19-
"paused": false,
19+
"entity_status": "ACTIVE",
2020
"account_id": "2iqph",
2121
"currency": "USD",
2222
"created_at": "2015-08-12T20:26:24Z",
@@ -36,7 +36,7 @@
3636
"standard_delivery": true,
3737
"total_budget_amount_local_micro": null,
3838
"id": "2wamv",
39-
"paused": true,
39+
"entity_status": "PAUSED",
4040
"account_id": "2iqph",
4141
"currency": "USD",
4242
"created_at": "2015-08-12T20:17:39Z",
@@ -57,7 +57,7 @@
5757
"standard_delivery": true,
5858
"total_budget_amount_local_micro": null,
5959
"id": "2wai9",
60-
"paused": true,
60+
"entity_status": "PAUSED",
6161
"account_id": "2iqph",
6262
"currency": "USD",
6363
"created_at": "2015-08-12T19:56:10Z",
@@ -77,7 +77,7 @@
7777
"standard_delivery": true,
7878
"total_budget_amount_local_micro": 1000000,
7979
"id": "2of1n",
80-
"paused": true,
80+
"entity_status": "PAUSED",
8181
"account_id": "2iqph",
8282
"currency": "USD",
8383
"created_at": "2015-06-29T22:24:17Z",
@@ -98,7 +98,7 @@
9898
"standard_delivery": true,
9999
"total_budget_amount_local_micro": null,
100100
"id": "2w9n1",
101-
"paused": true,
101+
"entity_status": "PAUSED",
102102
"account_id": "2iqph",
103103
"currency": "USD",
104104
"created_at": "2015-08-12T18:09:28Z",
@@ -118,7 +118,6 @@
118118
"standard_delivery": true,
119119
"total_budget_amount_local_micro": 1000000,
120120
"id": "2vuug",
121-
"paused": true,
122121
"account_id": "2iqph",
123122
"currency": "USD",
124123
"created_at": "2015-08-10T21:58:39Z",
@@ -136,7 +135,7 @@
136135
"standard_delivery": true,
137136
"total_budget_amount_local_micro": null,
138137
"id": "2vuj3",
139-
"paused": false,
138+
"entity_status": "ACTIVE",
140139
"account_id": "2iqph",
141140
"currency": "USD",
142141
"created_at": "2015-08-10T21:06:04Z",
@@ -154,7 +153,7 @@
154153
"standard_delivery": true,
155154
"total_budget_amount_local_micro": 10000,
156155
"id": "2v3c4",
157-
"paused": false,
156+
"entity_status": "ACTIVE",
158157
"account_id": "2iqph",
159158
"currency": "USD",
160159
"created_at": "2015-08-06T06:54:13Z",
@@ -174,7 +173,7 @@
174173
"standard_delivery": true,
175174
"total_budget_amount_local_micro": 100000000,
176175
"id": "2uubq",
177-
"paused": false,
176+
"entity_status": "ACTIVE",
178177
"account_id": "2iqph",
179178
"currency": "USD",
180179
"created_at": "2015-08-04T23:20:11Z",
@@ -194,7 +193,7 @@
194193
"standard_delivery": true,
195194
"total_budget_amount_local_micro": null,
196195
"id": "2ttv3",
197-
"paused": true,
196+
"entity_status": "PAUSED",
198197
"account_id": "2iqph",
199198
"currency": "USD",
200199
"created_at": "2015-07-29T23:05:56Z",

tests/fixtures/campaigns_load.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"standard_delivery": true,
1212
"total_budget_amount_local_micro": null,
1313
"id": "2wap7",
14-
"paused": false,
14+
"entity_status": "ACTIVE",
1515
"account_id": "2iqph",
1616
"currency": "USD",
1717
"created_at": "2015-08-12T20:26:24Z",

tests/fixtures/line_items_all.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"total_budget_amount_local_micro": null,
2323
"objective": "CUSTOM",
2424
"id": "bw2",
25-
"paused": false,
25+
"entity_status": "ACTIVE",
2626
"account_id": "2iqph",
2727
"optimization": "DEFAULT",
2828
"categories": [],
@@ -50,7 +50,7 @@
5050
"total_budget_amount_local_micro": null,
5151
"objective": "CUSTOM",
5252
"id": "c4m",
53-
"paused": false,
53+
"entity_status": "ACTIVE",
5454
"account_id": "2iqph",
5555
"optimization": "DEFAULT",
5656
"categories": [],
@@ -78,7 +78,7 @@
7878
"total_budget_amount_local_micro": null,
7979
"objective": "CUSTOM",
8080
"id": "c5c",
81-
"paused": false,
81+
"entity_status": "ACTIVE",
8282
"account_id": "2iqph",
8383
"optimization": "DEFAULT",
8484
"categories": [],
@@ -106,7 +106,7 @@
106106
"total_budget_amount_local_micro": null,
107107
"objective": "CUSTOM",
108108
"id": "fhu",
109-
"paused": false,
109+
"entity_status": "ACTIVE",
110110
"account_id": "2iqph",
111111
"optimization": "DEFAULT",
112112
"categories": [],
@@ -134,7 +134,7 @@
134134
"total_budget_amount_local_micro": null,
135135
"objective": "CUSTOM",
136136
"id": "fxd",
137-
"paused": false,
137+
"entity_status": "ACTIVE",
138138
"account_id": "2iqph",
139139
"optimization": "DEFAULT",
140140
"categories": [],
@@ -162,7 +162,7 @@
162162
"total_budget_amount_local_micro": null,
163163
"objective": "CUSTOM",
164164
"id": "fxt",
165-
"paused": false,
165+
"entity_status": "ACTIVE",
166166
"account_id": "2iqph",
167167
"optimization": "DEFAULT",
168168
"categories": [],
@@ -190,7 +190,7 @@
190190
"total_budget_amount_local_micro": null,
191191
"objective": "CUSTOM",
192192
"id": "fya",
193-
"paused": false,
193+
"entity_status": "ACTIVE",
194194
"account_id": "2iqph",
195195
"optimization": "DEFAULT",
196196
"categories": [],
@@ -218,7 +218,7 @@
218218
"total_budget_amount_local_micro": null,
219219
"objective": "CUSTOM",
220220
"id": "ghj",
221-
"paused": false,
221+
"entity_status": "ACTIVE",
222222
"account_id": "2iqph",
223223
"optimization": "DEFAULT",
224224
"categories": [],
@@ -246,7 +246,7 @@
246246
"total_budget_amount_local_micro": null,
247247
"objective": "CUSTOM",
248248
"id": "gra",
249-
"paused": false,
249+
"entity_status": "ACTIVE",
250250
"account_id": "2iqph",
251251
"optimization": "DEFAULT",
252252
"categories": [],
@@ -274,7 +274,7 @@
274274
"total_budget_amount_local_micro": null,
275275
"objective": "CUSTOM",
276276
"id": "gsw",
277-
"paused": false,
277+
"entity_status": "ACTIVE",
278278
"account_id": "2iqph",
279279
"optimization": "DEFAULT",
280280
"categories": [],

tests/fixtures/line_items_load.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"total_budget_amount_local_micro": null,
1818
"objective": "CUSTOM",
1919
"id": "bw2",
20-
"paused": false,
20+
"entity_status": "ACTIVE",
2121
"account_id": "2iqph",
2222
"optimization": "DEFAULT",
2323
"categories": [],

tests/test_campaign.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import responses
2+
import unittest
3+
4+
from tests.support import with_resource, with_fixture, characters
5+
6+
from twitter_ads.account import Account
7+
from twitter_ads.campaign import Campaign
8+
from twitter_ads.client import Client
9+
from twitter_ads.cursor import Cursor
10+
from twitter_ads import API_VERSION
11+
12+
13+
@responses.activate
14+
def test_campaigns_all():
15+
responses.add(
16+
responses.GET,
17+
with_resource('/' + API_VERSION + '/accounts/2iqph'),
18+
body=with_fixture('accounts_load'),
19+
content_type='application/json',
20+
)
21+
22+
responses.add(
23+
responses.GET,
24+
with_resource('/' + API_VERSION + '/accounts/2iqph/campaigns'),
25+
body=with_fixture('campaigns_all'),
26+
content_type='application/json',
27+
)
28+
29+
client = Client(
30+
characters(40),
31+
characters(40),
32+
characters(40),
33+
characters(40)
34+
)
35+
36+
account = Account.load(client, '2iqph')
37+
38+
cursor = account.campaigns()
39+
40+
assert cursor is not None
41+
assert isinstance(cursor, Cursor)
42+
assert cursor.count == 10
43+
44+
45+
@responses.activate
46+
def test_campaign_load():
47+
responses.add(
48+
responses.GET,
49+
with_resource('/' + API_VERSION + '/accounts/2iqph'),
50+
body=with_fixture('accounts_load'),
51+
content_type='application/json',
52+
)
53+
54+
responses.add(
55+
responses.GET,
56+
with_resource(
57+
'/' + API_VERSION + '/accounts/2iqph/campaigns/2wap7'),
58+
body=with_fixture('campaigns_load'),
59+
content_type='application/json',
60+
)
61+
62+
client = Client(
63+
characters(40),
64+
characters(40),
65+
characters(40),
66+
characters(40)
67+
)
68+
69+
account = Account.load(client, '2iqph')
70+
71+
campaign = Campaign.load(account, '2wap7')
72+
73+
assert campaign
74+
75+
76+
@responses.activate
77+
def test_campaign_entity_status_exists():
78+
responses.add(
79+
responses.GET,
80+
with_resource('/' + API_VERSION + '/accounts/2iqph'),
81+
body=with_fixture('accounts_load'),
82+
content_type='application/json',
83+
)
84+
85+
responses.add(
86+
responses.GET,
87+
with_resource(
88+
'/' + API_VERSION + '/accounts/2iqph/campaigns/2wap7'),
89+
body=with_fixture('campaigns_load'),
90+
content_type='application/json',
91+
)
92+
93+
client = Client(
94+
characters(40),
95+
characters(40),
96+
characters(40),
97+
characters(40)
98+
)
99+
100+
account = Account.load(client, '2iqph')
101+
102+
campaign = Campaign.load(account, '2wap7')
103+
104+
assert campaign.entity_status
105+
assert campaign.entity_status == 'ACTIVE'

0 commit comments

Comments
 (0)