def test_directives_correct_no_dupes(self):
     """
     Tests that a ServerName object properly returns a unique directive if the same directive
     is added multiple times.
     """
     directive = {"signature": "a:0.0.0.0:80:a.b.c:/"}
     handle_servername = ServerName(**{
         "domain": self.valid_domain,
     })
     for i in range(10):
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.directives), 1)
     self.assertEqual(directive, handle_servername.directives[0])
     del handle_servername
 def test_directives_correct_no_dupes(self):
     """
     Tests that a ServerName object properly returns a unique directive if the same directive
     is added multiple times.
     """
     directive = { "signature" : "a:0.0.0.0:80:a.b.c:/"}
     handle_servername = ServerName(**{
                                         "domain" : self.valid_domain,
                                     }
                                 )
     for i in range(10):
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.directives), 1)
     self.assertEqual(directive, handle_servername.directives[0])
     del handle_servername
 def test_build_correct(self):
     """
     Tests that the _build method properly turns the directives into unique Location objects.
     """
     handle_servername = ServerName(**{
                                         "domain" : self.valid_domain,
                                     }
                                 )
     directives = [
                     { "signature" : "a:0.0.0.0:80:a.b.c.d:/"},
                     { "signature" : "a:0.0.0.0:80:a.b.c.d:/that_place/"},
                     ]
     for directive in directives:
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.locations.keys()), 2)
     del handle_servername
 def test_is_valid_correct_invalid_location(self):
     """
     Tests that the is_valid property correctly returns False if any of its ServerName is
     invalid.
     """
     directives = [
                     { "signature" : "container1:0.0.0.0:80:a.b.c:/location1/"},
                     { "signature" : "container2:0.0.0.0:80:a.b.c:/location1/"}
                     ]
     handle_servername = ServerName(**{
                                         "domain" : self.valid_domain,
                                     }
                                 )
     for directive in directives:
         handle_servername.directives = directive
     self.assertFalse(handle_servername.is_valid)
     del handle_servername
 def test_is_valid_correct(self):
     """
     Tests that the is_valid property correctly returns True if all the Location objects
     associated to a ServerName are valid.
     """
     directives = [
                     { "signature" : "container1:0.0.0.0:80:a.b.c:/location1/"},
                     { "signature" : "container1:0.0.0.0:80:a.b.c:/location2/"}
                     ]
     handle_servername = ServerName(**{
                                         "domain" : self.valid_domain,
                                     }
                                 )
     for directive in directives:
         handle_servername.directives = directive
     self.assertTrue(handle_servername.is_valid)
     del handle_servername
 def test_is_valid_correct_invalid_location(self):
     """
     Tests that the is_valid property correctly returns False if any of its ServerName is
     invalid.
     """
     directives = [{
         "signature": "container1:0.0.0.0:80:a.b.c:/location1/"
     }, {
         "signature": "container2:0.0.0.0:80:a.b.c:/location1/"
     }]
     handle_servername = ServerName(**{
         "domain": self.valid_domain,
     })
     for directive in directives:
         handle_servername.directives = directive
     self.assertFalse(handle_servername.is_valid)
     del handle_servername
 def test_is_valid_correct(self):
     """
     Tests that the is_valid property correctly returns True if all the Location objects
     associated to a ServerName are valid.
     """
     directives = [{
         "signature": "container1:0.0.0.0:80:a.b.c:/location1/"
     }, {
         "signature": "container1:0.0.0.0:80:a.b.c:/location2/"
     }]
     handle_servername = ServerName(**{
         "domain": self.valid_domain,
     })
     for directive in directives:
         handle_servername.directives = directive
     self.assertTrue(handle_servername.is_valid)
     del handle_servername
 def test_directives_correct(self):
     """
     Tests that a ServerName object properly returns the directives that were assigned to it.
     """
     directives = [
                     { "signature" : "a:0.0.0.0:80:a.b.c:/"},
                     { "signature" : "a:0.0.0.0:8080:a.b.c:/"}
                     ]
     handle_servername = ServerName(**{
                                         "domain" : self.valid_domain,
                                     }
                                 )
     for directive in directives:
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.directives), 2)
     for directive, expected_directive in zip(handle_servername.directives, directives):
         self.assertEqual(directive, expected_directive)
     del handle_servername
 def test_build_correct_no_dupes(self):
     """
     Tests that the _build method properly generate a unique Location object if we try to
     resolve the same location twice.
     """
     handle_servername = ServerName(**{
                                         "domain" : self.valid_domain,
                                     }
                                 )
     location = "/"
     directives = [
                     { "signature" : "a:0.0.0.0:80:a.b.c.d:%s" % (location)},
                     { "signature" : "a:0.0.0.0:80:a.b.c.d:%s" % (location)},
                     ]
     for directive in directives:
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.locations.keys()), 1)
     self.assertEqual(list(handle_servername.locations.keys())[0], location)
     del handle_servername
 def test_directives_correct(self):
     """
     Tests that a ServerName object properly returns the directives that were assigned to it.
     """
     directives = [{
         "signature": "a:0.0.0.0:80:a.b.c:/"
     }, {
         "signature": "a:0.0.0.0:8080:a.b.c:/"
     }]
     handle_servername = ServerName(**{
         "domain": self.valid_domain,
     })
     for directive in directives:
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.directives), 2)
     for directive, expected_directive in zip(handle_servername.directives,
                                              directives):
         self.assertEqual(directive, expected_directive)
     del handle_servername
 def test_build_correct(self):
     """
     Tests that the _build method properly turns the directives into unique Location objects.
     """
     handle_servername = ServerName(**{
         "domain": self.valid_domain,
     })
     directives = [
         {
             "signature": "a:0.0.0.0:80:a.b.c.d:/"
         },
         {
             "signature": "a:0.0.0.0:80:a.b.c.d:/that_place/"
         },
     ]
     for directive in directives:
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.locations.keys()), 2)
     del handle_servername
 def test_build_correct_no_dupes(self):
     """
     Tests that the _build method properly generate a unique Location object if we try to
     resolve the same location twice.
     """
     handle_servername = ServerName(**{
         "domain": self.valid_domain,
     })
     location = "/"
     directives = [
         {
             "signature": "a:0.0.0.0:80:a.b.c.d:%s" % (location)
         },
         {
             "signature": "a:0.0.0.0:80:a.b.c.d:%s" % (location)
         },
     ]
     for directive in directives:
         handle_servername.directives = directive
     self.assertEqual(len(handle_servername.locations.keys()), 1)
     self.assertEqual(list(handle_servername.locations.keys())[0], location)
     del handle_servername