Esempio n. 1
0
    def test_bulk_create_lt_10000(self, load_geography, MockDatasetData,
                                  good_input):
        dataset = Mock()
        dataset.geography_hierarchy.version = 9999

        dataloader.loaddata(dataset, good_input, 0)

        MockDatasetData.objects.bulk_create.assert_called_once()
        load_geography.called_with("YYY", 222)
Esempio n. 2
0
    def test_bulk_check_load_geography_call(self, load_geography,
                                            MockDatasetData, good_input):
        dataset = Mock()
        dataset.geography_hierarchy.version = 9999
        load_geography.return_value = "XXX"

        dataloader.loaddata(dataset, good_input, 0)

        load_geography.assert_called_with("YYY", 9999)
Esempio n. 3
0
    def test_create_groups_called(self, create_groups, load_geography,
                                  MockDatasetData, good_input_with_groups):
        data = good_input_with_groups
        dataset = Mock(spec=models.Dataset)

        dataloader.loaddata(dataset, data, 0)

        assert create_groups.call_count == 1
        create_groups.assert_called_with(dataset, ["group1", "group2"])
Esempio n. 4
0
    def test_bulk_create_gt_10000(self, load_geography, MockDatasetData,
                                  good_input):
        dataset = Mock()
        load_geography.return_value = "XXX"

        input_data = [dict(good_input[0]) for i in range(20001)]

        dataloader.loaddata(dataset, input_data, 0)

        assert MockDatasetData.objects.bulk_create.call_count == 3
Esempio n. 5
0
    def test_datasetdata_created(self, load_geography, MockDatasetData,
                                 group_objects, good_input_with_groups):
        data = good_input_with_groups
        dataset = Mock(spec=models.Dataset)

        dataloader.loaddata(dataset, data, 0)

        assert MockDatasetData.call_count == 2
        args1 = MockDatasetData.call_args_list[0][1]
        args2 = MockDatasetData.call_args_list[1][1]
        assert args1["data"] == data[0]
        assert args1["dataset"] == dataset
        assert args2["data"] == data[1]
        assert args2["dataset"] == dataset
Esempio n. 6
0
    def test_bad_count(self, load_geography):
        dataset = Mock()
        input_data = [{"geography": "XXX", "count": ""}]

        (errors, warnings) = dataloader.loaddata(dataset, input_data, 0)
        assert len(warnings) == 0
        assert len(errors) == 1
Esempio n. 7
0
    def test_missing_geography(self, load_geography, MockDatasetData,
                               good_input):
        dataset = Mock()
        load_geography.side_effect = models.Geography.DoesNotExist()

        try:
            (errors, warnings) = dataloader.loaddata(dataset, good_input, 0)
            assert len(warnings) == 2
            assert len(errors) == 0
        except models.Geography.DoesNotExist:
            assert False

        assert MockDatasetData.objects.bulk_create.call_count == 1
        MockDatasetData.objects.bulk_create.assert_called_with([], 1000)