当前位置: 首页>>代码示例>>Python>>正文


Python SavedSearchFactory.save方法代码示例

本文整理汇总了Python中mysearches.tests.factories.SavedSearchFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python SavedSearchFactory.save方法的具体用法?Python SavedSearchFactory.save怎么用?Python SavedSearchFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mysearches.tests.factories.SavedSearchFactory的用法示例。


在下文中一共展示了SavedSearchFactory.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_requeue_weekly_saved_search

# 需要导入模块: from mysearches.tests.factories import SavedSearchFactory [as 别名]
# 或者: from mysearches.tests.factories.SavedSearchFactory import save [as 别名]
    def test_requeue_weekly_saved_search(self):
        """
        Tests that weekly saved searches are requeued correctly individually in
        addition to as part of a digest.
        """
        today = datetime.date.today()
        two_days_ago = today.isoweekday() - 2
        two_month_days_ago = today.day - 2
        if two_days_ago <= 0:
            # Dates can't be negative or zero
            two_days_ago += 7
        if two_month_days_ago == 0:
            # According to mysearches/models.py, we can't have saved searches on
            # the 31st. If two_month_days_ago==0, this would be the 31st.
            two_days_ago -= 1

        digest = SavedSearchDigestFactory(user=self.user, is_active=True)
        search = SavedSearchFactory(user=self.user, is_active=True,
                                    frequency='W', day_of_week=two_days_ago)

        self.requeue(search, digest)

        digest.is_active = False
        digest.save()
        search.last_sent = None
        search.save()
        mail.outbox = []

        self.requeue(search, digest)
开发者ID:kepinq,项目名称:MyJobs,代码行数:31,代码来源:test_models.py

示例2: test_requeue_monthly_saved_search

# 需要导入模块: from mysearches.tests.factories import SavedSearchFactory [as 别名]
# 或者: from mysearches.tests.factories.SavedSearchFactory import save [as 别名]
    def test_requeue_monthly_saved_search(self):
        """
        Tests that monthly saved searches are requeued correctly individually
        in addition to as part of a digest.
        """
        today = datetime.date.today()
        two_days_ago = today.day - 2
        if two_days_ago < 0:
            two_days_ago += 31
        elif two_days_ago == 0:
            two_days_ago = 30

        digest = SavedSearchDigestFactory(user=self.user, is_active=True)
        search = SavedSearchFactory(user=self.user, is_active=True,
                                    frequency='M', day_of_month=two_days_ago)

        self.requeue(search, digest)

        digest.is_active = False
        digest.save()
        search.last_sent = None
        search.save()
        mail.outbox = []

        self.requeue(search, digest)
开发者ID:kepinq,项目名称:MyJobs,代码行数:27,代码来源:test_models.py

示例3: test_saved_search_all_jobs_link

# 需要导入模块: from mysearches.tests.factories import SavedSearchFactory [as 别名]
# 或者: from mysearches.tests.factories.SavedSearchFactory import save [as 别名]
    def test_saved_search_all_jobs_link(self):
        search = SavedSearchFactory(user=self.user)
        search.send_email()

        email = mail.outbox.pop()
        # When search.url does not start with my.jobs, use it as the all jobs
        # link
        self.assertFalse(search.url.startswith('http://my.jobs'))
        self.assertNotEqual(email.body.find(search.url), -1)

        # When search.url starts with my.jobs, strip /feed/rss from search.feed
        # if it exists and use that as the all jobs link
        search.url = 'http://my.jobs/' + '1'*32
        search.save()
        search.send_email()
        email = mail.outbox.pop()
        self.assertEqual(email.body.find(search.url),
                         -1)
        self.assertNotEqual(email.body.find(search.feed.replace('/feed/rss', '')),
                            -1)
开发者ID:zeus911,项目名称:MyJobs,代码行数:22,代码来源:test_models.py

示例4: test_requeue_monthly_saved_search

