def test_directives_correct(self): """ Tests that an Nrt object properly returns the directives that were added to it. """ handle_nrt = Nrt(**{}) directives = [{"signature": "a:0.0.0.0:80:a.b.c:/"}, {"signature": "a:0.0.0.0:8080:a.b.c:/"}] for directive in directives: handle_nrt.directives = directive response = handle_nrt.directives for directive, expected_directive in zip(response, directives): self.assertEqual(directive, expected_directive) del handle_nrt
def test_build_correct_no_dupes(self): """ Tests that the _build method properly generate a unique Listen object if we try to resolve the same address twice but the directives per se are different. """ handle_nrt = Nrt(**{}) address = "0.0.0.0:80" directives = [{"signature": "a:%s:a.b.c:/" % (address)}, {"signature": "a:%s:aa.bb.cc:/" % (address)}] for directive in directives: handle_nrt.directives = directive self.assertEqual(len(handle_nrt.listen.keys()), 1) self.assertEqual(list(handle_nrt.listen.keys())[0], address) del handle_nrt
def test_is_valid_correct_invalid_location(self): """ Tests that the is_valid property correctly returns False if any of its Listen 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_nrt = Nrt(**{}) for directive in directives: handle_nrt.directives = directive self.assertFalse(handle_nrt.is_valid) del handle_nrt
def test_build_correct(self): """ Tests that the _build method properly turns the directives into unique Listen objects. """ handle_nrt = Nrt(**{}) directives = [ {"signature": "a:0.0.0.0:80:a.b.c:/"}, {"signature": "a:0.0.0.0:8080:a.b.c:/"}, {"signature": "a:0.0.0.0:80:a.b.c:/"}, ] for directive in directives: handle_nrt.directives = directive self.assertEqual(len(handle_nrt.listen.keys()), 2) del handle_nrt
def test_is_valid_correct(self): """ Tests that the is_valid property correctly returns True if all the ServerName objects associated to a Listen instance 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_nrt = Nrt(**{}) for directive in directives: handle_nrt.directives = directive self.assertTrue(handle_nrt.is_valid) del handle_nrt
def test_directives_correct_no_dupes(self): """ Tests that an Nrt object only stores a unique copy of directives having the same signature. """ handle_nrt = Nrt(**{}) directives = [ {"signature": "a:0.0.0.0:80:a.b.c:/"}, {"signature": "a:0.0.0.0:80:a.b.c:/"}, {"signature": "a:0.0.0.0:80:a.b.c:/"}, ] for directive in directives: handle_nrt.directives = directive response = handle_nrt.directives self.assertEqual(len(response), 1) del handle_nrt
def test_is_valid_correct_invalid_location(self): """ Tests that the is_valid property correctly returns False if any of its Listen 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_nrt = Nrt(**{}) for directive in directives: handle_nrt.directives = directive self.assertFalse(handle_nrt.is_valid) del handle_nrt
def test_is_valid_correct(self): """ Tests that the is_valid property correctly returns True if all the ServerName objects associated to a Listen instance 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_nrt = Nrt(**{}) for directive in directives: handle_nrt.directives = directive self.assertTrue(handle_nrt.is_valid) del handle_nrt
def test_directives_correct(self): """ Tests that an Nrt object properly returns the directives that were added to it. """ handle_nrt = Nrt(**{}) directives = [{ "signature": "a:0.0.0.0:80:a.b.c:/" }, { "signature": "a:0.0.0.0:8080:a.b.c:/" }] for directive in directives: handle_nrt.directives = directive response = handle_nrt.directives for directive, expected_directive in zip(response, directives): self.assertEqual(directive, expected_directive) del handle_nrt
def test_build_correct_no_dupes(self): """ Tests that the _build method properly generate a unique Listen object if we try to resolve the same address twice but the directives per se are different. """ handle_nrt = Nrt(**{}) address = "0.0.0.0:80" directives = [ { "signature": "a:%s:a.b.c:/" % (address) }, { "signature": "a:%s:aa.bb.cc:/" % (address) }, ] for directive in directives: handle_nrt.directives = directive self.assertEqual(len(handle_nrt.listen.keys()), 1) self.assertEqual(list(handle_nrt.listen.keys())[0], address) del handle_nrt
def test_build_correct(self): """ Tests that the _build method properly turns the directives into unique Listen objects. """ handle_nrt = Nrt(**{}) directives = [ { "signature": "a:0.0.0.0:80:a.b.c:/" }, { "signature": "a:0.0.0.0:8080:a.b.c:/" }, { "signature": "a:0.0.0.0:80:a.b.c:/" }, ] for directive in directives: handle_nrt.directives = directive self.assertEqual(len(handle_nrt.listen.keys()), 2) del handle_nrt
def test_directives_correct_no_dupes(self): """ Tests that an Nrt object only stores a unique copy of directives having the same signature. """ handle_nrt = Nrt(**{}) directives = [ { "signature": "a:0.0.0.0:80:a.b.c:/" }, { "signature": "a:0.0.0.0:80:a.b.c:/" }, { "signature": "a:0.0.0.0:80:a.b.c:/" }, ] for directive in directives: handle_nrt.directives = directive response = handle_nrt.directives self.assertEqual(len(response), 1) del handle_nrt