# Path: cron/cron.py
# class Job:
#     def __init__(self, id, job=None):
#     def run(self):
#     def get_email_list(self):
#     def run_queries(self):
#     def delete_images(self):
#     def send_mail(self):
#     def failure(self, trace_string):
# def cache_buster(days_back=2):
# def drop_table(table_name):
# def scheduled_job(frequency):
# def refresh_search_index():
# 
# 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 DashboardFactory(TagsFactory):
#     class Meta:
#         model = website.models.Dashboard
# 
#     title = 'title'
#     description = ''
#     description_long = ''
#     owner = factory.SubFactory(User)
# 
# 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 DashboardQueryFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = website.models.DashboardQuery
#     query = factory.SubFactory(QueryFactory)
#     dashboard = factory.SubFactory(DashboardFactory)
# 
# class JobFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = cron.models.Job
#     owner = factory.SubFactory(UserFactory)
#     dashboard = factory.SubFactory(DashboardFactory)
#     type = 'daily'
# 
# class EmailUserFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = cron.models.EmailUser
#     job = factory.SubFactory(JobFactory)
#     user = factory.SubFactory(UserFactory)


from django.test import TransactionTestCase
from django.core import mail
from cron import cron
from ..factories import (QueryFactory, DashboardFactory, UserFactory,
                         DashboardQueryFactory, JobFactory, EmailUserFactory)
        # Send message.
        mail.send_mail(
            'Subject here', 'Here is the message.',
            'from@example.com', ['to@example.com'],
            fail_silently=False,
        )

        # Test that one message has been sent.
        self.assertEqual(len(mail.outbox), 1)

        # Verify that the subject of the first message is correct.
        self.assertEqual(mail.outbox[0].subject, 'Subject here')

    def test_cron_email(self):
        self.mock_dashboard_cron()
        job_instance = cron.Job(self.job.id)
        return_data = job_instance.run()[0][self.query.id]
        del return_data['table']
        valid_data = {'description': u'description',
                      'id': self.query.id,
                      'img': None,
                      'title': u'title'}

        self.assertEqual(return_data, valid_data)
        self.assertEqual(mail.outbox[0].subject, self.dashboard.title)

    def mock_dashboard_cron(self):
        self.user = UserFactory()
        self.query = QueryFactory(
            query_text="""

# Path: cron/cron.py
# class Job:
#     def __init__(self, id, job=None):
#     def run(self):
#     def get_email_list(self):
#     def run_queries(self):
#     def delete_images(self):
#     def send_mail(self):
#     def failure(self, trace_string):
# def cache_buster(days_back=2):
# def drop_table(table_name):
# def scheduled_job(frequency):
# def refresh_search_index():
# 
# 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 DashboardFactory(TagsFactory):
#     class Meta:
#         model = website.models.Dashboard
# 
#     title = 'title'
#     description = ''
#     description_long = ''
#     owner = factory.SubFactory(User)
# 
# 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 DashboardQueryFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = website.models.DashboardQuery
#     query = factory.SubFactory(QueryFactory)
#     dashboard = factory.SubFactory(DashboardFactory)
# 
# class JobFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = cron.models.Job
#     owner = factory.SubFactory(UserFactory)
#     dashboard = factory.SubFactory(DashboardFactory)
#     type = 'daily'
# 
# class EmailUserFactory(factory.django.DjangoModelFactory):
#     class Meta:
#         model = cron.models.EmailUser
#     job = factory.SubFactory(JobFactory)
#     user = factory.SubFactory(UserFactory)


# Path: tests/unit/test_cron.py
from django.test import TransactionTestCase
from django.core import mail
from cron import cron
from ..factories import (QueryFactory, DashboardFactory, UserFactory,
                         DashboardQueryFactory, JobFactory, EmailUserFactory)

        # Send message.
        mail.send_mail(
            'Subject here', 'Here is the message.',
            'from@example.com', ['to@example.com'],
            fail_silently=False,
        )

        # Test that one message has been sent.
        self.assertEqual(len(mail.outbox), 1)

        # Verify that the subject of the first message is correct.
        self.assertEqual(mail.outbox[0].subject, 'Subject here')

    def test_cron_email(self):
        self.mock_dashboard_cron()
        job_instance = cron.Job(self.job.id)
        return_data = job_instance.run()[0][self.query.id]
        del return_data['table']
        valid_data = {'description': u'description',
                      'id': self.query.id,
                      'img': None,
                      'title': u'title'}

        self.assertEqual(return_data, valid_data)
        self.assertEqual(mail.outbox[0].subject, self.dashboard.title)

    def mock_dashboard_cron(self):
        self.user = UserFactory()
        self.query = QueryFactory(
            query_text="""

                select