<commit_before>from datetime import datetime
from mock import patch
from nose.tools import raises
import os

from onadata.apps.api.tools import get_form_submissions_grouped_by_field
from onadata.apps.main.tests.test_base import TestBase


class TestTools(TestBase):

    def setUp(self):
        super(self.__class__, self).setUp()
        self._create_user_and_login()
        self._publish_transportation_form()

    @patch('django.utils.timezone.now')
    def test_get_form_submissions_grouped_by_field(self, mock_time):
        mock_time.return_value = datetime.now()
        self._make_submissions()

        count_key = 'count'
        fields = ['_submission_time', '_xform_id_string']

        count = len(self.xform.surveys.all())

        for field in fields:
            result = get_form_submissions_grouped_by_field(
                self.xform, field)[0]

            self.assertEqual([field, count_key], sorted(result.keys()))
            self.assertEqual(result[count_key], count)<commit_msg>PLD: add test for datetime fields as date #118<commit_after>from datetime import datetime
import os

from mock import patch
from nose.tools import raises

from onadata.apps.api.tools import get_form_submissions_grouped_by_field
from onadata.apps.main.tests.test_base import TestBase


class TestTools(TestBase):

    def setUp(self):
        super(self.__class__, self).setUp()
        self._create_user_and_login()
        self._publish_transportation_form()

    @patch('django.utils.timezone.now')
    def test_get_form_submissions_grouped_by_field(self, mock_time):
        mock_time.return_value = datetime.now()
        self._make_submissions()

        count_key = 'count'
        fields = ['_submission_time', '_xform_id_string']

        count = len(self.xform.surveys.all())

        for field in fields:
            result = get_form_submissions_grouped_by_field(
                self.xform, field)[0]

            self.assertEqual([field, count_key], sorted(result.keys()))
            self.assertEqual(result[count_key], count)

    def test_get_form_submissions_grouped_by_field_datetime_to_date(self):
        self._make_submissions(pause=1)

        count_key = 'count'
        fields = ['_submission_time']

        count = len(self.xform.surveys.all())

        for field in fields:
            result = get_form_submissions_grouped_by_field(
                self.xform, field)

            self.assertEqual([field, count_key], sorted(result.keys()))
            self.assertEqual(result[count_key], count)
{'fraction_non_alphanumeric': 0.09450375642546462, 'fraction_numerical': 0.002372479240806643, 'mean_word_length': 3.1680395387149916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '349343', 'n_tokens_mistral': 785, 'n_tokens_neox': 748, 'n_words': 143}