MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / test_update_org

Function test_update_org

app/api/tests/opsboard/views/test_orgs.py:122–162  ·  view source on GitHub ↗

Test updating an organization's name.

(mock_request, orm_session, test_user)

Source from the content-addressed store, hash-verified

120
121@pytest.mark.asyncio
122async def test_update_org(mock_request, orm_session, test_user):
123 """Test updating an organization's name."""
124 # Create a fresh organization for this test
125 org = OrgModel(
126 name="Original Org Name",
127 prem_status=PremStatus.free,
128 )
129 orm_session.add(org)
130 orm_session.flush()
131
132 # Create a user-org relationship
133 user_id = mock_request.state.session.user_id
134 user_org = UserOrgModel(
135 user_id=user_id, org_id=org.id, role=OrgRoles.owner, user_email="test@example.com"
136 )
137 orm_session.add(user_org)
138 orm_session.commit() # Commit to ensure it's persisted
139
140 # Create the update body
141 body = OrgUpdateSchema(name="Updated Organization Name")
142
143 # Fetch org again with relationships to ensure we have the latest
144 org = orm_session.query(OrgModel).options(orm.selectinload(OrgModel.users)).filter_by(id=org.id).one()
145
146 # Verify the user is an owner of this org
147 membership = org.get_user_membership(user_id)
148 assert membership is not None, "User membership not found"
149 assert membership.role == OrgRoles.owner, "User is not an owner"
150
151 # Now call the update endpoint
152 result = update_org(request=mock_request, org_id=str(org.id), orm=orm_session, body=body)
153
154 # Verify the updates were applied
155 assert result.name == body.name
156
157 # Refresh the session to get the latest data
158 orm_session.expire_all() # Clear cached objects
159
160 # Verify the database was updated
161 updated_org = orm_session.query(OrgModel).filter_by(id=org.id).one()
162 assert updated_org.name == body.name
163
164
165@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 5

get_user_membershipMethod · 0.95
OrgModelClass · 0.90
UserOrgModelClass · 0.90
OrgUpdateSchemaClass · 0.90
update_orgFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…