
import unittest
import mock

from ggrc.converters import query_helper


class TestQueryHelper(unittest.TestCase):

  def test_expression_keys(self):
    """ test expression keys function

    Make sure it works with:
      empty query
      simple query
      complex query
      invalid complex query
    """
    query = mock.MagicMock()
    helper = query_helper.QueryHelper(query)

    expressions = [
        (set(), {}),
        (set(["key_1"]), {
            "left": "key_1",
            "op": {"name": "="},
            "right": "",
        }),
        (set(["key_1", "key_2"]), {
            "left": {
                "left": "key_2",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "AND"},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
        (set(), {
            "left": {
                "left": "5",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "="},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
    ]

    for expected_result, expression in expressions:
      self.assertEqual(expected_result, helper.expression_keys(expression))


import unittest
import mock

from ggrc.converters import query_helper


class TestQueryHelper(unittest.TestCase):

  def test_expression_keys(self):
    """ test expression keys function

    Make sure it works with:
      empty query
      simple query
      complex query
      invalid complex query
    """
    # pylint: disable=protected-access
    # needed for testing protected function inside the query helper
    query = mock.MagicMock()
    helper = query_helper.QueryHelper(query)

    expressions = [
        (set(), {}),
        (set(["key_1"]), {
            "left": "key_1",
            "op": {"name": "="},
            "right": "",
        }),
        (set(["key_1", "key_2"]), {
            "left": {
                "left": "key_2",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "AND"},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
        (set(), {
            "left": {
                "left": "5",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "="},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
    ]

    for expected_result, expression in expressions:
      self.assertEqual(expected_result, helper._expression_keys(expression))

Update unit tests with new query helper names
Update unit tests with new query helper names

  
  import unittest
  import mock
  
  from ggrc.converters import query_helper
  
  
  class TestQueryHelper(unittest.TestCase):
  
    def test_expression_keys(self):
      """ test expression keys function
  
      Make sure it works with:
        empty query
        simple query
        complex query
        invalid complex query
      """
+     # pylint: disable=protected-access
+     # needed for testing protected function inside the query helper
      query = mock.MagicMock()
      helper = query_helper.QueryHelper(query)
  
      expressions = [
          (set(), {}),
          (set(["key_1"]), {
              "left": "key_1",
              "op": {"name": "="},
              "right": "",
          }),
          (set(["key_1", "key_2"]), {
              "left": {
                  "left": "key_2",
                  "op": {"name": "="},
                  "right": "",
              },
              "op": {"name": "AND"},
              "right": {
                  "left": "key_1",
                  "op": {"name": "!="},
                  "right": "",
              },
          }),
          (set(), {
              "left": {
                  "left": "5",
                  "op": {"name": "="},
                  "right": "",
              },
              "op": {"name": "="},
              "right": {
                  "left": "key_1",
                  "op": {"name": "!="},
                  "right": "",
              },
          }),
      ]
  
      for expected_result, expression in expressions:
-       self.assertEqual(expected_result, helper.expression_keys(expression))
+       self.assertEqual(expected_result, helper._expression_keys(expression))
  
Update unit tests with new query helper names
## Code Before:

import unittest
import mock

from ggrc.converters import query_helper


class TestQueryHelper(unittest.TestCase):

  def test_expression_keys(self):
    """ test expression keys function

    Make sure it works with:
      empty query
      simple query
      complex query
      invalid complex query
    """
    query = mock.MagicMock()
    helper = query_helper.QueryHelper(query)

    expressions = [
        (set(), {}),
        (set(["key_1"]), {
            "left": "key_1",
            "op": {"name": "="},
            "right": "",
        }),
        (set(["key_1", "key_2"]), {
            "left": {
                "left": "key_2",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "AND"},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
        (set(), {
            "left": {
                "left": "5",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "="},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
    ]

    for expected_result, expression in expressions:
      self.assertEqual(expected_result, helper.expression_keys(expression))

## Instruction:
Update unit tests with new query helper names
## Code After:

import unittest
import mock

from ggrc.converters import query_helper


class TestQueryHelper(unittest.TestCase):

  def test_expression_keys(self):
    """ test expression keys function

    Make sure it works with:
      empty query
      simple query
      complex query
      invalid complex query
    """
    # pylint: disable=protected-access
    # needed for testing protected function inside the query helper
    query = mock.MagicMock()
    helper = query_helper.QueryHelper(query)

    expressions = [
        (set(), {}),
        (set(["key_1"]), {
            "left": "key_1",
            "op": {"name": "="},
            "right": "",
        }),
        (set(["key_1", "key_2"]), {
            "left": {
                "left": "key_2",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "AND"},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
        (set(), {
            "left": {
                "left": "5",
                "op": {"name": "="},
                "right": "",
            },
            "op": {"name": "="},
            "right": {
                "left": "key_1",
                "op": {"name": "!="},
                "right": "",
            },
        }),
    ]

    for expected_result, expression in expressions:
      self.assertEqual(expected_result, helper._expression_keys(expression))
