Skip to content

Commit 8bead90

Browse files
authored
Merge pull request #8 from ironSource/feature/instances_v3
feat(*): Feature/instances v3
2 parents 5741e9c + d419bc0 commit 8bead90

File tree

3 files changed

+60
-10
lines changed

3 files changed

+60
-10
lines changed

ironsource_api/monetize_api/monetize_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121

2222
MEDIATION_GROUP_MGMT_URL = 'https://platform.ironsrc.com/partners/publisher/mediation/management/v2'
2323

24-
INSTANCES_API_URL = 'https://platform.ironsrc.com/partners/publisher/instances/v1'
24+
INSTANCES_API_URL = 'https://platform.ironsrc.com/partners/publisher/instances/v3'
2525

2626
PLACEMENTS_URL = "https://platform.ironsrc.com/partners/publisher/placements/v1"
2727

2828

2929
class MonetizeAPI(BaseAPI):
3030
"""IronSource Monetize API"""
3131

32-
33-
34-
3532
###########
3633
# Reporting
3734
###########
@@ -338,8 +335,12 @@ async def add_instances(self, application_key: str, instances: Iterable[Instance
338335
if not instance.get_instance_ad_unit() in body['configurations'][instance.get_ad_source()]:
339336
body['configurations'][instance.get_ad_source(
340337
)][instance.get_instance_ad_unit()] = []
338+
ad_source = body['configurations'][instance.get_ad_source()]
339+
340+
if 'appConfig' in ad_source and ad_source['appConfig'] and all(v == '' for v in list(ad_source['appConfig'].values())):
341+
del ad_source['appConfig']
341342

342-
body['configurations'][instance.get_ad_source()][instance.get_instance_ad_unit()].append(
343+
ad_source[instance.get_instance_ad_unit()].append(
343344
instance.get_object())
344345

345346
options = {

tests/integration_tests/monetize_api_test.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async def test_create_new_instances(self):
145145

146146
assert res['rewardedVideo']
147147
assert (type(res['rewardedVideo']['ironSource']), len(
148-
res['rewardedVideo']['ironSource'])) == (list, 3)
148+
res['rewardedVideo']['ironSource'])) == (list, 2)
149149

150150
ironsource_instance = pydash.find(
151151
res['rewardedVideo']['ironSource'], lambda inst: inst['name'] == 'TEST')
@@ -160,6 +160,28 @@ async def test_create_new_instances(self):
160160
assert (type(res['rewardedVideo']['Vungle']), len(
161161
res['rewardedVideo']['Vungle'])) == (list, 1)
162162

163+
@pytest.mark.run(order=5)
164+
async def test_add_instances_without_appconfig(self):
165+
iron_src_api.set_credentials(API_CI_USER,
166+
API_CI_TOKEN,
167+
API_CI_SECRET)
168+
169+
assert self.__class__.TEST_APP_KEY != ''
170+
171+
vungle_instance = VungleInstance(instance_name='TEST2', ad_unit=AdUnits.RewardedVideo, app_id='',
172+
reporting_api_id='', placement_id='TEST2', status=True)
173+
174+
res = await iron_src_api.monetize_api().add_instances(self.__class__.TEST_APP_KEY,
175+
[ vungle_instance])
176+
177+
assert isinstance(res, dict)
178+
179+
assert res['rewardedVideo']
180+
assert (type(res['rewardedVideo']['Vungle']), len(
181+
res['rewardedVideo']['Vungle'])) == (list, 2)
182+
183+
184+
163185
@pytest.mark.run(order=5)
164186
async def test_update_instances(self):
165187

@@ -200,7 +222,7 @@ async def test_delete_instances(self):
200222
self.__class__.ironsource_instance_id)
201223
assert isinstance(res, dict)
202224
assert (type(res['rewardedVideo']['ironSource']), len(
203-
res['rewardedVideo']['ironSource'])) == (list, 2)
225+
res['rewardedVideo']['ironSource'])) == (list, 1)
204226

205227
@pytest.mark.run(order=8)
206228
async def test_get_mediation_group(self):

tests/unit_tests/unit_monetize_api_test.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,34 @@ async def test_unit_create_new_instances(self):
173173
"rewardedVideo": [{"instanceName": "TEST", "status": "active", "PlacementId": "TEST"}]}}}
174174
}
175175
mocked_req.assert_called_once_with(
176-
method='post', url="https://platform.ironsrc.com/partners/publisher/instances/v1", **options)
176+
method='post', url="https://platform.ironsrc.com/partners/publisher/instances/v3", **options)
177+
178+
@pytest.mark.asyncio
179+
async def test_unit_create_new_instance_without_appConfig(self):
180+
181+
mocked_req = self.get_mock_exec_req('{\"TEST\":\"TEST\"}')
182+
183+
vungle_instance = VungleInstance(instance_name='TEST_2', ad_unit=AdUnits.RewardedVideo, app_id='',
184+
reporting_api_id='', placement_id='TEST_2', status=True)
185+
186+
res = await ironsrc_api.monetize_api().add_instances(self.__class__.TEST_APP_KEY,
187+
[ vungle_instance])
188+
189+
options = {
190+
'headers': {
191+
'Authorization': 'Bearer TOKEN'
192+
},
193+
'json': {
194+
"appKey": "1234abc",
195+
"configurations":
196+
{
197+
"Vungle": {
198+
199+
"rewardedVideo": [{"instanceName": "TEST_2", "status": "active", "PlacementId": "TEST_2"}]}}}
200+
}
201+
mocked_req.assert_called_once_with(
202+
method='post', url="https://platform.ironsrc.com/partners/publisher/instances/v3", **options)
203+
177204

178205
@pytest.mark.asyncio
179206
async def test_unit_update_instances(self):
@@ -232,7 +259,7 @@ async def test_unit_update_instances(self):
232259
}
233260
}
234261
mocked_req.assert_called_once_with(
235-
method='put', url='https://platform.ironsrc.com/partners/publisher/instances/v1', **options)
262+
method='put', url='https://platform.ironsrc.com/partners/publisher/instances/v3', **options)
236263

237264
@pytest.mark.asyncio
238265
async def test_unit_delete_instances(self):
@@ -250,7 +277,7 @@ async def test_unit_delete_instances(self):
250277
}
251278
}
252279
mocked_req.assert_called_once_with(
253-
method='delete', url='https://platform.ironsrc.com/partners/publisher/instances/v1', **options)
280+
method='delete', url='https://platform.ironsrc.com/partners/publisher/instances/v3', **options)
254281

255282
@pytest.mark.asyncio
256283
async def test_unit_get_mediation_group(self):

0 commit comments

Comments
 (0)