Acceptance tests: Add a helper method to renew the request context
Renewing the request context is e.g. needed for email tests, because the IdentifiedUser caches the email addresses and needs to be recreated if new emails were added. Change-Id: Ib5699baab32febe62e904b65ee02c25f23c17a7c Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -696,6 +696,16 @@ public abstract class AbstractDaemonTest {
|
||||
identifiedUserFactory.create(account.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforce a new request context for the current API user.
|
||||
*
|
||||
* <p>This recreates the IdentifiedUser, hence everything which is cached in the IdentifiedUser is
|
||||
* reloaded (e.g. the email addresses of the user).
|
||||
*/
|
||||
protected Context resetCurrentApiUser() {
|
||||
return atrScope.set(newRequestContext(atrScope.get().getSession().getAccount()));
|
||||
}
|
||||
|
||||
protected Context setApiUser(TestAccount account) {
|
||||
return atrScope.set(newRequestContext(account));
|
||||
}
|
||||
|
||||
@@ -111,4 +111,8 @@ public class SshSession {
|
||||
b.append(session.getPort());
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public TestAccount getAccount() {
|
||||
return account;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,9 +386,7 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
gApi.accounts().self().addEmail(input);
|
||||
}
|
||||
|
||||
// enforce a new request context so that emails that are cached in
|
||||
// IdentifiedUser are reloaded
|
||||
setApiUser(admin);
|
||||
resetCurrentApiUser();
|
||||
assertThat(getEmails()).containsAllIn(emails);
|
||||
}
|
||||
|
||||
@@ -428,16 +426,12 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
input.noConfirmation = true;
|
||||
gApi.accounts().self().addEmail(input);
|
||||
|
||||
// enforce a new request context so that emails that are cached in
|
||||
// IdentifiedUser are reloaded
|
||||
setApiUser(admin);
|
||||
resetCurrentApiUser();
|
||||
assertThat(getEmails()).contains(email);
|
||||
|
||||
gApi.accounts().self().deleteEmail(input.email);
|
||||
|
||||
// enforce a new request context so that emails that are cached in
|
||||
// IdentifiedUser are reloaded
|
||||
setApiUser(admin);
|
||||
resetCurrentApiUser();
|
||||
assertThat(getEmails()).doesNotContain(email);
|
||||
}
|
||||
|
||||
@@ -456,16 +450,12 @@ public class AccountIT extends AbstractDaemonTest {
|
||||
gApi.accounts().self().getExternalIds().stream().map(e -> e.identity).collect(toSet()))
|
||||
.containsAllOf(extId1, extId2);
|
||||
|
||||
// enforce a new request context so that emails that are cached in
|
||||
// IdentifiedUser are reloaded
|
||||
setApiUser(admin);
|
||||
resetCurrentApiUser();
|
||||
assertThat(getEmails()).contains(email);
|
||||
|
||||
gApi.accounts().self().deleteEmail(email);
|
||||
|
||||
// enforce a new request context so that emails that are cached in
|
||||
// IdentifiedUser are reloaded
|
||||
setApiUser(admin);
|
||||
resetCurrentApiUser();
|
||||
assertThat(getEmails()).doesNotContain(email);
|
||||
assertThat(
|
||||
gApi.accounts().self().getExternalIds().stream().map(e -> e.identity).collect(toSet()))
|
||||
|
||||
Reference in New Issue
Block a user