def test_api_invite_existing_user(client, outbox):
 user = f.UserFactory.create()
 role = f.RoleFactory.create()
 f.MembershipFactory(project=role.project, user=role.project.owner, is_admin=True)
 client.login(role.project.owner)
 url = reverse('memberships-list')
 data = {'role': role.pk, 'project': role.project.pk, 'username': user.email}
 response = client.json.post(url, json.dumps(data))
 assert (response.status_code == 201), response.data
 assert (len(outbox) == 1)
 assert (user.memberships.count() == 1)
 message = outbox[0]
 assert (message.to == [user.email])
 assert ('Added to the project' in message.subject)

def test_api_invite_existing_user ( client , outbox ) : user = f . UserFactory . create ( ) role = f . RoleFactory . create ( ) f . MembershipFactory ( project = role . project , user = role . project . owner , is_admin = True ) client . login ( role . project . owner ) url = reverse ( 'memberships-list' ) data = { 'role' : role . pk , 'project' : role . project . pk , 'username' : user . email } response = client . json . post ( url , json . dumps ( data ) ) assert ( response . status_code == 201 ) , response . data assert ( len ( outbox ) == 1 ) assert ( user . memberships . count ( ) == 1 ) message = outbox [ 0 ] assert ( message . to == [ user . email ] ) assert ( 'Added to the project' in message . subject )
should create the invitation linked to that user .