Create user when running unittest from UTF

Create user when running unittest from UTF

  

I'm trying to create a test user when I'm running an unittest in UTF, but the message I get when I execute User_Create is that I need the role of UserManager. 

But the user that is running the unittest has an user_id of 0, so updating the role of that user fails, because user 0 does not exists and I cannot create that user either, since I do not have UserManager role.

Does anybody know how I can solve the problem of not being able to create a user?

Hi,


you can simply grant the loggedinuser with the UserManagerRole.

Reference the role from Users-espace.

GrantUserManageRole()

(be careful with this of course)




Solution

Since UTF executes web services in runtime, there is no explicit user session, but you can programmatically login as one existing user.

First, setup a user and grant him the UserManager role (in the /Users app).

In runtime, use the User_Login public action from module Users to login as this user.

Then you should be able to programmatically create an additional user, as part of your test.

Solution

Paulo Ramos wrote:

Since UTF executes web services in runtime, there is no explicit user session, but you can programmatically login as one existing user.

First, setup a user and grant him the UserManager role (in the /Users app).

In runtime, use the User_Login public action from module Users to login as this user.

Then you should be able to programmatically create an additional user, as part of your test.

Paulo,

This recipe did the trick. I can now add additional test-users in my testcases. Thanks for the quick reply ;-)

Once you know how to do it, it's fairly easy (as most things in life).