Пример #1
0
 def test_last_changed_datetime(self):
     resource = fac.ResourceFactory.create(
         url=u"http://test",
         document="""
             <iati-activities>
               <iati-activity>
                 <iati-identifier>test_deleted_activity</iati-identifier>
                 <title>test_deleted_activity</title>
                 <reporting-org ref="GB-CHC-202918" type="21">Oxfam GB</reporting-org>
               </iati-activity>
               <iati-activity>
                 <iati-identifier>test_deleted_activity_2</iati-identifier>
                 <title>test_deleted_activity_2</title>
                 <reporting-org ref="GB-CHC-202918" type="21">Oxfam GB</reporting-org>
               </iati-activity>
             </iati-activities>
         """
     )
     crawler.parse_resource(resource)
     db.session.commit()
     db.session.query(Activity).update(
         values={'last_change_datetime': datetime.datetime(2000, 1, 1)},
         synchronize_session=False)
     db.session.commit()
     crawler.parse_resource(resource)
     acts = db.session.query(Activity).all()
     self.assertEquals(datetime.datetime(2000, 1, 1),
         acts[0].last_change_datetime)
Пример #2
0
 def test_last_changed_datetime(self):
     resource = fac.ResourceFactory.create(url=u"http://test",
                                           document="""
             <iati-activities>
               <iati-activity>
                 <iati-identifier>test_deleted_activity</iati-identifier>
                 <title>test_deleted_activity</title>
                 <reporting-org ref="GB-CHC-202918" type="21">Oxfam GB</reporting-org>
               </iati-activity>
               <iati-activity>
                 <iati-identifier>test_deleted_activity_2</iati-identifier>
                 <title>test_deleted_activity_2</title>
                 <reporting-org ref="GB-CHC-202918" type="21">Oxfam GB</reporting-org>
               </iati-activity>
             </iati-activities>
         """)
     crawler.parse_resource(resource)
     db.session.commit()
     db.session.query(Activity).update(
         values={'last_change_datetime': datetime.datetime(2000, 1, 1)},
         synchronize_session=False)
     db.session.commit()
     crawler.parse_resource(resource)
     acts = db.session.query(Activity).all()
     self.assertEquals(datetime.datetime(2000, 1, 1),
                       acts[0].last_change_datetime)
Пример #3
0
 def test_deleted_activity_removal(self):
     db.session.add(DeletedActivity(iati_identifier='test_deleted_activity',
             deletion_date=datetime.datetime(2000, 1, 1)))
     db.session.commit()
     resource = fac.ResourceFactory.create(
         url=u"http://test",
         document="""
             <iati-activities>
               <iati-activity>
                 <iati-identifier>test_deleted_activity</iati-identifier>
                 <title>test_deleted_activity</title>
                 <reporting-org ref="GB-CHC-202918" type="21">Oxfam GB</reporting-org>
               </iati-activity>
             </iati-activities>
         """,
     )
     self.assertIn(
         "test_deleted_activity",
         [da.iati_identifier for da in db.session.query(DeletedActivity).all()]
     )
     resource = crawler.parse_resource(resource)
     db.session.commit()
     self.assertNotIn(
         "test_deleted_activity",
         [da.iati_identifier for da in DeletedActivity.query.all()]
     )
Пример #4
0
    def test_document_metadata(self):
        res = fac.ResourceFactory.create(
            url=u"http://res2",
            document=open(fixture_filename("complex_example_dfid.xml")).read())
        result = crawler.parse_resource(res)

        self.assertEquals("1.00", result.version)
Пример #5
0
 def test_deleted_activity_removal(self):
     db.session.add(
         DeletedActivity(iati_identifier='test_deleted_activity',
                         deletion_date=datetime.datetime(2000, 1, 1)))
     db.session.commit()
     resource = fac.ResourceFactory.create(
         url=u"http://test",
         document="""
             <iati-activities>
               <iati-activity>
                 <iati-identifier>test_deleted_activity</iati-identifier>
                 <title>test_deleted_activity</title>
                 <reporting-org ref="GB-CHC-202918" type="21">Oxfam GB</reporting-org>
               </iati-activity>
             </iati-activities>
         """,
     )
     self.assertIn("test_deleted_activity", [
         da.iati_identifier
         for da in db.session.query(DeletedActivity).all()
     ])
     resource = crawler.parse_resource(resource)
     db.session.commit()
     self.assertNotIn(
         "test_deleted_activity",
         [da.iati_identifier for da in DeletedActivity.query.all()])