# 需要导入模块: from mysearches.tests.factories import SavedSearchFactory [as 别名]
# 或者: from mysearches.tests.factories.SavedSearchFactory import save [as 别名]
    def test_requeue_monthly_saved_search(self):
        """
        Tests that monthly saved searches are requeued correctly individually
        in addition to as part of a digest.
        """
        today = datetime.date.today().day
        last_week = today - 7
        if last_week <= 0:
            last_week += 31
        digest = SavedSearchDigestFactory(user=self.user,
                                          is_active=True)
        search = SavedSearchFactory(user=self.user, is_active=True,
                                    frequency='M', day_of_month=last_week)

        self.requeue(search, digest)

        digest.is_active = False
        digest.save()
        search.last_sent = None
        search.save()
        mail.outbox = []

        self.requeue(search, digest)
开发者ID:wejhink,项目名称:MyJobs,代码行数:25,代码来源:test_models.py

示例5: SavedSearchSendingTests

# 需要导入模块: from mysearches.tests.factories import SavedSearchFactory [as 别名]
# 或者: from mysearches.tests.factories.SavedSearchFactory import save [as 别名]
class SavedSearchSendingTests(MyJobsBase):
    def setUp(self):
        super(SavedSearchSendingTests, self).setUp()
        self.feed = 'http://rushenterprises-veterans.jobs/alabama/usa/jobs/feed/rss'
        self.user = UserFactory()
        self.saved_search = SavedSearchFactory(user=self.user, feed=self.feed,
                                               frequency='D')
        self.company = CompanyFactory()
        self.partner = PartnerFactory(owner=self.company)
        self.contact = ContactFactory(user=self.user,
                                      partner=self.partner)
        self.partner_search = PartnerSavedSearchFactory(user=self.user,
                                                        feed=self.feed,
                                                        frequency='D',
                                                        created_by=self.user,
                                                        provider=self.company,
                                                        partner=self.partner)
        mail.outbox = []

    @patch('urllib2.urlopen')
    def test_all_jobs_new(self, urlopen_mock):
        mock_obj = Mock()
        mock_obj.read.side_effect = [jobs, jobs, jobs]
        urlopen_mock.return_value = mock_obj

        three_days_ago = datetime.datetime.now() - datetime.timedelta(days=365)
        self.partner_search.last_sent = three_days_ago
        self.saved_search.last_sent = three_days_ago
        self.partner_search.save()
        self.saved_search.save()

        # All of the jobs were sent within the past year, so if we set
        # last_sent to one year ago all of the jobs should be old.
        self.saved_search.send_email()
        email = mail.outbox.pop()
        self.assertIn('Showing the top 3 jobs', email.body)

        self.partner_search.send_email()
        email = mail.outbox.pop()
        self.assertIn('Showing the top 3 jobs', email.body)

    @patch('urllib2.urlopen')
    def test_some_jobs_new(self, urlopen_mock):
        mock_obj = Mock()
        mock_obj.read.side_effect = [jobs, jobs, jobs]
        urlopen_mock.return_value = mock_obj

        three_days_ago = datetime.datetime.now() - datetime.timedelta(days=3)
        self.partner_search.last_sent = three_days_ago
        self.saved_search.last_sent = three_days_ago
        self.partner_search.save()
        self.saved_search.save()

        # One job was sent within the past 3 days, so if we set last_sent to
        # three days ago one of the jobs should be old.
        self.saved_search.send_email()
        email = mail.outbox.pop()
        self.assertIn('Showing the top job', email.body)

        self.partner_search.send_email()
        email = mail.outbox.pop()
        self.assertIn('Showing the top 3 jobs', email.body)

    @patch('urllib2.urlopen')
    def test_no_jobs_new(self, urlopen_mock):
        mock_obj = Mock()
        mock_obj.read.side_effect = [jobs, jobs, jobs]
        urlopen_mock.return_value = mock_obj

        self.partner_search.last_sent = datetime.datetime.now()
        self.saved_search.last_sent = datetime.datetime.now()
        self.partner_search.save()
        self.saved_search.save()

        # All jobs were sent over 2 days ago, so if we set last_sent to
        # today none of the jobs should be old.
        self.saved_search.send_email()
        self.assertEqual(len(mail.outbox), 0)

        self.partner_search.send_email()
        email = mail.outbox.pop()
        self.assertIn('Showing the top 3 jobs', email.body)

    @patch('urllib2.urlopen')
    def test_partner_saved_search_backfill(self, urlopen_mock):
        mock_obj = Mock()
        mock_obj.read.side_effect = [jobs, jobs, jobs, jobs, jobs, jobs]
        urlopen_mock.return_value = mock_obj

        # Make it so there should be no new jobs.
        self.partner_search.last_sent = datetime.datetime.now()
        self.partner_search.save()

        # jobs_per_email is default, so all 3 should get sent.
        self.partner_search.send_email()
        email = mail.outbox.pop()
        self.assertIn('Showing the top 3 jobs', email.body)

        self.partner_search.jobs_per_email = 2
        self.partner_search.save()
