def test_collection_source_rows(graphql_request, merch_collection_id): rows = graphql_request( "getCollectionSourceRows", {"collectionId": merch_collection_id, "start": 0, "count": 5}, ) assert len(rows) == 5 first_column_name = rows[0][0] assert first_column_name == "email" def test_get_collections(graphql_request): collections = graphql_request("getCollections") assert len(collections) >= 1 def test_get_collections_under_parent_collection(graphql_request, merch_collection_id): collections = graphql_request("getCollections", {"parentId": merch_collection_id}) assert all(c["parentId"] == merch_collection_id for c in collections) def test_get_collection(graphql_request, merch_collection_id): collection = graphql_request("getCollection", {"collectionId": merch_collection_id}) assert collection["id"] == merch_collection_id assert collection["status"] == "finished" def test_get_guessed_labels(graphql_request, unlabeled_collection_id): labels = graphql_request( "getGuessedLabels", {"collectionId": unlabeled_collection_id} ) first_column_file_field_name = labels[0]["fileFieldName"] assert first_column_file_field_name == "email" first_column_system_field_name = labels[0]["systemFieldName"] assert first_column_system_field_name == "userEmail" def test_count_all(graphql_request, merch_collection_id): count_values = graphql_request("countAll", {"collectionId": merch_collection_id}) assert len(count_values) > 0 def test_update_collection_name(graphql_request, merch_collection_id, random_string): random_collection_name = f"demo_merch_data_m_458-{random_string}.csv" collection = graphql_request( "updateCollectionName", {"collectionId": merch_collection_id, "newName": random_collection_name}, ) assert collection["id"] == merch_collection_id assert collection["name"] == random_collection_name # TODO mapCollection # TODO tryDeleteCollection def test_create_and_delete_collection(graphql_request, company_schema, random_string): # TODO mock boto3 s3 "generate_presigned_url" call create_response = graphql_request( "createCollection", {"fileName": f"test-collection-{random_string}.csv"} ) collection_id = create_response.get("collectionId") assert collection_id.startswith(company_schema) assert len(create_response.get("uploadUrl", "")) > 0 deleted_collection = graphql_request( "deleteCollection", { "collectionId": collection_id, # un-enriched collection has no dependencies => no deletion consequences "acceptedConsequences": [], }, ) assert deleted_collection is not None assert deleted_collection['id'] == collection_id collection = graphql_request("getCollection", {"collectionId": collection_id}) assert ( collection.get("status") == "deleting" or collection.get("error") == "Invalid collectionId" ) def test_create_and_save_segment( graphql_request, company_schema, merch_collection_id, random_string ): male_set = graphql_request( "applyFilters", { "workspaceId": company_schema, "sourceId": company_schema, "filters": [ # Data Sources {"id": 0, "values": [merch_collection_id.split("-")[1]]}, # Gender {"id": 1, "values": ["male"]}, ], }, ) set_id = male_set["id"] male_collection_name = f"demo_merch_data_m_458.csv-MALES-{random_string}" male_collection = graphql_request( "saveSegment", {"setId": set_id, "name": male_collection_name}, ) assert male_collection["name"] == male_collection_name # TODO cancel Airflow enrichment and delete segment