Skip to content
Open
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
31 changes: 31 additions & 0 deletions tests/test_apple_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,36 @@ def test_invalid_purposes_report_options_without_running_iris(self):
run.assert_not_called()


class SetAvailabilityTests(unittest.TestCase):
def call_with_plan(self, territories, available_in_new):
response = {"available": ["BRA", "USA"]}
with patch.object(apple_console, "_run_iris", return_value=response) as run:
result = apple_console.set_availability("test-app", territories, available_in_new)
run.assert_called_once()
app_id, body = run.call_args.args
self.assertEqual(app_id, "test-app")
self.assertIs(result, response)
match = re.search(r"const want=(.*);", body)
self.assertIsNotNone(match)
self.assertIn("id:'test-app'", body)
self.assertIn("/iris/v2/appAvailabilities/test-app/territoryAvailabilities?", body)
return json.loads(match.group(1)), body

def test_normalizes_deduplicates_and_sorts_territories(self):
wanted, _ = self.call_with_plan(["usa", "BRA", "bra"], False)
self.assertEqual(wanted, ["BRA", "USA"])

def test_serializes_both_new_territory_options(self):
for available_in_new, expected in [(True, "true"), (False, "false")]:
with self.subTest(available_in_new=available_in_new):
_, body = self.call_with_plan(["USA"], available_in_new)
self.assertIn(f"availableInNewTerritories:{expected}", body)
self.assertNotIn(f"availableInNewTerritories:{available_in_new}", body)

def test_empty_territories_are_preserved(self):
wanted, _ = self.call_with_plan([], False)
self.assertEqual(wanted, [])


if __name__ == "__main__":
unittest.main()
Loading