#.........这里部分代码省略.........
开发者ID:zeus911,项目名称:MyJobs,代码行数:103,代码来源:test_models.py

示例6: CronEventTests

# 需要导入模块: from mysearches.tests.factories import SavedSearchFactory [as 别名]
# 或者: from mysearches.tests.factories.SavedSearchFactory import save [as 别名]
class CronEventTests(MyJobsBase):
    def setUp(self):
        super(CronEventTests, self).setUp()
        # I'm using SavedSearch for these tests, but you can use any
        # model with a DateTimeField for the "*_with_field" option, and
        # any object for the "*_no_field" option.
        # It might actually be worth using additional object types
        # in future tests.
        yesterday = datetime.now() - timedelta(1)
        self.saved_search = SavedSearchFactory(last_sent=yesterday)

        model = self.saved_search._meta.model
        self.saved_search_contenttype = ContentType.objects.get_for_model(model)
        cron_kwargs = {'model': self.saved_search_contenttype}
        self.cron_event_no_field = factories.CronEventFactory(**cron_kwargs)
        cron_kwargs['field'] = 'last_sent'
        self.cron_event_with_field = factories.CronEventFactory(**cron_kwargs)

    def test_cron_event_schedule_task_no_field(self):
        today = datetime.now().date()
        task = self.cron_event_no_field.schedule_task(self.saved_search)

        self.assertEqual(task.object_id, self.saved_search.id)
        self.assertEqual(task.object_model, self.saved_search_contenttype)
        self.assertEqual(task.related_event, self.cron_event_no_field)
        self.assertEqual(task.scheduled_for.date(), today)
        self.assertEqual(task.scheduled_at.date(), today)
        self.assertIsNone(task.completed_on)

    def test_cron_event_schedule_task_with_field(self):
        yesterday = (datetime.now() - timedelta(1)).date()
        today = datetime.now().date()
        task = self.cron_event_with_field.schedule_task(self.saved_search)

        self.assertEqual(task.object_id, self.saved_search.id)
        self.assertEqual(task.object_model, self.saved_search_contenttype)
        self.assertEqual(task.related_event, self.cron_event_with_field)
        self.assertEqual(task.scheduled_for.date(), yesterday)
        self.assertEqual(task.scheduled_at.date(), today)
        self.assertIsNone(task.completed_on)

    def test_scheduled_for_with_field(self):
        """
        CronEvents that have an associated field should schedule from the
        time contained within the associated field.
        
        """
        tomorrow = datetime.now() + timedelta(1)
        self.saved_search.last_sent = tomorrow
        self.saved_search.save()

        self.cron_event_with_field.minutes = 60*25
        self.cron_event_with_field.save()
        should_be_scheduled_for = (tomorrow + timedelta(1)).date()

        task = self.cron_event_with_field.schedule_task(self.saved_search)
        self.assertEqual(task.scheduled_for.date(), should_be_scheduled_for)

    def test_scheduled_for_no_field(self):
        """
        CronEvents that don't have an associated field should instead be
        scheduled based on the current time.

        """
        self.cron_event_no_field.minutes = 60
        self.cron_event_no_field.save()
        should_be_scheduled_for = datetime.now() + timedelta(minutes=60)
        should_be_scheduled_for = should_be_scheduled_for.date()

        task = self.cron_event_no_field.schedule_task(self.saved_search)
        self.assertEqual(task.scheduled_for.date(), should_be_scheduled_for)
开发者ID:abdulfiroz007,项目名称:MyJobs,代码行数:73,代码来源:test_models.py


注:本文中的mysearches.tests.factories.SavedSearchFactory.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。