@@ -33,7 +33,7 @@ def test_bound_network_init(self, network_response):
3333
3434 assert len (bound_network .subnets ) == 2
3535 assert isinstance (bound_network .subnets [0 ], NetworkSubnet )
36- assert bound_network .subnets [0 ].type == "cloud"
36+ assert bound_network .subnets [0 ].type == NetworkSubnet . TYPE_CLOUD
3737 assert bound_network .subnets [0 ].ip_range == "10.0.1.0/24"
3838 assert bound_network .subnets [0 ].network_zone == "eu-central"
3939 assert bound_network .subnets [0 ].gateway == "10.0.0.1"
@@ -80,10 +80,10 @@ def test_change_protection(self, hetzner_client, bound_network, generic_action):
8080
8181 def test_add_subnet (self , hetzner_client , bound_network , generic_action ):
8282 hetzner_client .request .return_value = generic_action
83- subnet = NetworkSubnet (type = "cloud" , ip_range = "10.0.1.0/24" , network_zone = "eu-central" )
83+ subnet = NetworkSubnet (type = NetworkSubnet . TYPE_CLOUD , ip_range = "10.0.1.0/24" , network_zone = "eu-central" )
8484 action = bound_network .add_subnet (subnet )
8585 hetzner_client .request .assert_called_with (url = "/networks/14/actions/add_subnet" , method = "POST" ,
86- json = {"type" : "cloud" , "ip_range" : "10.0.1.0/24" ,
86+ json = {"type" : NetworkSubnet . TYPE_CLOUD , "ip_range" : "10.0.1.0/24" ,
8787 "network_zone" : "eu-central" })
8888
8989 assert action .id == 1
@@ -137,7 +137,11 @@ def networks_client(self):
137137
138138 @pytest .fixture ()
139139 def network_subnet (self ):
140- return NetworkSubnet (type = "cloud" , ip_range = "10.0.1.0/24" , network_zone = "eu-central" )
140+ return NetworkSubnet (type = NetworkSubnet .TYPE_CLOUD , ip_range = "10.0.1.0/24" , network_zone = "eu-central" )
141+
142+ @pytest .fixture ()
143+ def network_vswitch_subnet (self ):
144+ return NetworkSubnet (type = NetworkSubnet .TYPE_VSWITCH , ip_range = "10.0.1.0/24" , network_zone = "eu-central" , vswitch_id = 123 )
141145
142146 @pytest .fixture ()
143147 def network_route (self ):
@@ -244,7 +248,7 @@ def test_create_with_subnet(self, networks_client, network_subnet, network_creat
244248 'ip_range' : "10.0.0.0/8" ,
245249 'subnets' : [
246250 {
247- 'type' : "cloud" ,
251+ 'type' : NetworkSubnet . TYPE_CLOUD ,
248252 'ip_range' : "10.0.1.0/24" ,
249253 'network_zone' : "eu-central"
250254 }
@@ -291,7 +295,7 @@ def test_create_with_route_and_subnet(self, networks_client, network_subnet, net
291295 'ip_range' : "10.0.0.0/8" ,
292296 'subnets' : [
293297 {
294- 'type' : "cloud" ,
298+ 'type' : NetworkSubnet . TYPE_CLOUD ,
295299 'ip_range' : "10.0.1.0/24" ,
296300 'network_zone' : "eu-central"
297301 }
@@ -353,12 +357,24 @@ def test_add_subnet(self, networks_client, network, generic_action, network_subn
353357
354358 action = networks_client .add_subnet (network , network_subnet )
355359 networks_client ._client .request .assert_called_with (url = "/networks/1/actions/add_subnet" , method = "POST" ,
356- json = {"type" : "cloud" , "ip_range" : "10.0.1.0/24" ,
360+ json = {"type" : NetworkSubnet . TYPE_CLOUD , "ip_range" : "10.0.1.0/24" ,
357361 "network_zone" : "eu-central" })
358362
359363 assert action .id == 1
360364 assert action .progress == 0
361365
366+ @pytest .mark .parametrize ("network" , [Network (id = 1 ), BoundNetwork (mock .MagicMock (), dict (id = 1 ))])
367+ def test_add_subnet_vswitch (self , networks_client , network , generic_action , network_vswitch_subnet ):
368+ networks_client ._client .request .return_value = generic_action
369+
370+ action = networks_client .add_subnet (network , network_vswitch_subnet )
371+ networks_client ._client .request .assert_called_with (url = "/networks/1/actions/add_subnet" , method = "POST" ,
372+ json = {"type" : NetworkSubnet .TYPE_VSWITCH , "ip_range" : "10.0.1.0/24" ,
373+ "network_zone" : "eu-central" , "vswitch_id" : 123 })
374+
375+ assert action .id == 1
376+ assert action .progress == 0
377+
362378 @pytest .mark .parametrize ("network" , [Network (id = 1 ), BoundNetwork (mock .MagicMock (), dict (id = 1 ))])
363379 def test_delete_subnet (self , networks_client , network , generic_action , network_subnet ):
364380 networks_client ._client .request .return_value = generic_action
0 commit comments