|
| 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.client import Client |
| 8 | +from twitter_ads.targeting import AudienceSummary |
| 9 | +from twitter_ads import API_VERSION |
| 10 | + |
| 11 | + |
| 12 | +@responses.activate |
| 13 | +def test_audience_summary(): |
| 14 | + responses.add(responses.GET, |
| 15 | + with_resource('/' + API_VERSION + '/accounts/2iqph'), |
| 16 | + body=with_fixture('accounts_load'), |
| 17 | + content_type='application/json') |
| 18 | + |
| 19 | + responses.add(responses.POST, |
| 20 | + with_resource('/' + API_VERSION + '/accounts/2iqph/audience_summary'), |
| 21 | + body=with_fixture('audience_summary'), |
| 22 | + content_type='application/json') |
| 23 | + |
| 24 | + client = Client( |
| 25 | + characters(40), |
| 26 | + characters(40), |
| 27 | + characters(40), |
| 28 | + characters(40) |
| 29 | + ) |
| 30 | + |
| 31 | + account = Account.load(client, '2iqph') |
| 32 | + |
| 33 | + params = { |
| 34 | + "targeting_criteria": [ |
| 35 | + { |
| 36 | + "targeting_type":"LOCATION", |
| 37 | + "targeting_value":"96683cc9126741d1" |
| 38 | + }, |
| 39 | + { |
| 40 | + "targeting_type":"BROAD_KEYWORD", |
| 41 | + "targeting_value":"cats" |
| 42 | + }, |
| 43 | + { |
| 44 | + "targeting_type":"SIMILAR_TO_FOLLOWERS_OF_USER", |
| 45 | + "targeting_value": "14230524" |
| 46 | + }, |
| 47 | + { |
| 48 | + "targeting_type":"SIMILAR_TO_FOLLOWERS_OF_USER", |
| 49 | + "targeting_value": "90420314" |
| 50 | + } |
| 51 | + ] |
| 52 | + } |
| 53 | + |
| 54 | + audience_summary = AudienceSummary.load( |
| 55 | + account=account, |
| 56 | + params=params |
| 57 | + ) |
| 58 | + |
| 59 | + print (audience_summary) |
| 60 | + assert audience_summary is not None |
| 61 | + assert audience_summary.audience_size is not None |
| 62 | + assert audience_summary.audience_size['min'] == 41133600 |
| 63 | + assert audience_summary.audience_size['max'] == 50274400 |
0 commit comments