SHARE
TWEET

Untitled

a guest Oct 17th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import unittest
  2. import types
  3. from config_service.api.v1.resources.appilcations_rules.application_rules_utils import random_available_ports
  4.  
  5.  
  6. class TestSplitPorts(unittest.TestCase):
  7.     def setUp(self) -> None:
  8.         # Given
  9.         self.exclude_ports = [1024, 1025, 1027, 1035, 1050, 1027]
  10.         self.start_port = 1024
  11.         self.end_port = 1060
  12.  
  13.     def tearDown(self) -> None:
  14.         pass
  15.  
  16.     def test_random_available_ports_returns_generator(self):
  17.         # When
  18.         available_ports = random_available_ports(self.start_port, self.end_port, self.exclude_ports)
  19.         # Then
  20.         self.assertIsInstance(available_ports, types.GeneratorType)
  21.  
  22.     def test_random_available_ports_doesnt_return_excluded_port(self):
  23.         # Given
  24.         start_port = 1024  # shadows self.start_port
  25.         end_port = 1074  # shadows self.end_port
  26.         # When
  27.         available_ports = list(random_available_ports(start_port, end_port, self.exclude_ports))
  28.         # Then
  29.         self.assertNotIn(self.exclude_ports, available_ports)
  30.  
  31.     def test_random_available_ports_generates_next_available_port(self):
  32.         available_ports = random_available_ports(self.start_port, self.end_port, self.exclude_ports)
  33.         self.assertEqual(next(available_ports), 1026)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top