# -*- coding: utf-8 -*-
#

from __future__ import print_function
from datetime import datetime

from django.conf import settings
from django.db import connection

from .common import *


class NodeTest(TestCase):

    def test_add_root(self):
        operator = BinaryOperator(operator='+')
        operator.save()
        root = Node.add_root(content_object=operator)
        self.failUnless(root.id)
        self.failUnless(root.content_object)
        self.failUnlessEqual(operator.operator, root.content_object.operator)
        self.failUnlessEqual('+', root.content_object.operator)
        root = Node.objects.get(id=root.id)
        self.failUnless(root.content_object)
        self.failUnlessEqual(operator.operator, root.content_object.operator)
        self.failUnlessEqual('+', root.content_object.operator)

    def test_add_child(self):
        operator = BinaryOperator(operator='+')
        operator.save()
        root = Node.add_root(content_object=operator)
        self.failUnless(root.is_leaf())

        self.failUnless(root.content_object)
        self.failUnless(root.object_id)
        self.failUnlessEqual(operator.operator, root.content_object.operator)
        self.failUnlessEqual('+', root.content_object.operator)
        self.failUnlessEqual(0, len(root.get_children()))

        number_constant1 = NumberConstant(value=1)
        child_node = root.add_child(content_object=number_constant1)
        self.failUnless(child_node.id)
        self.failUnless(child_node.content_object)

        self.failUnless(root.is_root())
        self.failUnlessEqual(1, len(root.get_children()))

        root = Node.objects.get(id=root.id)
        self.failUnlessEqual(1, len(root.get_children()))

    def test_tree(self):