def test_get_csv_rows(self): rows = subscribers_as_csv_rows() assert len(rows) == len(self.subscribers) + 1 assert ("username", "email") == rows[0] for user in [s.user for s in self.subscribers]: assert (user.username, user.email) in rows
def test_get_csv_rows(self): baker.make(NewsletterSubscriber, user__is_active=False, _quantity=5) # inactive rows = subscribers_as_csv_rows() assert len(rows) == len(self.subscribers) + 1 assert ("username", "email") == rows[0] for user in [s.user for s in self.subscribers]: assert (user.username, user.email) in rows
def view(request): rows = subscribers_as_csv_rows() # we can refactor this later # copied from core/views.py pseudo_buffer = Echo() writer = csv.writer(pseudo_buffer, dialect=csv.excel) response = StreamingHttpResponse( (writer.writerow(row) for row in rows), content_type="text/csv;charset=UTF-8", ) response["Content-Disposition"] = 'attachment; filename="newsletter_subscribers.csv"' response.encoding = "UTF-8" return response
def test_get_csv_rows_without_header(self): rows = subscribers_as_csv_rows(include_header=False) assert len(rows) == len(self.subscribers) for user in [s.user for s in self.subscribers]: assert (user.username, user.email) in rows