<commit_before>""" Tests for analytics.csvs """

from __future__ import absolute_import

import pytest
from django.test import TestCase
from six.moves import range

from lms.djangoapps.instructor_analytics.csvs import create_csv_response, format_dictlist, format_instances


class TestAnalyticsCSVS(TestCase):
    """ Test analytics rendering of csv files."""

    def test_create_csv_response_nodata(self):
        header = ['Name', 'Email']
        datarows = []

        res = create_csv_response('robot.csv', header, datarows)
        self.assertEqual(res['Content-Type'], 'text/csv')
        self.assertEqual(res['Content-Disposition'], u'attachment; filename={0}'.format('robot.csv'))
        self.assertEqual(res.content.strip(), '"Name","Email"')

    def test_create_csv_response(self):
        header = ['Name', 'Email']
        datarows = [['Jim', '<EMAIL>'], ['Jake', '<EMAIL>'], ['Jeeves', '<EMAIL>']]

        res = create_csv_response('robot.csv', header, datarows)
        self.assertEqual(res['Content-Type'], 'text/csv')
        self.assertEqual(res['Content-Disposition'], u'attachment; filename={0}'.format('robot.csv'))
        self.assertEqual(res.content.strip(), '"Name","Email"\r\n"Jim","<EMAIL>"\r\n"Jake","<EMAIL>"\r\n"Jeeves","<EMAIL>"')

    def test_create_csv_response_empty(self):
        header = []
        datarows = []

        res = create_csv_response('robot.csv', header, datarows)
        self.assertEqual(res['Content-Type'], 'text/csv')
        self.assertEqual(res['Content-Disposition'], u'attachment; filename={0}'.format('robot.csv'))
        self.assertEqual(res.content.strip(), '')


class TestAnalyticsFormatDictlist(TestCase):
    """ Test format_dictlist method """<commit_msg>BOM-142 Py3 Assertion Error<commit_after>""" Tests for analytics.csvs """

from __future__ import absolute_import

import pytest
from django.test import TestCase
from six.moves import range

from lms.djangoapps.instructor_analytics.csvs import create_csv_response, format_dictlist, format_instances


class TestAnalyticsCSVS(TestCase):
    """ Test analytics rendering of csv files."""

    def test_create_csv_response_nodata(self):
        header = ['Name', 'Email']
        datarows = []

        res = create_csv_response('robot.csv', header, datarows)
        self.assertEqual(res['Content-Type'], 'text/csv')
        self.assertEqual(res['Content-Disposition'], u'attachment; filename={0}'.format('robot.csv'))
        self.assertEqual(res.content.strip(), '"Name","Email"')

    def test_create_csv_response(self):
        header = ['Name', 'Email']
        datarows = [['Jim', '<EMAIL>'], ['Jake', '<EMAIL>'], ['Jeeves', '<EMAIL>']]

        res = create_csv_response('robot.csv', header, datarows)
        self.assertEqual(res['Content-Type'], 'text/csv')
        self.assertEqual(res['Content-Disposition'], u'attachment; filename={0}'.format('robot.csv'))
        self.assertEqual(res.content.strip(), '"Name","Email"\r\n"Jim","<EMAIL>"\r\n"Jake","<EMAIL>"\r\n"Jeeves","<EMAIL>"')

    def test_create_csv_response_empty(self):
        header = []
        datarows = []

        res = create_csv_response('robot.csv', header, datarows)
        self.assertEqual(res['Content-Type'], 'text/csv')
        self.assertEqual(res['Content-Disposition'], u'attachment; filename={0}'.format('robot.csv'))
        self.assertEqual(res.content.strip().decode('utf-8'), '')


class TestAnalyticsFormatDictlist(TestCase):
    """ Test format_dictlist method """
{'fraction_non_alphanumeric': 0.1694380733944954, 'fraction_numerical': 0.0031536697247706424, 'mean_word_length': 4.230884557721139, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4149349', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1064, 'n_words': 185}