示例#1
0
 def test_clean_data_from_data_fetch(self):
     with patch(get_method_path(
             DataFetch.execute_on_save_methods)) as mock_method:
         data, data_fetch, user = self.create_data_fetch_objects()
         self.assertIsNone(DataFile.objects.first())
         tasks.clean_data_from_source(data_fetch.pk,
                                      is_from_file_upload=False)
         self.assertIsNotNone(DataFile.objects.first())
示例#2
0
 def test_build_data_from_data_fetch(self):
     with patch(get_method_path(
             DataFetch.execute_on_save_methods)) as mock_method:
         data, data_fetch, user = self.create_data_fetch_objects()
         TransformFilesToData().create_data_file(data, user, data_fetch)
         dynamic_model_tasks.build_models_from_data_files(
             pk=data_fetch.refined_data_file.pk)
         model = get_dynamic_model("activity")
         self.assertIsNotNone(model)
示例#3
0
 def test_load_one_provider(self):
     data = MockDataProvider.build_strava_data_provider_json()
     with patch(
             get_method_path(
                 InitializeDataProviders.
                 get_data_providers_from_local_or_remote_file)) as mock:
         mock.return_value = [
             data,
         ]
         InitializeDataProviders.load()
     data_provider = DataProvider.objects.get(provider_name="strava")
     self.assertEqual(data_provider.api_endpoint, data["api_endpoint"])
示例#4
0
    def test_update_data_provider_to_json_file(self):
        dp = MockDataProvider.create_data_provider_with_endpoints()

        def side_effect(data):
            data_provider = InitializeDataProviders.find_provider_with_name(
                data, dp)[1]
            self.assertEqual(data_provider["api_endpoint"], "test_endpoint")
            return data

        with patch(
                get_method_path(InitializeDataProviders.write_data_to_json_file
                                )) as mock_method:
            mock_method.side_effect = side_effect
            InitializeDataProviders.update_data_provider_to_json_file(dp)
        mock_method.assert_called_once()
示例#5
0
 def test_execute_on_save_methods_when_has_been_refined(self, name, has_been_refined):
     with patch(get_method_path(tasks.clean_data_from_source) + ".delay") as mock_method:
         baker.make(DataFetch.__name__, make_m2m=True, has_been_refined=has_been_refined)
     self.assertEqual(mock_method.call_count, int(not has_been_refined))