1- from datetime import datetime , date
21import json
3- import unittest
42from unittest .mock import patch , MagicMock
5- import tempfile
63import os
7- import time
8- from datetime import datetime
9- import pdb
10- import pandas as pd
11- import pandas .api .types as ptypes
124
135from delphi_nssp .pull import (
146 pull_nssp_data ,
157)
16- from delphi_nssp .constants import (
17- SIGNALS ,
18- NEWLINE ,
19- SIGNALS_MAP ,
20- TYPE_DICT ,
21- )
8+ from delphi_nssp .constants import SIGNALS
229
10+ from delphi_utils import get_structured_logger
2311
24- class TestPullNSSPData ( unittest . TestCase ) :
12+ class TestPullNSSPData :
2513 @patch ("delphi_nssp.pull.Socrata" )
26- def test_pull_nssp_data (self , mock_socrata ):
14+ def test_pull_nssp_data (self , mock_socrata , caplog ):
2715 # Load test data
2816 with open ("test_data/page.txt" , "r" ) as f :
2917 test_data = json .load (f )
@@ -40,19 +28,18 @@ def test_pull_nssp_data(self, mock_socrata):
4028
4129 custom_run = False
4230
43- mock_logger = MagicMock ()
31+ logger = get_structured_logger ()
4432
4533 # Call function with test token
4634 test_token = "test_token"
47- result = pull_nssp_data (test_token , backup_dir , custom_run , mock_logger )
48- print (result )
35+ result = pull_nssp_data (test_token , backup_dir , custom_run , logger )
4936
5037 # Check logger used:
51- mock_logger . info . assert_called ()
38+ assert "Backup file created" in caplog . text
5239
5340 # Check that backup file was created
5441 backup_files = os .listdir (backup_dir )
55- assert len (backup_files ) == 1 , "Backup file was not created"
42+ assert len (backup_files ) == 2 , "Backup file was not created"
5643
5744 # Check that Socrata client was initialized with correct arguments
5845 mock_socrata .assert_called_once_with ("data.cdc.gov" , test_token )
@@ -71,6 +58,3 @@ def test_pull_nssp_data(self, mock_socrata):
7158 for signal in SIGNALS :
7259 assert result [signal ].notnull ().all (), f"{ signal } has rogue NaN"
7360
74-
75- if __name__ == "__main__" :
76- unittest .main ()
0 commit comments