# Path: tests/factories.py
# class QueryFactory(TagsFactory):
#     class Meta:
#         model = website.models.Query
# 
#     title = "title"
#     description = "description"
#     db = factory.SubFactory(DbFactory)
#     owner = factory.SubFactory(UserFactory)
#     graph_extra = "{}"
#     query_text = "select username, last_login from auth_user"
#     pivot_data = False
#     insert_limit = True
# 
# class QueryDefaultFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = website.models.QueryDefault
#     query = factory.SubFactory(QueryFactory)
#     search_for = "<DEFAULT>"
#     replace_with = ""
#     data_type = 'String'
# 
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = User
# 
#     username = factory.Sequence(lambda x: "user{}".format(x))
#     email = factory.Sequence(lambda x: "user{}@example.com".format(x))
#     password = factory.PostGenerationMethodCall('set_password', "password")
# 
# class QueryPrecedentFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = website.models.QueryPrecedent
#     final_query = factory.SubFactory(QueryFactory)
#     preceding_query = factory.SubFactory(QueryFactory)
# 
# Path: tests/functional/testcases.py
# class APITestCase(TestCaseMixin, TransactionTestCase):
# 
#     def login(self):
#         self.client.login(username=self.username, password=self.password)


import json
import datetime
import os
from ..factories import QueryFactory, QueryDefaultFactory, UserFactory, \
    QueryPrecedentFactory
from .testcases import APITestCase
                where
                    id < 0
                """,
            owner=user,
        )
        data = self.get_query(query.id)
        self.assert_query_data(
            data,
            error=True,
            data='Query contained delete -- Can not be run'
        )

    def test_valid_query(self):
        user = self.create_user()
        query = QueryFactory(
            query_text="select id, username from auth_user",
            owner=user,
        )
        self.login()
        data = self.get_query(query.id)
        self.assert_query_data(data, data={
            'columns': ['id', 'username'],
            'data': [[user.id, user.username]],
        })

    def test_time(self):
        """
        Create query that returns a time stamp
        """
        user = self.create_user()

# Path: tests/factories.py
# class QueryFactory(TagsFactory):
#     class Meta:
#         model = website.models.Query
# 
#     title = "title"
#     description = "description"
#     db = factory.SubFactory(DbFactory)
#     owner = factory.SubFactory(UserFactory)
#     graph_extra = "{}"
#     query_text = "select username, last_login from auth_user"
#     pivot_data = False
#     insert_limit = True
# 
# class QueryDefaultFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = website.models.QueryDefault
#     query = factory.SubFactory(QueryFactory)
#     search_for = "<DEFAULT>"
#     replace_with = ""
#     data_type = 'String'
# 
# class UserFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = User
# 
#     username = factory.Sequence(lambda x: "user{}".format(x))
#     email = factory.Sequence(lambda x: "user{}@example.com".format(x))
#     password = factory.PostGenerationMethodCall('set_password', "password")
# 
# class QueryPrecedentFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = website.models.QueryPrecedent
#     final_query = factory.SubFactory(QueryFactory)
#     preceding_query = factory.SubFactory(QueryFactory)
# 
# Path: tests/functional/testcases.py
# class APITestCase(TestCaseMixin, TransactionTestCase):
# 
#     def login(self):
#         self.client.login(username=self.username, password=self.password)


# Path: tests/functional/test_api.py
import json
import datetime
import os
from ..factories import QueryFactory, QueryDefaultFactory, UserFactory, \
    QueryPrecedentFactory
from .testcases import APITestCase

                where
                    id < 0
                """,
            owner=user,
        )
        data = self.get_query(query.id)
        self.assert_query_data(
            data,
            error=True,
            data='Query contained delete -- Can not be run'
        )

    def test_valid_query(self):
        user = self.create_user()
        query = QueryFactory(
            query_text="select id, username from auth_user",
            owner=user,
        )
        self.login()
        data = self.get_query(query.id)
        self.assert_query_data(data, data={
            'columns': ['id', 'username'],
            'data': [[user.id, user.username]],
        })

    def test_time(self):
        """
        Create query that returns a time stamp
        """
        user = self.create_user()

        query = QueryFactory(