Пример #1
0
 def test_bogus_icalendar_data_does_not_crash_harvesting(self):
     log_mock = self.patch('ode.harvesting.log')
     source1 = self.make_source(url=u"http://example.com/a",
                                provider_id='123')
     self.make_source(url=u"http://example.com/b", provider_id='456')
     self.setup_requests_mock()
     self.mock_requests.get.side_effect = [
         Mock(
             status_code=200,
             content_type='text/calendar',
             text='*** BOGUS DATA ***',
         ),
         Mock(
             status_code=200,
             content_type='text/calendar',
             text=valid_icalendar,
         ),
     ]
     harvest()
     self.assertEqual(DBSession.query(Event).count(), 1)
     expected_messasge = "Invalid iCalendar request body: "
     actual_message = log_mock.warning.call_args[0][0]
     self.assertTrue(actual_message.startswith(expected_messasge))
     log_mock.warning.assert_any_call(
         u"Failed to harvest source {} with URL {}".format(
             source1.id, source1.url),
         exc_info=True)
Пример #2
0
 def test_bogus_icalendar_data_does_not_crash_harvesting(self):
     log_mock = self.patch('ode.harvesting.log')
     source1 = self.make_source(url=u"http://example.com/a",
                                provider_id='123')
     self.make_source(url=u"http://example.com/b", provider_id='456')
     self.setup_requests_mock()
     self.mock_requests.get.side_effect = [
         Mock(
             status_code=200,
             content_type='text/calendar',
             text='*** BOGUS DATA ***',
         ),
         Mock(
             status_code=200,
             content_type='text/calendar',
             text=valid_icalendar,
         ),
     ]
     harvest()
     self.assertEqual(DBSession.query(Event).count(), 1)
     expected_messasge = "Invalid iCalendar request body: "
     actual_message = log_mock.warning.call_args[0][0]
     self.assertTrue(actual_message.startswith(expected_messasge))
     log_mock.warning.assert_any_call(
         u"Failed to harvest source {} with URL {}".format(
             source1.id, source1.url),
         exc_info=True)
Пример #3
0
 def test_bogus_json_data(self):
     log_mock = self.patch('ode.harvesting.log')
     self.make_source(url=u"http://example.com/a", provider_id='123')
     self.setup_requests_mock(content_type='text/json',
                              body_text=u'{"foo": 42}')
     harvest()
     self.assertEqual(DBSession.query(Event).count(), 0)
     log_mock.warning.assert_any_call(u"Invalid Collection+JSON input")
Пример #4
0
 def test_bogus_json_data(self):
     log_mock = self.patch('ode.harvesting.log')
     self.make_source(url=u"http://example.com/a", provider_id='123')
     self.setup_requests_mock(content_type='text/json',
                              body_text=u'{"foo": 42}')
     harvest()
     self.assertEqual(DBSession.query(Event).count(), 0)
     log_mock.warning.assert_any_call(u"Invalid Collection+JSON input")
Пример #5
0
 def test_update_from_uid_with_domain_part(self):
     self.create_event(title=u'Existing event', id=u'*****@*****.**')
     DBSession.flush()
     self.setup_requests_mock(body_text=valid_icalendar)
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     event = DBSession.query(Event).one()
     self.assertEqual(event.title, u"Capitole du Libre")
Пример #6
0
 def test_update_from_uid_with_domain_part(self):
     self.create_event(title=u'Existing event', id=u'*****@*****.**')
     DBSession.flush()
     self.setup_requests_mock(body_text=valid_icalendar)
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     event = DBSession.query(Event).one()
     self.assertEqual(event.title, u"Capitole du Libre")
Пример #7
0
 def test_fetch_json_data_from_source(self):
     self.setup_requests_mock(content_type='text/json',
                              body_text=valid_json)
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     event = DBSession.query(Event).one()
     self.assertEqual(event.title, u"Test medias")
     self.assertEqual(event.description, u"Description")
Пример #8
0
 def test_fetch_json_data_from_source(self):
     self.setup_requests_mock(content_type='text/json',
                              body_text=valid_json)
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     event = DBSession.query(Event).one()
     self.assertEqual(event.title, u"Test medias")
     self.assertEqual(event.description,
                      u"Description")
Пример #9
0
 def test_fetch_data_from_source(self):
     self.setup_requests_mock()
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     event = DBSession.query(Event).one()
     self.assertEqual(event.title, u"Capitole du Libre")
     self.assertEqual(event.url,
                      u"http://www.agendadulibre.org/showevent.php?id=7064")
     self.assertEqual(event.description,
                      u"Un évènement de l'Agenda du Libre")
Пример #10
0
 def test_fetch_data_from_source(self):
     self.setup_requests_mock()
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     event = DBSession.query(Event).one()
     self.assertEqual(event.title, u"Capitole du Libre")
     self.assertEqual(
         event.url, u"http://www.agendadulibre.org/showevent.php?id=7064")
     self.assertEqual(event.description,
                      u"Un évènement de l'Agenda du Libre")
Пример #11
0
def main():
    description = """\
    Harvest event from sources.
    Example: 'harvest deployment.ini'
    """
    usage = "usage: %prog config_uri"
    parser = optparse.OptionParser(usage=usage,
                                   description=textwrap.dedent(description))

    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 1:
        print('You must provide one argument')
        return 2
    config_uri = args[0]
    pyramid.paster.setup_logging(config_uri)
    env = bootstrap(config_uri)
    settings, closer = env['registry'].settings, env['closer']
    try:
        with transaction.manager:
            harvest()
    finally:
        closer()
Пример #12
0
def main():
    description = """\
    Harvest event from sources.
    Example: 'harvest deployment.ini'
    """
    usage = "usage: %prog config_uri"
    parser = optparse.OptionParser(
        usage=usage,
        description=textwrap.dedent(description)
        )

    options, args = parser.parse_args(sys.argv[1:])
    if not len(args) >= 1:
        print('You must provide one argument')
        return 2
    config_uri = args[0]
    pyramid.paster.setup_logging(config_uri)
    env = bootstrap(config_uri)
    closer = env['closer']
    try:
        with transaction.manager:
            harvest()
    finally:
        closer()
Пример #13
0
 def test_fix_calendar_with_timezone_aware_datetimes(self):
     self.setup_requests_mock(body_text=icalendar_with_timezone)
     self.make_source()
     harvest()
     harvest()  # Second call was crashing
Пример #14
0
 def test_invalid_calendar(self):
     self.setup_requests_mock(body_text=start_time_missing)
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     self.assertEqual(DBSession.query(Event).count(), 0)
Пример #15
0
 def test_fix_calendar_with_timezone_aware_datetimes(self):
     self.setup_requests_mock(body_text=icalendar_with_timezone)
     self.make_source()
     harvest()
     harvest()  # Second call was crashing
Пример #16
0
 def test_invalid_calendar(self):
     self.setup_requests_mock(body_text=start_time_missing)
     source = self.make_source()
     harvest()
     self.mock_requests.get.assert_called_with(source.url)
     self.assertEqual(DBSession.query(Event).count(), 0)