示例#1
0
 def setUp(self):
     self.validator = XRI(xri_type="i-number")
示例#2
0
 def setUp(self):
     self.validator = XRI(xri_type="i-name")
示例#3
0
class TestINumberValidator(unittest.TestCase):
    """Tests for the XRI i-number validator"""

    def setUp(self):
        self.validator = XRI(xri_type="i-number")

    def test_valid_global_personal_inumber(self):
        """Global & valid personal i-numbers must pass validation"""
        self.validator.validate_python('=!1000.a1b2.93d2.8c73')

    def test_valid_global_organizational_inumber(self):
        """Global & valid organizational i-numbers must pass validation"""
        self.validator.validate_python('@!1000.a1b2.93d2.8c73')

    def test_valid_global_network_inumber(self):
        """Global & valid network i-numbers must pass validation"""
        self.validator.validate_python('!!1000')

    def test_valid_community_personal_inumbers(self):
        """Community & valid personal i-numbers must pass validation"""
        self.validator.validate_python('=!1000.a1b2.93d2.8c73!3ae2!1490')

    def test_valid_community_organizational_inumber(self):
        """Community & valid organizational i-numbers must pass validation"""
        self.validator.validate_python('@!1000.9554.fabd.129c!2847.df3c')

    def test_valid_community_network_inumber(self):
        """Community & valid network i-numbers must pass validation"""
        self.validator.validate_python('!!1000!de21.4536.2cb2.8074')
示例#4
0
class TestINameValidator(unittest.TestCase):
    """Tests for the XRI i-names validator"""

    def setUp(self):
        self.validator = XRI(xri_type="i-name")

    def test_valid_global_individual_iname(self):
        """Global & valid individual i-names must pass validation"""
        self.validator.validate_python('=Gustavo')

    def test_valid_global_organizational_iname(self):
        """Global & valid organizational i-names must pass validation"""
        self.validator.validate_python('@Canonical')

    def test_invalid_iname(self):
        """Non-string i-names are rejected"""
        self.assertRaises(Invalid, self.validator.validate_python, None)

    def test_exclamation_in_inames(self):
        """Exclamation marks at the beggining of XRIs is something specific
        to i-numbers and must be rejected in i-names"""
        self.assertRaises(Invalid, self.validator.validate_python,
                          "!!1000!de21.4536.2cb2.8074")

    def test_repeated_characters(self):
        """Dots and dashes must not be consecutively repeated in i-names"""
        self.assertRaises(Invalid, self.validator.validate_python,
                          "=Gustavo--Narea")
        self.assertRaises(Invalid, self.validator.validate_python,
                          "=Gustavo..Narea")

    def test_punctuation_marks_at_beggining(self):
        """Punctuation marks at the beggining of i-names are forbidden"""
        self.assertRaises(Invalid, self.validator.validate_python,
                          "=.Gustavo")
        self.assertRaises(Invalid, self.validator.validate_python,
                          "=-Gustavo.Narea")

    def test_numerals_at_beggining(self):
        """Numerals at the beggining of i-names are forbidden"""
        self.assertRaises(Invalid, self.validator.validate_python,
                          "=1Gustavo")

    def test_non_english_inames(self):
        """i-names with non-English characters are valid"""
        self.validator.validate_python(u'=Gustavo.Narea.García')
        self.validator.validate_python(u'@名前.例')

    def test_inames_plus_paths(self):
        """i-names with paths are valid but not supported"""
        self.assertRaises(Invalid, self.validator.validate_python,
                          "=Gustavo/(+email)")

    def test_communities(self):
        """i-names may have so-called 'communities'"""
        self.validator.validate_python(u'=María*Yolanda*Liliana*Gustavo')
        self.validator.validate_python(u'=Gustavo*Andreina')
        self.validator.validate_python(u'@IBM*Lenovo')
示例#5
0
 def test_spaces_are_trimmed(self):
     """Spaces at the beggining or end of the XRI are removed"""
     validator = XRI()
     self.assertEqual(validator.to_python('    =Gustavo  '), '=Gustavo')
示例#6
0
 def test_schema_not_added_if_not_asked(self):
     """The schema must not be added to an XRI unless explicitly asked"""
     validator = XRI()
     self.assertEqual(validator.to_python('=Gustavo'), '=Gustavo')
示例#7
0
 def test_schema_is_added_if_asked(self):
     """The schema must be added to an XRI if explicitly asked"""
     validator = XRI(True)
     self.assertEqual(validator.to_python('=Gustavo'),
                      'xri://=Gustavo')
示例#8
0
 def test_valid_iname_with_schema(self):
     """XRIs may have their schema in the beggining"""
     validator = XRI()
     self.assertEqual(validator.to_python('xri://=Gustavo'),
                      'xri://=Gustavo')