def test_get_inactive_users_data_added(self): CommCareUser(domain='icds-cas', username='******').save() CommCareUser(domain='icds-cas', username='******').save() IcdsFile.objects.filter( data_type='inactive_dashboard_users').all().delete() collect_inactive_dashboard_users() sync = IcdsFile.objects.filter(data_type='inactive_dashboard_users' ).order_by('-file_added').first() with sync.get_file_from_blobdb() as fileobj, NamedTemporaryFile( ) as out: shutil.copyfileobj(fileobj, out) zip = zipfile.ZipFile(out, 'r') for zipped_file in zip.namelist(): items_file = zip.open(zipped_file) items_file = io.TextIOWrapper(io.BytesIO(items_file.read())) csv_reader = csv.reader(items_file) data = list(csv_reader) sorted(data, key=lambda x: x[0]) self.assertEqual(['Username', 'Location', 'State'], data[0]) self.assertCountEqual([ ['*****@*****.**', '', ''], ['*****@*****.**', '', ''], ], data[1:])
def test_get_inactive_users(self): IcdsFile.objects.filter(data_type='inactive_dashboard_users').all().delete() collect_inactive_dashboard_users() sync = IcdsFile.objects.filter(data_type='inactive_dashboard_users').order_by('-file_added').first() with sync.get_file_from_blobdb() as fileobj: zip = zipfile.ZipFile(fileobj, 'r') for zipped_file in zip.namelist(): items_file = zip.open(zipped_file) items_file = io.TextIOWrapper(io.BytesIO(items_file.read())) csv_reader = csv.reader(items_file) data = list(csv_reader) self.assertEqual([['Username', 'Location', 'State']], data)
def test_get_inactive_users(self): IcdsFile.objects.filter( data_type='inactive_dashboard_users').all().delete() collect_inactive_dashboard_users() sync = IcdsFile.objects.filter(data_type='inactive_dashboard_users' ).order_by('-file_added').first() with sync.get_file_from_blobdb() as fileobj: zip = zipfile.ZipFile(fileobj, 'r') for zipped_file in zip.namelist(): csv_reader = csv.reader(zip.open(zipped_file)) data = list(csv_reader) self.assertEqual([['Username', 'Location', 'State']], data)
def test_get_inactive_users(self): IcdsFile.objects.filter(data_type='inactive_dashboard_users').all().delete() collect_inactive_dashboard_users() sync = IcdsFile.objects.filter(data_type='inactive_dashboard_users').order_by('-file_added').first() with sync.get_file_from_blobdb() as fileobj, NamedTemporaryFile() as out: shutil.copyfileobj(fileobj, out) zip = zipfile.ZipFile(out, 'r') for zipped_file in zip.namelist(): items_file = zip.open(zipped_file) items_file = io.TextIOWrapper(io.BytesIO(items_file.read())) csv_reader = csv.reader(items_file) data = list(csv_reader) self.assertEqual([['Username', 'Location', 'State']], data)
def test_get_inactive_users_data_added(self): CommCareUser(domain='icds-cas', username='******').save() CommCareUser(domain='icds-cas', username='******').save() IcdsFile.objects.filter(data_type='inactive_dashboard_users').all().delete() collect_inactive_dashboard_users() sync = IcdsFile.objects.filter(data_type='inactive_dashboard_users').order_by('-file_added').first() with sync.get_file_from_blobdb() as fileobj: zip = zipfile.ZipFile(fileobj, 'r') for zipped_file in zip.namelist(): items_file = zip.open(zipped_file) items_file = io.TextIOWrapper(io.BytesIO(items_file.read())) csv_reader = csv.reader(items_file) data = list(csv_reader) sorted(data, key=lambda x: x[0]) self.assertEqual(['Username', 'Location', 'State'], data[0]) self.assertCountEqual([ ['*****@*****.**', '', ''], ['*****@*****.**', '', ''], ], data[1:])
def test_get_inactive_users_data_added(self): CommCareUser(domain='icds-cas', username='******').save() CommCareUser(domain='icds-cas', username='******').save() IcdsFile.objects.filter( data_type='inactive_dashboard_users').all().delete() collect_inactive_dashboard_users() sync = IcdsFile.objects.filter(data_type='inactive_dashboard_users' ).order_by('-file_added').first() with sync.get_file_from_blobdb() as fileobj: zip = zipfile.ZipFile(fileobj, 'r') for zipped_file in zip.namelist(): csv_reader = csv.reader(zip.open(zipped_file), ) data = list(csv_reader) sorted(data, key=lambda x: x[0]) self.assertEqual( [['Username', 'Location', 'State'], ['*****@*****.**', '', ''], ['*****@*****.**', '', '']], data)