def test_download_csv_with_an_username_contains_ascii_code(self): self.user.username = '******' self.user.save() response = download_as_csv(ProfileUserAdmin(UserProfile, self.site), None, User.objects.all()) self.assertContains(response, '사이네')
def test_download_csv_with_an_alias_contains_ascii_code(self): profile = self.user.profile profile.alias = 'The Alias 😁' profile.mobile_number = '+27784667723' profile.save() response = download_as_csv(ProfileUserAdmin(UserProfile, self.site), None, User.objects.all()) self.assertContains(response, 'The Alias 😁')
def test_download_csv_with_an_username_contains_ascii_code(self): self.user.username = '******' self.user.save() response = download_as_csv(ProfileUserAdmin(UserProfile, self.site), None, User.objects.all()) date = str(self.user.date_joined.strftime("%Y-%m-%d %H:%M")) expected_output = ('Content-Type: text/csv\r\nContent-Disposition: ' 'attachment;filename=export.csv\r\n\r\nusername,' 'email,first_name,last_name,is_staff,date_joined,' 'alias,mobile_number\r\n\xec\x82\xac\xec\x9d\xb4' '\xeb\x84\xa4,[email protected],' ',,False,' + date + ',,\r\n') self.assertEquals(str(response), expected_output)
def test_download_csv(self): profile = self.user.profile profile.alias = 'The Alias' profile.mobile_number = '+27784667723' profile.save() response = download_as_csv(ProfileUserAdmin(UserProfile, self.site), None, User.objects.all()) date = str(self.user.date_joined.strftime("%Y-%m-%d %H:%M")) expected_output = ('Content-Type: text/csv\r\nContent-Disposition: ' 'attachment;filename=export.csv\r\n\r\nusername,' 'email,first_name,last_name,is_staff,date_joined,' 'alias,mobile_number\r\ntester,[email protected],' ',,False,' + date + ',The Alias,+27784667723\r\n') self.assertEquals(str(response), expected_output)
def test_download_csv(self): profile = self.user.profile profile.alias = 'The Alias' profile.mobile_number = '+27784667723' profile.save() response = download_as_csv(ProfileUserAdmin(UserProfile, self.site), None, User.objects.all()) date = str(self.user.date_joined.strftime("%Y-%m-%d %H:%M")) csv_header = [ 'username', 'email', 'first_name', 'last_name', 'is_staff', 'date_joined', 'alias', 'mobile_number', ] csv_row_one = [ 'tester', '*****@*****.**', '', '', 'False', date, 'The Alias', '+27784667723', ] expected_csv = [ ','.join(csv_header), ','.join(csv_row_one), '', ] self.assertTrue(isinstance(response, HttpResponse)) self.assertContains(response, "\r\n".join(expected_csv)) self.assertEqual( response['Content-Type'], 'text/csv', ) self.assertEqual( response['Content-Disposition'], 'attachment;filename=export.csv', )