def test_date_from_name(): csv_file = CsvFile(api_name='series', type='analytics', file_name='analytics_2018-12-20.csv', file=Mock()) assert csv_file.date_from_name().strftime('%Y-%m-%d') == '2018-12-20'
def test_years_from_name(): csv_file = CsvFile(api_name='series', type='analytics', file_name='analytics_2018-12-20.csv', file=Mock()) assert csv_file.years_from_name() == '2018'
def create_csv_file(name): with open(str(settings.MEDIA_ROOT + name), 'r+') as file: CsvFile(type='analytics', api_name='series', file_name=name, file=File(file)).save() return file
def test_compress_single_file(): file_name = 'analytics_2018-10-15.csv' csv_file = CsvFile(api_name='series', file_name=file_name, file=get_file_mock(file_name)) create_csv_file('analytics_2018-10-15.csv') csv_compressor().compress_single_file(csv_file) assert ZipFile.objects.count() == 1 assert 'analytics_2018.zip' in ZipFile.objects.first().file_name
def create_csv_file(self, file_name, file): csv_file = self.get_csv_file(file_name) if csv_file is not None: if csv_file.file.name != '': csv_file.file.delete() # removes from disk csv_file.file = File(file) csv_file.save() else: CsvFile(api_name=self.api_name, file_name=file_name, file=File(file), type=self.csv_file_type()).save()
def get_csv_file(): return CsvFile(api_name='series', type='analytics', file_name='analytics_2018-12-20.csv', file=Mock())
def test_years_from_csv_file_name(): csv_file = CsvFile(api_name='series', file_name='analytics_2017-10-15.csv') assert csv_compressor().years_from_csv_file_name(csv_file) == '2017'