def setUp(self):
     super(ActorSchemaTests, self).setUp()
     from oe_utils.validation.validators_actor import (
         TelefoonSchemaNode
     )
     self.telefoon_schema = TelefoonSchemaNode()
     self.kbo_schema = KBOSchemaNode()
     self.rrn_schema = RRNSchemaNode()
 def test_kbo_preparer(self):
     self.assertEqual(KBOSchemaNode.preparer(None), colander.null)
     self.assertEqual(KBOSchemaNode.preparer('12.34.56.7.8.911'), '12345678911')
class ActorSchemaTests(unittest.TestCase):
    def setUp(self):
        super(ActorSchemaTests, self).setUp()
        from oe_utils.validation.validators_actor import (
            TelefoonSchemaNode
        )
        self.telefoon_schema = TelefoonSchemaNode()
        self.kbo_schema = KBOSchemaNode()
        self.rrn_schema = RRNSchemaNode()

    def tearDown(self):
        del self.telefoon_schema
        super(ActorSchemaTests, self).tearDown()

    def test_kbo_preparer(self):
        self.assertEqual(KBOSchemaNode.preparer(None), colander.null)
        self.assertEqual(KBOSchemaNode.preparer('12.34.56.7.8.911'), '12345678911')

    def test_kbonummer(self):
        self.kbo_schema.deserialize('1234678911')
        self.assertRaises(colander.Invalid,
                          self.kbo_schema.deserialize,
                          '123'
                          )

    def test_phonenumber_preparer(self):
        self.assertEqual(Telefoon.preparer(None), colander.null)
        self.assertEqual(Telefoon.preparer({'landcode': '02', 'nummer': '/553.54.05'}),
                         {'landcode': '+2', 'nummer': '5535405'})
        self.assertEqual(Telefoon.preparer({'landcode': '    0032', 'nummer': '02/55/3.54     05  '}),
                         {'landcode': '+32', 'nummer': '25535405'})
        self.assertEqual(Telefoon.preparer({'landcode': '+32 ', 'nummer': '496 11 31 67'}),
                         {'landcode': '+32', 'nummer': '496113167'})
        self.assertEqual(Telefoon.preparer({'landcode': '+32', 'nummer': ' 496 11 \t 31 67'}),
                         {'landcode': '+32', 'nummer': '496113167'})
        self.assertEqual(Telefoon.preparer({'landcode': '+32', 'nummer': ' 496. 11 \n 31    67'}),
                         {'landcode': '+32', 'nummer': '496113167'})
        self.assertEqual(Telefoon.preparer({'landcode': '+32', 'nummer': ' 50 60 90 60'}),
                         {'landcode': '+32', 'nummer': '50609060'})
        self.assertEqual(Telefoon.preparer({'landcode': '+32', 'nummer': ' 9 245 13 08'}),
                         Telefoon.preparer({'landcode': '+32', 'nummer': ' 9/245.13.08'}))

    def test_telefoonnummer_number_as_integer(self):
        # number as integer
        self.assertRaises(
            colander.Invalid,
            self.telefoon_schema.deserialize,
            {
                'type': {'id': 1},
                'nummer': 12345
            }
        )

    def test_telefoonnummer_number_less_3(self):
        self.assertRaises(
            colander.Invalid,
            self.telefoon_schema.deserialize,
            {
                'nummer': "01"
            }
        )

    def test_telefoonnummer_number_greater_16(self):
        self.assertRaises(
            colander.Invalid,
            self.telefoon_schema.deserialize,
            {
                'landcode': '+32',
                'nummer': "123456789123456789"
            }
        )

    def test_telefoonnummer_number_small(self):
        self.assertRaises(
            colander.Invalid,
            self.telefoon_schema.deserialize,
            {
                'landcode': '+21456',
                'nummer': "1"
            }
        )

    def test_telefoonnummer_number_belgium_with_0(self):
        self.assertRaises(
            colander.Invalid,
            Telefoon.validator,
            Telefoon(),
            {
                'landcode': '+32',
                'nummer': "0476/123"
            }
        )

    def test_telefoonnummer_number_belgium_with_greater_9(self):
        self.assertRaises(
            colander.Invalid,
            self.telefoon_schema.deserialize,
            {

                'type': {'id': 1},
                'landcode': '0032',
                'nummer': "476/11.22.334"
            }
        )

    def test_telefoonnummer_valid_number(self):
        self.telefoon_schema.deserialize(
            {
                'type': {'id': 1},
                'landcode': "+11",
                'nummer': "255/3.54.05"
            }

        )

    def test_rrn(self):
        self.rrn_schema.deserialize('72020290081')
        self.rrn_schema.deserialize('00012556777')
        self.assertRaises(
            colander.Invalid,
            self.rrn_schema.deserialize, '72020291181'
        )
        self.assertRaises(
            colander.Invalid,
            self.rrn_schema.deserialize, '7202029008'
        )