Пример #1
0
    def test_delete_removed_activities(self):
        """The parser should remove activities that are not in the source any longer

        create 2 activities
        mock a file with 1 of them
        parsing this file should delete the other activity
        """
        root = E('iati-activities', version='2.01')
        xml_activity = E('iati-activity')
        xml_title = E('title', 'Title of activity 1')
        xml_activity.append(xml_title)
        xml_identifier = E('iati-identifier', 'IATI-0001')
        xml_activity.append(xml_identifier)
        root.append(xml_activity)

        self.parser = Parser_201(root)
        self.parser.dataset = self.dataset
        # mock non related functions that are called (and that use postgres fts
        # which makes the test fail on sqlite)
        self.parser.update_activity_search_index = MagicMock()
        self.parser.post_save_models = MagicMock()

        self.parser.parse_start_datetime = datetime.datetime.now()
        self.parser.parse_activities(root)

        self.assertEqual(Activity.objects.count(), 1)
Пример #2
0
    def setUp(self):
        self.parser = Parser_201(None)

        version = VersionFactory.create(code='2.01')
        self.activity = iati_factory.ActivityFactory.create(
            id='IATI-0001',
            iati_identifier='IATI-0001',
            iati_standard_version=version,
            xml_source_ref='source_reference')
Пример #3
0
    def setUp(self):
        self.parser = Parser_201(None)

        version = VersionFactory.create(code='2.01')
        dataset = DatasetFactory.create(name='dataset-4')
        self.activity = iati_factory.ActivityFactory.create(
            iati_identifier='IATI-0001',
            iati_standard_version=version,
            dataset=dataset)
 def test_post_save_file(self):
     """
     Check if all required functions are called
     """
     self.parser = Parser_201(None)
     self.parser.dataset = self.dataset
     self.parser.delete_removed_activities = MagicMock()
     self.parser.post_save_file(self.parser.dataset)
     self.parser.delete_removed_activities.assert_called_once_with(
         self.parser.dataset)
    def setUp(self):
        self.parser = Parser_201(None)

        # XXX: previously, django's 'flush' management command was called to
        # flush the database, but it breaks tests ('no table blah blah exists')
        # and etc., so let's just manually remove objects which were created
        # during previous fixtures.
        # TODO: get rid of fixtures and use factory-boy everywhere.
        Sector.objects.all().delete()

        version = VersionFactory.create(code='2.01')
        dataset = DatasetFactory.create(name='dataset-4')
        self.activity = iati_factory.ActivityFactory.create(
            iati_identifier='IATI-0001',
            iati_standard_version=version,
            dataset=dataset)
Пример #6
0
    def test_register_model_stores_model_by_name(self):
        parser = Parser_201(None)

        activity = build_activity()
        parser.register_model(activity, activity)
        self.assertTrue(parser.model_store['Activity'][0] == activity)