def test_get_submitted_drafts_returns_submitted_draft_services_only( mock_data_client): mock_data_client.find_draft_services_iter.return_value = iter(({ "id": 123, "status": "submitted" }, { "id": 234, "status": "failed" }, { "id": 345, "status": "submitted" }, { "id": 456, "status": "draft" })) result = framework_helpers.get_submitted_drafts( mock_data_client, 12345, 'digital-biscuits-and-cakes') assert result == [{ "id": 123, "status": "submitted" }, { "id": 345, "status": "submitted" }]
def test_get_submitted_drafts_returns_submitted_draft_services_without_service_ids_only( mock_data_client): mock_data_client.find_draft_services_iter.return_value = iter(( { "id": 1, "status": "not-submitted" }, { "id": 2, "status": "submitted", "serviceId": "ALREADY_A_LIVE_SERVICE" }, { "id": 3, "status": "submitted" }, )) result = framework_helpers.get_submitted_drafts( mock_data_client, 12345, 'digital-biscuits-and-cakes') assert (result == [{"id": 3, "status": "submitted"}])
def get_draft_services(): if DRAFT_IDS: with open(DRAFT_IDS) as draft_ids: draft_ids = [line.strip() for line in draft_ids.read().split()] for draft_id in draft_ids: draft_service = client.get_draft_service(draft_id)['services'] supplier_framework = client.get_supplier_framework_info( draft_service['supplierId'], FRAMEWORK_SLUG) if supplier_framework['onFramework']: yield draft_service else: suppliers = find_suppliers_on_framework(client, FRAMEWORK_SLUG) for supplier in suppliers: print("Migrating drafts for supplier {}".format( supplier['supplierId'])) for draft in get_submitted_drafts(client, FRAMEWORK_SLUG, supplier['supplierId']): yield draft
service_id)) except Exception as e: if e.message == "Cannot re-publish a submitted service": print(u" > Draft {} already published".format(draft['id'])) else: print(u" > ERROR MIGRATING DRAFT {} - {}".format( draft['id'], e.message)) if __name__ == "__main__": arguments = docopt(__doc__) STAGE = arguments['<stage>'] DRY_RUN = arguments['--dry-run'] FRAMEWORK_SLUG = arguments['<framework_slug>'] api_url = get_api_endpoint_from_stage(STAGE) client = DataAPIClient(api_url, get_auth_token('api', STAGE)) print("Finding suppliers...") suppliers = find_suppliers_on_framework(client, FRAMEWORK_SLUG) print("Migrating drafts...") for supplier in suppliers: print(u"Migrating drafts for supplier {} - {}".format( supplier['supplierId'], supplier['supplierName'])) draft_services = get_submitted_drafts(client, FRAMEWORK_SLUG, supplier['supplierId']) for draft_service in draft_services: make_draft_service_live(client, draft_service, DRY_RUN)
def test_get_submitted_drafts_calls_with_correct_arguments(mock_data_client): mock_data_client.find_draft_services_iter.return_value = iter([]) framework_helpers.get_submitted_drafts(mock_data_client, 'digital-biscuits-and-cakes', 12345) mock_data_client.find_draft_services_iter.assert_called_with( 12345, framework='digital-biscuits-and-cakes')