/
snowflake-restapi
/
snowflake_connector
/
tests
/
Upload File
HOME
import json from django.contrib.auth.models import User from django.urls import reverse from rest_framework import status import pytest from snowflake_connector.models import SnowflakeAuthentication @pytest.fixture def authenticate(api_client): def do_authenticate(is_staff): return api_client.force_authenticate(User(is_staff=is_staff)) return do_authenticate @pytest.fixture def authenticate_snowflake(): def do_authenticate_snowflake(data): return SnowflakeAuthentication.objects.create(**data) return do_authenticate_snowflake @pytest.mark.django_db class TestSnowflakeAuthentication: def test_authenticate_invalid_data(self, api_client, authenticate): authenticate(is_staff=False) response = api_client.post('/snowflake/authentication/', { "account": "xktnwha-rq26191", "role": "accountadmin", "sf_user_id": 1 }) assert response.status_code == status.HTTP_400_BAD_REQUEST response = api_client.post('/snowflake/authentication/', { "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", }) assert response.status_code == status.HTTP_400_BAD_REQUEST def test_authenticate(self, api_client, authenticate): authenticate(is_staff=True) response = api_client.post('/snowflake/authentication/', { "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) assert response.status_code == status.HTTP_201_CREATED @pytest.mark.django_db class TestGetData: def test_warehouse_database(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('warehouse-database-list'), data=json.dumps(obj={"snowflake_id": snowflake.id}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_200_OK def test_warehouse_database_invalid_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "sf_user_id": 1 }) response = api_client.generic( path=reverse('warehouse-database-list'), data=json.dumps(obj={"snowflake_id": snowflake.id}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_404_NOT_FOUND def test_warehouse_database_invalid_data_2(self, api_client, authenticate): authenticate(is_staff=True) response = api_client.generic( path=reverse('warehouse-database-list'), data=json.dumps(obj={"snowflake_id": 'snowflake.id'}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_400_BAD_REQUEST def test_schema_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('schema-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_200_OK def test_schema_data_invalid_warehouse(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('schema-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "database": "SUBSCRIPTION_FLOW_DEMO"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_400_BAD_REQUEST def test_schema_data_invalid_database(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('schema-list'), data=json.dumps( obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_200_OK def test_schema_data_invalid_snowflake_auth(self, api_client, authenticate): authenticate(is_staff=True) response = api_client.generic( path=reverse('schema-list'), data=json.dumps(obj={"snowflake_id": '', "warehouse": "COMPUTE_WH"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_400_BAD_REQUEST def test_table_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('table-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_200_OK def test_table_data_invalid_schema(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('table-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC1"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_404_NOT_FOUND def test_table_data_missing_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('table-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_400_BAD_REQUEST def test_column_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('column-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC", "table": "SIGNAL_DESCRIPTION"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_200_OK def test_column_data_invalid_table(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('column-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC", "table": "SIGNAL_DESCRIPTION1"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_404_NOT_FOUND def test_column_data_missing_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.generic( path=reverse('column-list'), data=json.dumps(obj={"snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC"}), content_type="application/json", method='GET') assert response.status_code == status.HTTP_400_BAD_REQUEST @pytest.mark.django_db class TestMappingData: def test_mapping_data(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.post('/snowflake/mapping/', { "snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC", "table": "SIGNAL_DESCRIPTION", "retention_database": "SUBSCRIPTION_FLOW_DEMO", "timestamp": "EVENT_TIMESTAMP", "e": "SIGNAL", "customer": "CUSTOMER", "metadata": "DESCRIPTION", "subdomain": "snowflake.subscriptionflow.com", "client_id": "26e5d476-f06c-4f68-978b-35f45a6694ff" }) assert response.status_code == status.HTTP_201_CREATED def test_mapping_data_invalid_database_retentionflow(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.post('/snowflake/mapping/', { "snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "schema": "PUBLIC", "table": "SIGNAL_DESCRIPTION", "retention_database": "SUBSCRIPTION_FLOW_DEMO1", "timestamp": "EVENT_TIMESTAMP", "e": "SIGNAL", "customer": "CUSTOMER", "metadata": "DESCRIPTION", "subdomain": "snowflake.subscriptionflow.com", "client_id": "26e5d476-f06c-4f68-978b-35f45a6694ff" }) assert response.status_code == status.HTTP_404_NOT_FOUND def test_mapping_data_invalid_missing_schema_table(self, api_client, authenticate, authenticate_snowflake): authenticate(is_staff=True) snowflake = authenticate_snowflake({ "account": "xktnwha-rq26191", "user": "sayyam", "password": "Techloyce123", "role": "accountadmin", "sf_user_id": 1 }) response = api_client.post('/snowflake/mapping/', { "snowflake_id": snowflake.id, "warehouse": "COMPUTE_WH", "database": "SUBSCRIPTION_FLOW_DEMO", "retention_database": "SUBSCRIPTION_FLOW_DEMO1", "timestamp": "EVENT_TIMESTAMP", "e": "SIGNAL", "customer": "CUSTOMER", "metadata": "DESCRIPTION", "subdomain": "snowflake.subscriptionflow.com", "client_id": "26e5d476-f06c-4f68-978b-35f45a6694ff" }) print(response.json()) assert response.status_code == status.HTTP_400_BAD_REQUEST