# Path: doorman/rules.py
# class Network(object):
# class BaseCondition(object):
# class AndCondition(BaseCondition):
# class OrCondition(BaseCondition):
# class LogicCondition(BaseCondition):
# class EqualCondition(LogicCondition):
# class NotEqualCondition(LogicCondition):
# class BeginsWithCondition(LogicCondition):
# class NotBeginsWithCondition(LogicCondition):
# class ContainsCondition(LogicCondition):
# class NotContainsCondition(LogicCondition):
# class EndsWithCondition(LogicCondition):
# class NotEndsWithCondition(LogicCondition):
# class IsEmptyCondition(LogicCondition):
# class IsNotEmptyCondition(LogicCondition):
# class LessCondition(LogicCondition):
# class LessEqualCondition(LogicCondition):
# class GreaterCondition(LogicCondition):
# class GreaterEqualCondition(LogicCondition):
# class MatchesRegexCondition(LogicCondition):
# class NotMatchesRegexCondition(LogicCondition):
#     def __init__(self):
#     def make_condition(self, klass, *args, **kwargs):
#         def tupleify(obj):
#     def make_alert_condition(self, alert, dependent, rule_id=None):
#     def process(self, entry, node):
#     def parse_query(self, query, alerters=None, rule_id=None):
#         def parse_condition(d):
#         def parse_group(d):
#         def parse(d):
#     def __init__(self):
#     def init_network(self, network):
#     def run(self, input):
#     def local_run(self, input):
#     def __repr__(self):
#     def __init__(self, upstream):
#     def local_run(self, input):
#     def __init__(self, upstream):
#     def local_run(self, input):
#     def __init__(self, key, expected, column_name=None):
#     def maybe_make_number(self, value):
#     def local_run(self, input):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def __init__(self, key, expected, **kwargs):
#     def compare(self, value):
#     def __init__(self, key, expected, **kwargs):
#     def compare(self, value):
# OPERATOR_MAP = {
#     'equal': EqualCondition,
#     'not_equal': NotEqualCondition,
#     'begins_with': BeginsWithCondition,
#     'not_begins_with': NotBeginsWithCondition,
#     'contains': ContainsCondition,
#     'not_contains': NotContainsCondition,
#     'ends_with': EndsWithCondition,
#     'not_ends_with': NotEndsWithCondition,
#     'is_empty': IsEmptyCondition,
#     'is_not_empty': IsNotEmptyCondition,
#     'less': LessCondition,
#     'less_or_equal': LessEqualCondition,
#     'greater': GreaterCondition,
#     'greater_or_equal': GreaterEqualCondition,
#     'matches_regex': MatchesRegexCondition,
#     'not_matches_regex': NotMatchesRegexCondition,
# }


import json
import logging
import datetime as dt
from collections import defaultdict
from doorman.rules import (
    BaseCondition,
    EqualCondition,
    LessCondition,
    GreaterEqualCondition,
    LogicCondition,
    MatchesRegexCondition,
    Network,
    NotMatchesRegexCondition,
    RuleInput,
)
                  "field": "query_name",
                  "type": "string",
                  "input": "text",
                  "operator": "equal",
                  "value": "asdf"
                }
              ]
            }
          ]
        }""")

        network = Network()
        network.parse_query(query)

        counts = defaultdict(int)
        for condition in network.conditions.values():
            counts[condition.__class__.__name__] += 1

        # Top level, each sub-group (not reused), each condition
        assert counts == {'AndCondition': 3, 'EqualCondition': 1, 'NotEqualCondition': 1}

    def test_parse_error_no_rules_in_group(self):
        # Different operators in each sub-group
        query = json.loads("""
        {
          "condition": "AND",
          "rules": [
          ]
        }""")


# Path: doorman/rules.py
# class Network(object):
# class BaseCondition(object):
# class AndCondition(BaseCondition):
# class OrCondition(BaseCondition):
# class LogicCondition(BaseCondition):
# class EqualCondition(LogicCondition):
# class NotEqualCondition(LogicCondition):
# class BeginsWithCondition(LogicCondition):
# class NotBeginsWithCondition(LogicCondition):
# class ContainsCondition(LogicCondition):
# class NotContainsCondition(LogicCondition):
# class EndsWithCondition(LogicCondition):
# class NotEndsWithCondition(LogicCondition):
# class IsEmptyCondition(LogicCondition):
# class IsNotEmptyCondition(LogicCondition):
# class LessCondition(LogicCondition):
# class LessEqualCondition(LogicCondition):
# class GreaterCondition(LogicCondition):
# class GreaterEqualCondition(LogicCondition):
# class MatchesRegexCondition(LogicCondition):
# class NotMatchesRegexCondition(LogicCondition):
#     def __init__(self):
#     def make_condition(self, klass, *args, **kwargs):
#         def tupleify(obj):
#     def make_alert_condition(self, alert, dependent, rule_id=None):
#     def process(self, entry, node):
#     def parse_query(self, query, alerters=None, rule_id=None):
#         def parse_condition(d):
#         def parse_group(d):
#         def parse(d):
#     def __init__(self):
#     def init_network(self, network):
#     def run(self, input):
#     def local_run(self, input):
#     def __repr__(self):
#     def __init__(self, upstream):
#     def local_run(self, input):
#     def __init__(self, upstream):
#     def local_run(self, input):
#     def __init__(self, key, expected, column_name=None):
#     def maybe_make_number(self, value):
#     def local_run(self, input):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def compare(self, value):
#     def __init__(self, key, expected, **kwargs):
#     def compare(self, value):
#     def __init__(self, key, expected, **kwargs):
#     def compare(self, value):
# OPERATOR_MAP = {
#     'equal': EqualCondition,
#     'not_equal': NotEqualCondition,
#     'begins_with': BeginsWithCondition,
#     'not_begins_with': NotBeginsWithCondition,
#     'contains': ContainsCondition,
#     'not_contains': NotContainsCondition,
#     'ends_with': EndsWithCondition,
#     'not_ends_with': NotEndsWithCondition,
#     'is_empty': IsEmptyCondition,
#     'is_not_empty': IsNotEmptyCondition,
#     'less': LessCondition,
#     'less_or_equal': LessEqualCondition,
#     'greater': GreaterCondition,
#     'greater_or_equal': GreaterEqualCondition,
#     'matches_regex': MatchesRegexCondition,
#     'not_matches_regex': NotMatchesRegexCondition,
# }


# Path: tests/test_rules.py
import json
import logging
import datetime as dt
from collections import defaultdict
from doorman.rules import (
    BaseCondition,
    EqualCondition,
    LessCondition,
    GreaterEqualCondition,
    LogicCondition,
    MatchesRegexCondition,
    Network,
    NotMatchesRegexCondition,
    RuleInput,
)

                  "field": "query_name",
                  "type": "string",
                  "input": "text",
                  "operator": "equal",
                  "value": "asdf"
                }
              ]
            }
          ]
        }""")

        network = Network()
        network.parse_query(query)

        counts = defaultdict(int)
        for condition in network.conditions.values():
            counts[condition.__class__.__name__] += 1

        # Top level, each sub-group (not reused), each condition
        assert counts == {'AndCondition': 3, 'EqualCondition': 1, 'NotEqualCondition': 1}

    def test_parse_error_no_rules_in_group(self):
        # Different operators in each sub-group
        query = json.loads("""
        {
          "condition": "AND",
          "rules": [
          ]
        }""")


        network = Network()