def create_org(namespace, owner): try: User.get(username=namespace) except User.DoesNotExist: organization.create_organization(namespace, "*****@*****.**" % str(uuid.uuid1()), owner)
def test_get_proxy_cache_config_for_org_without_proxy_config(initialized_db): test_org = "test" test_email = "*****@*****.**" user_obj = create_user_noverify(test_org, test_email) org = create_organization("foobar", "*****@*****.**", user_obj) get_proxy_cache_config_for_org(org.username)
def setup(self, app): self.user = get_user("devtable") self.org = create_organization(self.orgname, "{self.orgname}@devtable.com", self.user) self.org.save() self.config = create_proxy_cache_config( org_name=self.orgname, upstream_registry=self.upstream_registry, expiration_s=3600, )
def test_registry_proxy_model_init_only_query_db_once(initialized_db): orgname = "testorg" user = get_user("devtable") org = create_organization(orgname, "{self.orgname}@devtable.com", user) org.save() create_proxy_cache_config( org_name=orgname, upstream_registry="quay.io", expiration_s=3600, ) with assert_query_count(1): ProxyModel( orgname, "app-sre/ubi8-ubi", user, )
def test_remove_user_from_team(initialized_db): first_user = get_user("devtable") second_user = get_user("randomuser") # Create new org: devtable should be in the admin owners team new_org = create_organization("testorg", "testorg" + "@example.com", first_user) admin_teams = list(__get_user_admin_teams("testorg", "devtable")) # Add user to another admin team new_team = create_team("testteam", new_org, "admin", description="test another admin team") assert add_user_to_team(second_user, new_team) # Cannot remove themselves from their only admin team with pytest.raises(DataModelException): remove_user_from_team("testorg", "testteam", "randomuser", "randomuser") # Another admin should be able to remove_user_from_team("testorg", "testteam", "randomuser", "devtable")
def run_invite_flow(orgname): # Create an org owned by `devtable`. org = create_organization(orgname, orgname + "@example.com", first_user) # Create another team and add `devtable` to it. Since `devtable` is already # in the org, it should be done directly. other_team = create_team("otherteam", org, "admin") invite = add_or_invite_to_team(first_user, other_team, user_obj=first_user) assert invite is None assert is_in_team(other_team, first_user) # Try to add `newuser` to the team, which should require an invite. invite = add_or_invite_to_team(first_user, other_team, user_obj=second_user) assert invite is not None assert not is_in_team(other_team, second_user) # Accept the invite. confirm_team_invite(invite.invite_token, second_user) assert is_in_team(other_team, second_user)
def test_remove_team(initialized_db): first_user = get_user("devtable") # Create new org: devtable should be in the admin owners team new_org = create_organization("testorg", "testorg" + "@example.com", first_user) admin_teams = list(__get_user_admin_teams("testorg", "devtable")) assert len(admin_teams) == 1 and admin_teams[0].name == "owners" # Create new admin team without adding the devtable to the team: # devtable should be able to delete the new admin team new_team = create_team("testteam", new_org, "admin", description="test second admin team") admin_teams = list(__get_user_admin_teams("testorg", "devtable")) assert len(admin_teams) == 1 and admin_teams[0].name != "testteam" # Removing the only team which devtable is the admin to should fail with pytest.raises(DataModelException): remove_team("testorg", "owners", "devtable") # Removing the other admin team should succeed, since devtable is already admin in another team remove_team("testorg", "testteam", "devtable")
def create_org(user_name, user_email, org_name, org_email): user_obj = create_user_noverify(user_name, user_email) return create_organization(org_name, org_email, user_obj)