def test_find_vlans_in_org_one_child(self): """Should return all vlans in this org and child org""" self.assertEqual( sorted(find_vlans_in_org(self.org2)), sorted( [FantasyVlan(self.vlan3.vlan), FantasyVlan(self.vlan2.vlan)]))
def test_find_vlans_in_org_filter_nonevalues(self): """Should filter vlans with no vlan value""" self.vlan1.vlan = None self.assertEqual( sorted(find_vlans_in_org(self.org1)), sorted( [FantasyVlan(self.vlan3.vlan), FantasyVlan(self.vlan2.vlan)]))
def test_find_vlans_in_org_two_children(self): """Should return all vlans in this org and all children orgs""" self.assertEqual( sorted(find_vlans_in_org(self.org1)), sorted([ FantasyVlan(self.vlan3.vlan), FantasyVlan(self.vlan2.vlan), FantasyVlan(self.vlan1.vlan) ]))
def test_find_vlans_in_org_no_duplicates(self): """Should filter duplicates""" self.org3.vlan_set.all.return_value = [self.vlan3, self.vlan2] self.assertEqual( sorted(find_vlans_in_org(self.org1)), sorted([ FantasyVlan(self.vlan3.vlan), FantasyVlan(self.vlan2.vlan), FantasyVlan(self.vlan1.vlan) ]))
def test_find_allowed_vlans_for_user(self): """Should return all vlans for this users org and child orgs""" account = Mock() account.organizations.all.return_value = [self.org1] self.assertEqual( sorted(find_allowed_vlans_for_user(account)), sorted([ FantasyVlan(self.vlan1.vlan), FantasyVlan(self.vlan2.vlan), FantasyVlan(self.vlan3.vlan) ]))
def find_vlans_in_org(org): """Find all vlans in an organization and child organizations :returns: list of FantasyVlans :rtype: list """ vlans = list(org.vlan_set.all()) for child_org in org.organization_set.all(): vlans.extend(find_vlans_in_org(child_org)) return [FantasyVlan(x.vlan, x.net_ident) for x in list(set(vlans)) if x.vlan]
def find_default_vlan(include_netident=False): """Check config to see if a default vlan is set :rtype: FantasyVlan """ defaultvlan = "" netident = "" config = read_config() if config.has_section("defaultvlan"): if config.has_option("defaultvlan", "vlan"): defaultvlan = config.getint("defaultvlan", "vlan") if config.has_option("defaultvlan", "netident"): netident = config.get("defaultvlan", "netident") if defaultvlan: if include_netident: return FantasyVlan(defaultvlan, netident) else: return FantasyVlan(defaultvlan)
def test_find_vlans_in_org_no_children(self): """Should return all vlans in this org""" self.assertEqual(find_vlans_in_org(self.org3), [FantasyVlan(self.vlan3.vlan)])