Python hamcrest.is_() Examples
The following are 30
code examples of hamcrest.is_().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
hamcrest
, or try the search function
.
Example #1
Source File: switch_api_test.py From netman with Apache License 2.0 | 6 votes |
def test_raised_base_exceptions_are_marshalled_correctly(self): self.switch_factory.should_receive('get_switch').with_args('my.switch').and_return(self.switch_mock).once().ordered() self.switch_mock.should_receive('connect').once().ordered() self.switch_mock.should_receive('set_access_vlan').with_args('FastEthernet0/4', 1000).once().ordered() \ .and_raise(Exception("ERMAHGERD")) self.switch_mock.should_receive('disconnect').once().ordered() result, code = self.put("/switches/my.switch/interfaces/FastEthernet0/4/access-vlan", fixture="put_switch_hostname_interfaces_intname_accessvlan.txt", headers={"Netman-Verbose-Errors": "yes"}) assert_that(code, is_(500)) assert_that(result, is_({ "error": "ERMAHGERD", "error-class": "Exception", }))
Example #2
Source File: switch_api_test.py From netman with Apache License 2.0 | 6 votes |
def test_raised_exceptions_are_marshalled_correctly(self): self.switch_factory.should_receive('get_switch').with_args('my.switch').and_return(self.switch_mock).once().ordered() self.switch_mock.should_receive('connect').once().ordered() self.switch_mock.should_receive('set_access_vlan').with_args('FastEthernet0/4', 1000).once().ordered() \ .and_raise(UnknownInterface("SHIZZLE")) self.switch_mock.should_receive('disconnect').once().ordered() result, code = self.put("/switches/my.switch/interfaces/FastEthernet0/4/access-vlan", fixture="put_switch_hostname_interfaces_intname_accessvlan.txt", headers={"Netman-Verbose-Errors": "yes"}) assert_that(code, is_(404)) assert_that(result, is_({ "error": "Unknown interface SHIZZLE", "error-module": UnknownInterface.__module__, "error-class": UnknownInterface.__name__, }))
Example #3
Source File: brocade_test.py From netman with Apache License 2.0 | 6 votes |
def test_get_vlan_with_an_empty_interface(self): self.shell_mock.should_receive("do").with_args("show vlan 1750").once().ordered().and_return( vlan_with_vif_display(1750, 999, name="Shizzle") ) self.shell_mock.should_receive("do").with_args("show running-config interface ve 999").once().ordered().and_return([ "interface ve 999", "!", ]) vlan = self.switch.get_vlan(1750) assert_that(vlan.number, is_(1750)) assert_that(vlan.name, is_("Shizzle")) assert_that(vlan.access_groups[IN], is_(none())) assert_that(vlan.access_groups[OUT], is_(none())) assert_that(vlan.vrf_forwarding, is_(none())) assert_that(vlan.ips, is_(empty())) assert_that(vlan.vrrp_groups, is_(empty())) assert_that(vlan.dhcp_relay_servers, is_(empty()))
Example #4
Source File: switch_api_test.py From netman with Apache License 2.0 | 6 votes |
def test_raised_not_implemented_error_are_marshalled_correctly(self): self.switch_factory.should_receive('get_switch').with_args('my.switch').and_return(self.switch_mock).once().ordered() self.switch_mock.should_receive('connect').once().ordered() self.switch_mock.should_receive('set_access_vlan').with_args('FastEthernet0/4', 1000).once().ordered() \ .and_raise(NotImplementedError()) self.switch_mock.should_receive('disconnect').once().ordered() result, code = self.put("/switches/my.switch/interfaces/FastEthernet0/4/access-vlan", fixture="put_switch_hostname_interfaces_intname_accessvlan.txt", headers={"Netman-Verbose-Errors": "yes"}) assert_that(code, is_(501)) assert_that(result, is_({ "error": "", "error-class": "NotImplementedError", }))
Example #5
Source File: cached_switch_test.py From netman with Apache License 2.0 | 6 votes |
def test_after_get_vlans_was_cached_adding_new_vlans_will_trigger_single_get_vlans_to_fill_the_gaps(self): all_vlans = [Vlan(1)] self.real_switch_mock.should_receive("get_vlans").once().ordered().and_return(all_vlans) assert_that(self.switch.get_vlans(), is_(all_vlans)) self.real_switch_mock.should_receive("add_vlan").once().with_args(10) self.switch.add_vlan(10) self.real_switch_mock.should_receive("add_vlan").once().with_args(11) self.switch.add_vlan(11) self.real_switch_mock.should_receive("add_vlan").once().with_args(12) self.switch.add_vlan(12) self.real_switch_mock.should_receive("get_vlan").with_args(10).once().and_return(Vlan(10)) self.real_switch_mock.should_receive("get_vlan").with_args(11).once().and_return(Vlan(11)) self.real_switch_mock.should_receive("get_vlan").with_args(12).once().and_return(Vlan(12)) assert_that(self.switch.get_vlans(), is_([Vlan(1), Vlan(10), Vlan(11), Vlan(12)])) assert_that(self.switch.get_vlans(), is_([Vlan(1), Vlan(10), Vlan(11), Vlan(12)]))
Example #6
Source File: get_interface_test.py From netman with Apache License 2.0 | 6 votes |
def test_get_interface_and_get_interfaces_are_same(self): self.client.add_vlan(1000, name="vlan1000") self.client.add_vlan(2000, name="vlan2000") expected = self.test_ports[0] self.try_to.set_access_vlan(expected.name, 1000) self.try_to.set_trunk_mode(expected.name) self.try_to.set_interface_state(expected.name, ON) self.try_to.set_interface_native_vlan(expected.name, 2000) self.try_to.set_interface_auto_negotiation_state(expected.name, ON) self.try_to.set_interface_mtu(expected.name, 5000) interface_from_single = self.client.get_interface(expected.name) interfaces = [inte for inte in self.client.get_interfaces() if inte.name == expected.name] interface_from_multiple = interfaces[0] assert_that(interface_from_single.name, is_(interface_from_multiple.name)) assert_that(interface_from_single.port_mode, is_(interface_from_multiple.port_mode)) assert_that(interface_from_single.shutdown, is_(interface_from_multiple.shutdown)) assert_that(interface_from_single.trunk_native_vlan, is_(interface_from_multiple.trunk_native_vlan)) assert_that(interface_from_single.trunk_vlans, is_(interface_from_multiple.trunk_vlans)) assert_that(interface_from_single.auto_negotiation, is_(interface_from_multiple.auto_negotiation)) assert_that(interface_from_single.mtu, is_(interface_from_multiple.mtu))
Example #7
Source File: add_interface_to_bond_test.py From netman with Apache License 2.0 | 5 votes |
def test_resets_the_interface_access_vlan(self): self.client.add_vlan(90) self.client.set_access_mode(self.test_port) self.client.set_access_vlan(self.test_port, 90) self.client.add_interface_to_bond(self.test_port, 42) interface = self.client.get_interface(self.test_port) assert_that(interface.access_vlan, is_(none())) self.janitor.remove_vlan(90)
Example #8
Source File: add_interface_to_bond_test.py From netman with Apache License 2.0 | 5 votes |
def test_sets_the_interface_port_mode_to_bond_members(self): self.client.add_interface_to_bond(self.test_port, 42) interface = self.client.get_interface(self.test_port) assert_that(interface.port_mode, is_(BOND_MEMBER)) self.janitor.remove_interface_from_bond(self.test_port)
Example #9
Source File: add_interface_to_bond_test.py From netman with Apache License 2.0 | 5 votes |
def test_resets_the_interface_trunk_vlans(self): self.client.add_vlan(90) self.client.set_trunk_mode(self.test_port) self.client.add_trunk_vlan(self.test_port, 90) self.client.add_interface_to_bond(self.test_port, 42) interface = self.client.get_interface(self.test_port) assert_that(interface.trunk_vlans, is_(empty())) self.janitor.remove_vlan(90) self.janitor.remove_interface_from_bond(self.test_port) self.janitor.set_access_mode(self.test_port)
Example #10
Source File: add_interface_to_bond_test.py From netman with Apache License 2.0 | 5 votes |
def test_resets_the_interface_trunk_native_vlan(self): self.client.add_vlan(90) self.client.set_trunk_mode(self.test_port) self.client.set_interface_native_vlan(self.test_port, 90) self.client.add_interface_to_bond(self.test_port, 42) interface = self.client.get_interface(self.test_port) assert_that(interface.trunk_native_vlan, is_(none())) self.janitor.remove_vlan(90) self.janitor.remove_interface_from_bond(self.test_port) self.janitor.set_access_mode(self.test_port)
Example #11
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_unset_interface_access_vlan(self): self.real_switch_mock.should_receive("get_interfaces").once().and_return( [Interface('eth0', access_vlan=123)]) self.switch.get_interfaces() self.real_switch_mock.should_receive("unset_interface_access_vlan").once() \ .with_args('eth0') self.switch.unset_interface_access_vlan('eth0') assert_that( self.switch.get_interfaces(), is_([Interface('eth0')]) )
Example #12
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_remove_vlan(self): self.real_switch_mock.should_receive("get_vlans").once().and_return( [Vlan(1), Vlan(2)]) self.switch.get_vlans() self.real_switch_mock.should_receive("remove_vlan").once().with_args(1) self.switch.remove_vlan(1) assert_that(self.switch.get_vlans(), is_([Vlan(2)]))
Example #13
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_access_new_vlan_after_vlan_list(self): all_vlans = [Vlan(1, 'first'), Vlan(2, 'second')] vlan3 = Vlan(3, 'third', ips=[IPNetwork("2.2.2.2/24")]) self.real_switch_mock.should_receive("get_vlans").once().and_return(all_vlans) self.real_switch_mock.should_receive("add_ip_to_vlan").once().with_args(3, ExactIpNetwork("2.2.2.2/24")) self.real_switch_mock.should_receive("get_vlan").with_args(3).once().and_return(vlan3) assert_that(self.switch.get_vlans(), is_(all_vlans)) self.switch.add_ip_to_vlan(3, IPNetwork("2.2.2.2/24")) assert_that(self.switch.get_vlan(3), is_(vlan3))
Example #14
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_get_vlans(self): all_vlans = [Vlan(1, 'first'), Vlan(2, 'second')] self.real_switch_mock.should_receive("get_vlans").once().and_return( all_vlans) assert_that(self.switch.get_vlans(), is_(all_vlans)) assert_that(self.switch.get_vlans(), is_(all_vlans))
Example #15
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_add_vlan_first(self): all_vlans = [Vlan(1), Vlan(2), Vlan(123, name='allo')] self.real_switch_mock.should_receive("add_vlan").once().with_args(123, name='allo') self.switch.add_vlan(123, 'allo') self.real_switch_mock.should_receive("get_vlans").once().and_return( all_vlans) assert_that(self.switch.get_vlans(), is_(all_vlans)) assert_that(self.switch.get_vlans(), is_(all_vlans))
Example #16
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_add_vlan_after_get_vlans(self): all_vlans = [Vlan(1), Vlan(2)] self.real_switch_mock.should_receive("get_vlans").once().ordered().and_return( all_vlans) assert_that(self.switch.get_vlans(), is_(all_vlans)) assert_that(self.switch.get_vlans(), is_(all_vlans)) self.real_switch_mock.should_receive("add_vlan").once().with_args(123, name='allo') self.switch.add_vlan(123, 'allo') self.real_switch_mock.should_receive("get_vlan").once().ordered().and_return(Vlan(123, name='allo')) assert_that(self.switch.get_vlans(), is_(all_vlans+[Vlan(123, name='allo')])) assert_that(self.switch.get_vlans(), is_(all_vlans+[Vlan(123, name='allo')]))
Example #17
Source File: cached_switch_test.py From netman with Apache License 2.0 | 5 votes |
def test_get_interface(self): interface = Interface('xe-1/0/1') self.real_switch_mock.should_receive("get_interface").with_args("xe-1/0/1").once() \ .and_return(interface) assert_that(self.switch.get_interface('xe-1/0/1'), is_(interface)) assert_that(self.switch.get_interface('xe-1/0/1'), is_(interface))
Example #18
Source File: brocade_test.py From netman with Apache License 2.0 | 5 votes |
def test_switch_has_a_logger_configured_with_the_switch_name(self): assert_that(self.switch.logger.name, is_(Brocade.__module__ + ".my.hostname"))
Example #19
Source File: remove_ip_from_vlan_test.py From netman with Apache License 2.0 | 5 votes |
def test_unassigns(self): self.client.remove_ip_from_vlan(1000, IPNetwork("10.10.10.2/29")) assert_that(self.client.get_vlan(1000).ips, is_(empty()))
Example #20
Source File: set_vlan_mpls_ip_test.py From netman with Apache License 2.0 | 5 votes |
def test_sets_mpls_ip_state_false_for_the_vlan(self): self.client.add_vlan(1000) self.client.set_vlan_mpls_ip_state(1000, False) vlan = self.client.get_vlan(1000) assert_that(vlan.mpls_ip, is_(False))
Example #21
Source File: get_interface_test.py From netman with Apache License 2.0 | 5 votes |
def test_returns_an_interface(self): interface = self.client.get_interface(self.test_ports[0].name) assert_that(interface.name, is_(self.test_ports[0].name))
Example #22
Source File: get_vlan_test.py From netman with Apache License 2.0 | 5 votes |
def test_returns_a_vlan_with_all_available_data(self): self.client.add_vlan(1000, name="vlan_name") self.try_to.set_vlan_vrf(1000, "DEFAULT-LAN") self.try_to.add_ip_to_vlan(1000, IPNetwork("10.10.10.2/29")) self.try_to.set_vlan_access_group(1000, IN, "ACL-IN") self.try_to.set_vlan_access_group(1000, OUT, "ACL-OUT") self.try_to.add_vrrp_group(1000, 1, ips=[IPAddress("10.10.10.1")], priority=110, hello_interval=10, dead_interval=11, track_id=self.test_vrrp_track_id, track_decrement=50) self.try_to.add_dhcp_relay_server(1000, IPAddress("11.11.11.1")) self.try_to.set_vlan_icmp_redirects_state(1000, False) assert_that(self.client.get_vlan(1000), is_(self.get_vlan_from_list(1000)))
Example #23
Source File: set_interface_auto_negotiation_state_test.py From netman with Apache License 2.0 | 5 votes |
def test_can_activate_the_auto_negotiation(self): self.client.set_interface_auto_negotiation_state(self.test_port, state=ON) interface = self.client.get_interface(self.test_port) assert_that(interface.auto_negotiation, is_(True))
Example #24
Source File: set_vlan_unicast_rpf_mode_test.py From netman with Apache License 2.0 | 5 votes |
def test_can_activate_the_strict_unicast_anti_spoofing(self): self.client.set_vlan_unicast_rpf_mode(1000, STRICT) vlan = self.get_vlan_from_list(1000) assert_that(vlan.unicast_rpf_mode, is_(STRICT))
Example #25
Source File: set_vlan_ntp_state.py From netman with Apache License 2.0 | 5 votes |
def test_enables_ntp_when_given_true(self): self.try_to.set_vlan_ntp_state(2999, True) vlan = self.get_vlan_from_list(2999) assert_that(vlan.ntp, is_(True))
Example #26
Source File: set_vlan_ntp_state.py From netman with Apache License 2.0 | 5 votes |
def test_disables_ntp_when_given_false(self): self.try_to.set_vlan_ntp_state(2999, False) vlan = self.get_vlan_from_list(2999) assert_that(vlan.ntp, is_(False))
Example #27
Source File: add_vlan_test.py From netman with Apache License 2.0 | 5 votes |
def test_sets_the_name_when_given(self): self.client.add_vlan(1000, name="Hey") vlan = self.get_vlan_from_list(1000) assert_that(vlan.name, is_("Hey"))
Example #28
Source File: unset_vlan_load_interval_test.py From netman with Apache License 2.0 | 5 votes |
def test_unset_load_interval_from_the_vlan(self): self.client.add_vlan(1000) self.try_to.set_vlan_load_interval(1000, 30) self.client.unset_vlan_load_interval(1000) vlan = self.client.get_vlan(1000) assert_that(vlan.load_interval, is_(None))
Example #29
Source File: add_bond_test.py From netman with Apache License 2.0 | 5 votes |
def test_creates_the_bond(self): self.client.add_bond(42) bond_from_get_bond = self.client.get_bond(42) assert_that(bond_from_get_bond.number, is_(42)) self.janitor.remove_bond(42)
Example #30
Source File: add_varp_ip_to_vlan_test.py From netman with Apache License 2.0 | 5 votes |
def test_assigns_the_varp_ip(self): self.client.add_vlan_varp_ip(1000, IPNetwork("10.10.40.2/29")) assert_that(self.client.get_vlan(1000).varp_ips, is_([IPNetwork("10.10.40.2/29")]))