Пример #6
0
 def test_document_metadata(self):
     res = fac.ResourceFactory.create(
         url=u"http://res2",
         document=open(fixture_filename("complex_example_dfid.xml")).read()
     )
     result = crawler.parse_resource(res)
     
     self.assertEquals("1.00", result.version)
Пример #7
0
 def test_parse_resource_succ(self):
     resource = Resource(document="<iati-activities />")
     resource = crawler.parse_resource(resource)
     self.assertEquals([], resource.activities)
     self.assertEquals(None, resource.last_parse_error)
     self.assertAlmostEquals(
         resource.last_parsed,
         datetime.datetime.utcnow(),
         delta=datetime.timedelta(seconds=5))
Пример #8
0
 def test_parse_resource_succ(self):
     resource = Resource(document="<iati-activities />", url="http://foo")
     resource = crawler.parse_resource(resource)
     self.assertEquals([], resource.activities)
     self.assertEquals(None, resource.last_parse_error)
     now = datetime.datetime.utcnow()
     self.assertAlmostEquals(resource.last_parsed,
                             now,
                             delta=datetime.timedelta(seconds=15))
Пример #9
0
 def test_parse_resource_succ(self):
     resource = Resource(document="<iati-activities />", url="http://foo")
     resource = crawler.parse_resource(resource)
     self.assertEquals([], list(resource.activities))
     self.assertEquals(None, resource.last_parse_error)
     now = datetime.datetime.utcnow()
     self.assertAlmostEquals(
         resource.last_parsed,
         now,
         delta=datetime.timedelta(seconds=15))
Пример #10
0
 def test_parse_resource_succ_replaces_activities(self):
     # what's in the db before the resource is updated
     act = fac.ActivityFactory.build(iati_identifier="deleted_activity")
     resource = fac.ResourceFactory.create(url=u"http://test",
                                           activities=[act])
     # the updated resource (will remove the activities)
     resource.document = "<iati-activities />"
     resource = crawler.parse_resource(resource)
     db.session.commit()
     self.assertEquals(None, Activity.query.get(act.iati_identifier))
     self.assertIn(
         "deleted_activity",
         [da.iati_identifier for da in DeletedActivity.query.all()])
Пример #11
0
 def test_parse_resource_succ_replaces_activities(self):
     # what's in the db before the resource is updated
     act = fac.ActivityFactory.build()
     fac.ResourceFactory.create(
         url=u"http://test",
         activities=[act]
     )
     # the updated resource (will remove the activities)
     resource = Resource(
         url=u"http://test",
         document="<iati-activities />"
     )
     resource = crawler.parse_resource(resource)
     self.assertEquals(None, Activity.query.get(act.iati_identifier))
Пример #12
0
 def test_parse_resource_succ_replaces_activities(self):
     # what's in the db before the resource is updated
     act = fac.ActivityFactory.build(iati_identifier="deleted_activity")
     resource = fac.ResourceFactory.create(
         url=u"http://test",
         activities=[act]
     )
     # the updated resource (will remove the activities)
     resource.document="<iati-activities />"
     resource = crawler.parse_resource(resource)
     db.session.commit()
     self.assertEquals(None, Activity.query.get(act.iati_identifier))
     self.assertIn(
         "deleted_activity",
         [da.iati_identifier for da in DeletedActivity.query.all()]
     )
Пример #13
0
 def test_parse_resource_fail(self):
     resource = Resource(document="")
     with self.assertRaises(parse.ParserError):
         resource = crawler.parse_resource(resource)
         self.assertEquals(None, resource.last_parsed)
Пример #14
0
 def test_parse_resource_fail(self):
     resource = Resource(document="")
     with self.assertRaises(parse.ParserError):
         resource = crawler.parse_resource(resource)
         self.assertEquals(None, resource.last_parsed)