from unittest import TestCase
from unittest.mock import Mock
from nose_parameterized import parameterized

from grapher import errors
from grapher.parsers import query, RequestQueryParser


class RequestQueryParserTest(TestCase):
    def setUp(self):
        r = Mock()
        r.args = Mock()
        r.args.get = Mock()
        query.request = r

    @parameterized.expand([
        (None, ''),
        ('', ''),
        ('{"test":"test 1"}', '{"test":"test 1"}'),
    ])
    def test_query(self, request_query, expected):
        query.request.args.get.return_value = request_query

        actual = RequestQueryParser.query()

        self.assertEqual(actual, expected)

    @parameterized.expand([
        (None, {}),
        ('{"name":"Test"}', {"name": "Test"}),
    ])
    def test_query_as_object(self, request_query, expected):
        query.request.args.get.return_value = request_query

        actual = RequestQueryParser.query_as_object()

        self.assertDictEqual(actual, expected)

    @parameterized.expand([
        ('{}{}{}',),
        ('{"$xor":{}}',),
    ])
    def test_query_as_object_raise_graph_error(self, request_query):
        query.request.args.get.return_value = request_query

        with self.assertRaises(errors.BadRequestError):
            RequestQueryParser.query_as_object()

@@ -58,134 +58,127 @@
 ock%0A
+%0A
 from 
-nose_parameterized import parameterized%0A%0Afrom grapher import errors%0Afrom grapher.parsers import query, RequestQueryParser
+grapher.parsers import QueryParser%0Afrom grapher.parsers import query%0Afrom nose_parameterized import parameterized
 %0A%0A%0Ac
@@ -182,23 +182,16 @@
 %0A%0Aclass 
-Request
 QueryPar
@@ -375,382 +375,134 @@
 ne, 
-''),%0A        ('', ''),%0A        ('%7B%22test%22:%22test 1%22%7D', '%7B%22test%22:%22test 1%22%7D'),%0A    %5D)%0A    def test_query(self, request_query, expected):%0A        query.request.args.get.return_value = request_query%0A%0A        actual = RequestQueryParser.query()%0A%0A        self.assertEqual(actual, expected)%0A%0A    @parameterized.expand(%5B%0A        (None, %7B%7D),%0A        ('%7B%22name%22:%22Test%22%7D', %7B%22name%22: %22Test%22
+%7B'query': %7B%7D, 'skip': 0, 'limit': None%7D),%0A        ('%7B%22test%22:%22test 1%22%7D', %7B'query': %7B'test': 'test 1'%7D, 'skip': 0, 'limit': None
 %7D),%0A
@@ -521,31 +521,21 @@
 ef test_
-query_as_object
+parse
 (self, r
@@ -637,23 +637,16 @@
 ctual = 
-Request
 QueryPar
@@ -649,31 +649,21 @@
 yParser.
-query_as_object
+parse
 ()%0A%0A    
@@ -681,12 +681,8 @@
 sert
-Dict
 Equa
@@ -705,322 +705,4 @@
 ed)%0A
-%0A    @parameterized.expand(%5B%0A        ('%7B%7D%7B%7D%7B%7D',),%0A        ('%7B%22$xor%22:%7B%7D%7D',),%0A    %5D)%0A    def test_query_as_object_raise_graph_error(self, request_query):%0A        query.request.args.get.return_value = request_query%0A%0A        with self.assertRaises(errors.BadRequestError):%0A            RequestQueryParser.query_as_object()%0A

Update QueryParser tests.