This repository has been archived by the owner on Oct 24, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #128
- Loading branch information
Showing
4 changed files
with
263 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,242 @@ | ||
import org.specs2.mutable._ | ||
import org.specs2.runner._ | ||
|
||
import play.api.test._ | ||
import play.api.test.Helpers._ | ||
import org.fest.assertions.Assertions.assertThat | ||
import play.api.Application | ||
import play.api.Play | ||
import play.api.Play.current | ||
import models.{ User } | ||
|
||
/** | ||
* An integration test will fire up a whole play application in a real (or headless) browser | ||
*/ | ||
class SysAdminPagesSpec extends Specification { | ||
|
||
"SysAdmin pages" should { | ||
|
||
def create_user(role: String) = User.make("bob", "bob@example.com", role, "current_user") | ||
|
||
// GET /reindex | ||
"reindex" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/reindex/topic") | ||
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub") | ||
} | ||
|
||
"as an analyst redirects to Error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
browser.goTo("http://localhost:" + port + "/reindex/topic") | ||
assertThat(browser.title()).isEqualTo("Error - TopicHub") | ||
browser.pageSource must contain("You are not authorized") | ||
} | ||
|
||
"as an admin reindexes" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
browser.goTo("http://localhost:" + port + "/reindex/topic") | ||
browser.pageSource must contain("Reindexing topics") | ||
} | ||
} | ||
|
||
// GET /workbench | ||
"workbench" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/workbench") | ||
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub") | ||
} | ||
|
||
"as an analyst displays workbench" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
browser.goTo("http://localhost:" + port + "/workbench") | ||
assertThat(browser.title()).isEqualTo("Workbench - TopicHub") | ||
} | ||
|
||
"as an admin redirects to error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
browser.goTo("http://localhost:" + port + "/workbench") | ||
assertThat(browser.title()).isEqualTo("Error - TopicHub") | ||
browser.pageSource must contain("You are not authorized") | ||
} | ||
} | ||
|
||
// GET /purge | ||
"purge" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/purge") | ||
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub") | ||
} | ||
|
||
"as an analyst redirects to Error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
browser.goTo("http://localhost:" + port + "/purge") | ||
assertThat(browser.title()).isEqualTo("Error - TopicHub") | ||
browser.pageSource must contain("You are not authorized") | ||
} | ||
|
||
"as an admin reindexes" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
browser.goTo("http://localhost:" + port + "/purge") | ||
browser.pageSource must contain("too late to go back now") | ||
} | ||
} | ||
|
||
// GET /sandbox | ||
"sandbox" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/sandbox") | ||
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub") | ||
} | ||
|
||
"as an analyst displays form" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
browser.goTo("http://localhost:" + port + "/sandbox") | ||
assertThat(browser.title()).isEqualTo("Sandbox - TopicHub") | ||
browser.pageSource must contain("""<form action="/testExpression" method="POST">""") | ||
} | ||
|
||
"as an admin redirects to Error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
browser.goTo("http://localhost:" + port + "/sandbox") | ||
assertThat(browser.title()).isEqualTo("Error - TopicHub") | ||
browser.pageSource must contain("You are not authorized") | ||
} | ||
} | ||
|
||
// POST /testExpression | ||
"testExpression" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val action = route(FakeRequest(POST, "/testExpression")).get | ||
redirectLocation(action) must beSome.which(_ == "/login") | ||
} | ||
|
||
"as an analyst displays form" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
val action = route(FakeRequest(POST, "/testExpression")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("This field is required") | ||
} | ||
|
||
"as an admin redirects to Error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
val action = route(FakeRequest(POST, "/testExpression")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("Reason: You are not authorized") | ||
} | ||
} | ||
|
||
// GET /model/create | ||
"contentModel" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
browser.goTo("http://localhost:" + port + "/model/create") | ||
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub") | ||
} | ||
|
||
"as an analyst redirects to error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
browser.goTo("http://localhost:" + port + "/model/create") | ||
assertThat(browser.title()).isEqualTo("Error - TopicHub") | ||
browser.pageSource must contain("You are not authorized") | ||
} | ||
|
||
"as an admin display form" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
browser.goTo("http://localhost:" + port + "/model/create") | ||
assertThat(browser.title()).isEqualTo("Create Model - TopicHub") | ||
} | ||
} | ||
|
||
// POST /cmodel | ||
"addContentModel" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val action = route(FakeRequest(POST, "/cmodel")).get | ||
redirectLocation(action) must beSome.which(_ == "/login") | ||
} | ||
|
||
"as an analyst redirects to error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
val action = route(FakeRequest(POST, "/cmodel")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("Reason: You are not authorized") | ||
} | ||
|
||
"as an admin is allowed" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
val action = route(FakeRequest(POST, "/cmodel")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("This field is required") | ||
} | ||
} | ||
|
||
// POST /pubmodel | ||
"addPublisherModel" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val action = route(FakeRequest(POST, "/pubmodel")).get | ||
redirectLocation(action) must beSome.which(_ == "/login") | ||
} | ||
|
||
"as an analyst redirects to error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
val action = route(FakeRequest(POST, "/pubmodel")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("Reason: You are not authorized") | ||
} | ||
|
||
"as an admin is allowed" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
val action = route(FakeRequest(POST, "/pubmodel")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("This field is required") | ||
} | ||
} | ||
|
||
// POST /submodel | ||
"addSubscriberModel" should { | ||
"as an unauthenticated User redirects to login" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
val action = route(FakeRequest(POST, "/submodel")).get | ||
redirectLocation(action) must beSome.which(_ == "/login") | ||
} | ||
|
||
"as an analyst redirects to error" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("analyst") | ||
val action = route(FakeRequest(POST, "/submodel")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("Reason: You are not authorized") | ||
} | ||
|
||
"as an admin is allowed" in new WithBrowser( | ||
app = FakeApplication(additionalConfiguration = inMemoryDatabase())) { | ||
create_user("sysadmin") | ||
val action = route(FakeRequest(POST, "/submodel")).get | ||
redirectLocation(action) must beNone | ||
contentAsString(action) must contain ("This field is required") | ||
} | ||
} | ||
} | ||
} |
6435f97
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