import unittest
from modelverse_state.main import ModelverseState

from modelverse_state import status

class TestCreateDict(unittest.TestCase):
    def setUp(self):
        self.mvs = ModelverseState()

    def test_create_dict_simple(self):
        id1, r1 = self.mvs.create_node()
        id2, r2 = self.mvs.create_node()
        self.assertEquals(r1, status.SUCCESS)
        self.assertEquals(r2, status.SUCCESS)

        n, r = self.mvs.create_dict(id1, "abc", id2)
        self.assertEquals(r, status.SUCCESS)

        v, r = self.mvs.read_dict(id1, "abc")
        self.assertEquals(r, status.SUCCESS)
        self.assertEquals(v, id2)

    def test_create_dict_no_source(self):
        id1 = 100000
        id2, r2 = self.mvs.create_node()
        self.assertEquals(r2, status.SUCCESS)

        n, r = self.mvs.create_dict(id1, "abc", id2)
        self.assertEquals(r, status.FAIL_CDICT_SOURCE)

        v, r = self.mvs.read_dict(id1, "abc")
        self.assertEquals(r, status.FAIL_RDICT_UNKNOWN)
        self.assertEquals(v, None)

    def test_create_dict_no_target(self):
        id2 = 100000
        id1, r2 = self.mvs.create_node()
        self.assertEquals(r2, status.SUCCESS)

        n, r = self.mvs.create_dict(id1, "abc", id2)
        self.assertEquals(r, status.FAIL_CDICT_TARGET)

        v, r = self.mvs.read_dict(id1, "abc")
        self.assertEquals(r, status.FAIL_RDICT_NOT_FOUND)
        self.assertEquals(v, None)
