-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5779d2f
commit 1806d00
Showing
9 changed files
with
141 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package teammates.it.ui.webapi; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
|
@@ -13,7 +15,6 @@ | |
import teammates.common.util.HibernateUtil; | ||
import teammates.common.util.StringHelperExtension; | ||
import teammates.storage.sqlentity.AccountRequest; | ||
import teammates.storage.sqlentity.Course; | ||
import teammates.ui.output.AccountRequestData; | ||
import teammates.ui.request.AccountRequestUpdateRequest; | ||
import teammates.ui.request.InvalidHttpRequestBodyException; | ||
|
@@ -30,9 +31,7 @@ public class UpdateAccountRequestActionIT extends BaseActionIT<UpdateAccountRequ | |
@Override | ||
@BeforeMethod | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
persistDataBundle(typicalBundle); | ||
HibernateUtil.flushSession(); | ||
// no need to call super.setUp() because the action is wrapped in a transaction | ||
} | ||
|
||
@Override | ||
|
@@ -49,8 +48,8 @@ protected String getRequestMethod() { | |
@Test | ||
public void testExecute() throws Exception { | ||
______TS("edit fields of an account request"); | ||
AccountRequest accountRequest = typicalBundle.accountRequests.get("unregisteredInstructor1"); | ||
accountRequest.setStatus(AccountRequestStatus.PENDING); | ||
AccountRequest accountRequest = logic.createAccountRequestWithTransaction("name", "[email protected]", | ||
"institute", AccountRequestStatus.PENDING, "comments"); | ||
UUID id = accountRequest.getId(); | ||
String name = "newName"; | ||
String email = "[email protected]"; | ||
|
@@ -75,8 +74,8 @@ public void testExecute() throws Exception { | |
verifyNoEmailsSent(); | ||
|
||
______TS("approve a pending account request"); | ||
accountRequest = typicalBundle.accountRequests.get("unregisteredInstructor2"); | ||
accountRequest.setStatus(AccountRequestStatus.PENDING); | ||
accountRequest = logic.createAccountRequestWithTransaction("name", "[email protected]", | ||
"institute", AccountRequestStatus.PENDING, "comments"); | ||
requestBody = new AccountRequestUpdateRequest(accountRequest.getName(), accountRequest.getEmail(), | ||
accountRequest.getInstitute(), AccountRequestStatus.APPROVED, accountRequest.getComments()); | ||
params = new String[] {Const.ParamsNames.ACCOUNT_REQUEST_ID, accountRequest.getId().toString()}; | ||
|
@@ -92,7 +91,8 @@ public void testExecute() throws Exception { | |
verifyNumberOfEmailsSent(1); | ||
|
||
______TS("already registered account request has no email sent when approved"); | ||
accountRequest = typicalBundle.accountRequests.get("instructor2"); | ||
accountRequest = logic.createAccountRequestWithTransaction("name", "[email protected]", | ||
"institute", AccountRequestStatus.REGISTERED, "comments"); | ||
requestBody = new AccountRequestUpdateRequest(name, email, institute, AccountRequestStatus.APPROVED, comments); | ||
params = new String[] {Const.ParamsNames.ACCOUNT_REQUEST_ID, accountRequest.getId().toString()}; | ||
|
||
|
@@ -127,7 +127,8 @@ public void testExecute() throws Exception { | |
assertEquals("Invalid UUID string: invalid", ihpe.getMessage()); | ||
|
||
______TS("invalid email"); | ||
accountRequest = typicalBundle.accountRequests.get("unregisteredInstructor1"); | ||
accountRequest = logic.createAccountRequestWithTransaction("name", "[email protected]", | ||
"institute", AccountRequestStatus.PENDING, "comments"); | ||
id = accountRequest.getId(); | ||
email = "newEmail"; | ||
status = accountRequest.getStatus(); | ||
|
@@ -217,7 +218,29 @@ public void testExecute() throws Exception { | |
@Override | ||
@Test | ||
protected void testAccessControl() throws InvalidParametersException, EntityAlreadyExistsException { | ||
Course course = typicalBundle.courses.get("course1"); | ||
verifyOnlyAdminCanAccess(course); | ||
// TODO: find a way to test this in its own transaction | ||
// HibernateUtil.beginTransaction(); | ||
// Course course = typicalBundle.courses.get("course1"); | ||
// course = logic.createCourse(course); | ||
// verifyOnlyAdminCanAccess(course); | ||
// verifyInaccessibleWithoutLogin(); | ||
// verifyInaccessibleForUnregisteredUsers(); | ||
// verifyInaccessibleForStudents(course); | ||
// verifyInaccessibleForInstructors(course); | ||
// verifyAccessibleForAdmin(); | ||
// HibernateUtil.rollbackTransaction(); | ||
} | ||
|
||
@Override | ||
@AfterMethod | ||
protected void tearDown() { | ||
HibernateUtil.beginTransaction(); | ||
List<AccountRequest> accountRequests = logic.getAllAccountRequests(); | ||
for (AccountRequest ar : accountRequests) { | ||
logic.deleteAccountRequest(ar.getEmail(), ar.getInstitute()); | ||
} | ||
accountRequests = logic.getPendingAccountRequests(); | ||
HibernateUtil.commitTransaction(); | ||
assert accountRequests.isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters