<commit_before>import unittest
import urllib
import datetime
from hamcrest import *
from mock import patch
import pytz
from backdrop.read import api


class ReadApiTestCase(unittest.TestCase):
    def setUp(self):
        self.app = api.app.test_client()

    @patch('backdrop.core.storage.Bucket.query')
    def test_period_query_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get('/foo?period=week')
        mock_query.assert_called_with(period=u"week")

    @patch('backdrop.core.storage.Bucket.query')
    def test_filter_by_query_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get('/foo?filter_by=zombies:yes')
        mock_query.assert_called_with(filter_by=[[u'zombies', u'yes']])

    @patch('backdrop.core.storage.Bucket.query')
    def test_group_by_query_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get('/foo?group_by=zombies')
        mock_query.assert_called_with(group_by=u'zombies')

    @patch('backdrop.core.storage.Bucket.query')
    def test_start_at_is_executed(self, mock_query):
        mock_query.return_value = None
        expected_start_at = datetime.datetime(2012, 12, 12, 8, 12, 43,
                                              tzinfo=pytz.UTC)
        self.app.get(
            '/foo?start_at=' + urllib.quote("2012-12-12T08:12:43+00:00")
        )
        mock_query.assert_called_with(start_at=expected_start_at)

    @patch('backdrop.core.storage.Bucket.query')
    def test_start_at_is_executed(self, mock_query):
        mock_query.return_value = None
        expected_end_at = datetime.datetime(2012, 12, 12, 8, 12, 43,
                                            tzinfo=pytz.UTC)
        self.app.get(
            '/foo?end_at=' + urllib.quote("2012-12-12T08:12:43+00:00")
        )
        mock_query.assert_called_with(end_at=expected_end_at)<commit_msg>Test query is parsed and sent to bucket<commit_after>import unittest
import urllib
import datetime
from hamcrest import *
from mock import patch
import pytz
from backdrop.read import api


class ReadApiTestCase(unittest.TestCase):
    def setUp(self):
        self.app = api.app.test_client()

    @patch('backdrop.core.storage.Bucket.query')
    def test_period_query_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get('/foo?period=week')
        mock_query.assert_called_with(period=u"week")

    @patch('backdrop.core.storage.Bucket.query')
    def test_filter_by_query_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get('/foo?filter_by=zombies:yes')
        mock_query.assert_called_with(filter_by=[[u'zombies', u'yes']])

    @patch('backdrop.core.storage.Bucket.query')
    def test_group_by_query_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get('/foo?group_by=zombies')
        mock_query.assert_called_with(group_by=u'zombies')

    @patch('backdrop.core.storage.Bucket.query')
    def test_start_at_query_is_executed(self, mock_query):
        mock_query.return_value = None
        expected_start_at = datetime.datetime(2012, 12, 12, 8, 12, 43,
                                              tzinfo=pytz.UTC)
        self.app.get(
            '/foo?start_at=' + urllib.quote("2012-12-12T08:12:43+00:00")
        )
        mock_query.assert_called_with(start_at=expected_start_at)

    @patch('backdrop.core.storage.Bucket.query')
    def test_end_at_query_is_executed(self, mock_query):
        mock_query.return_value = None
        expected_end_at = datetime.datetime(2012, 12, 12, 8, 12, 43,
                                            tzinfo=pytz.UTC)
        self.app.get(
            '/foo?end_at=' + urllib.quote("2012-12-12T08:12:43+00:00")
        )
        mock_query.assert_called_with(end_at=expected_end_at)

    @patch('backdrop.core.storage.Bucket.query')
    def test_group_by_with_period_is_executed(self, mock_query):
        mock_query.return_value = None
        self.app.get(
            '/foo?period=week&group_by=stuff'
        )
        mock_query.assert_called_with(period="week", group_by="stuff")
{'fraction_non_alphanumeric': 0.11412131383361304, 'fraction_numerical': 0.029729081754974827, 'mean_word_length': 2.980916030534351, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '490160', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1377, 'n_words': 188}