From ea99d47b9a5fbf5486f0a1f9cc89505806f18222 Mon Sep 17 00:00:00 2001
From: Andrea Fazzi
Date: Sat, 8 Feb 2020 12:27:13 +0100
Subject: [PATCH] Working on school subscription regression test
---
Makefile | 1 +
config/config.regression_test.yaml | 6 +--
go.sum | 1 +
orm/orm.go | 7 +++
regression_test/Makefile | 5 +-
regression_test/regression_test.go | 83 ++++++++++++++++++++++++++++--
templates/layout/base.html.tpl | 2 +-
templates/schools_show.html.tpl | 6 +++
8 files changed, 102 insertions(+), 9 deletions(-)
diff --git a/Makefile b/Makefile
index 55811f99..fc40e602 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ regression_test:
go build .
docker-compose -f docker/oef_regression_test/docker-compose.yaml up --build -d
./bash/wait_until_up.bash oef_regression_test
+ ./bash/wait_until_up.bash oef_regression_test_selenium_1
cd regression_test && make
all: prod
diff --git a/config/config.regression_test.yaml b/config/config.regression_test.yaml
index c644c8be..2fb7795d 100644
--- a/config/config.regression_test.yaml
+++ b/config/config.regression_test.yaml
@@ -1,4 +1,4 @@
-url: "http://localhost:3000"
+url: "http://oef_regression_test:3000"
log_level: 2
language: "it"
@@ -20,8 +20,8 @@ subscriber:
password: "subscribe"
smtp:
- host: "localhost"
- port: 1025
+ host: "smtp"
+ port: 25
username: ""
password: ""
from: "no-reply@olimpiadi-economiaefinanza.it"
diff --git a/go.sum b/go.sum
index 5f67da4e..6f284ed4 100644
--- a/go.sum
+++ b/go.sum
@@ -3,6 +3,7 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.37.4 h1:glPeL3BQJsbF6aIIYfZizMwc5LTYz250bDMjttbBGAU=
cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
+cloud.google.com/go v0.41.0 h1:NFvqUTDnSNYPX5oReekmB+D+90jrJIcVImxQ3qrBVgM=
cloud.google.com/go v0.41.0/go.mod h1:OauMR7DV8fzvZIl2qg6rkaIhD/vmgk4iwEw/h6ercmg=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
diff --git a/orm/orm.go b/orm/orm.go
index 5ffe0470..6d4bc51f 100644
--- a/orm/orm.go
+++ b/orm/orm.go
@@ -55,6 +55,13 @@ func (db *Database) AutoMigrate() {
}
+func (db *Database) Reset() {
+ if err := db._db.DropTable(db.models...).Error; err != nil {
+ panic(err)
+ }
+
+}
+
func (db *Database) GetUser(username, password string) (*User, error) {
var user User
if err := db._db.Where("username = ? AND password = ?", username, password).First(&user).Error; err != nil {
diff --git a/regression_test/Makefile b/regression_test/Makefile
index dcb44042..076eefa8 100644
--- a/regression_test/Makefile
+++ b/regression_test/Makefile
@@ -4,7 +4,8 @@
test:
docker exec -d oef_regression_test_selenium_1 ffmpeg -y -video_size 1360x1020 -framerate 15 -f x11grab -i :99.0 /tmp/recording.mp4
go test
- docker exec oef_regression_test_selenium_1 killall -s QUIT ffmpeg
- docker cp oef_regression_test_selenium_1:/tmp/recording.mp4 recordings/recording.mp4
+ docker exec oef_regression_test_selenium_1 killall -s SIGINT ffmpeg
+ docker exec oef_regression_test_selenium_1 MP4Box -isma -inter 500 -out /tmp/recording_cleaned_up.mp4 /tmp/recording.mp4
+ docker cp oef_regression_test_selenium_1:/tmp/recording_cleaned_up.mp4 recordings/recording.mp4
all: test
diff --git a/regression_test/regression_test.go b/regression_test/regression_test.go
index d5e46328..45a55d38 100644
--- a/regression_test/regression_test.go
+++ b/regression_test/regression_test.go
@@ -2,6 +2,7 @@ package regression_test
import (
"fmt"
+ "log"
"testing"
"github.com/remogatto/prettytest"
@@ -126,22 +127,81 @@ func (t *testSuite) TestSchoolSubscription() {
panic(err)
}
+ err = findElement("#school_email").SendKeys("foo.bar@school.org")
+ if err != nil {
+ panic(err)
+ }
+
+ err = findElement("#school_contact_person_firstname").SendKeys("Mario")
+ if err != nil {
+ panic(err)
+ }
+ err = findElement("#school_contact_person_lastname").SendKeys("BROS")
+ if err != nil {
+ panic(err)
+ }
+
+ err = findElement("#school_contest_director_firstname").SendKeys("Luigi")
+ if err != nil {
+ panic(err)
+ }
+ err = findElement("#school_contest_director_lastname").SendKeys("BROS")
+ if err != nil {
+ panic(err)
+ }
+
err = findElement("button.btn.btn-primary").Click()
if err != nil {
panic(err)
}
- expected := []string{"JUNIOR Contest", "SENIOR Contest"}
- elements := findElements(".list-group a")
+ expected := []string{"Liceo GALILEI", "foo.bar@school.org"}
+ elements := findElements("p strong")
+ t.True(len(elements) > 0)
for i, el := range elements {
text, err := el.Text()
if err != nil {
panic(err)
}
- t.Contain(expected[i], text)
+ t.Equal(expected[i], text)
+ }
+
+ credentials := findElements("dd")
+ log.Println("DD", credentials)
+ if len(credentials) == 0 {
+ panic("Can't find credentials in the renderered HTML page")
+ }
+
+ username, err := credentials[0].Text()
+ if err != nil {
+ panic(err)
+ }
+ password, err := credentials[1].Text()
+ if err != nil {
+ panic(err)
}
logout()
+
+ login(username, password)
+
+ logout()
+
+ login("admin", "admin")
+
+ err = findElement("#schools_navbar_link").Click()
+ if err != nil {
+ panic(err)
+ }
+ err = findElement("#myInput").SendKeys("Liceo GALILEI")
+ if err != nil {
+ panic(err)
+ }
+ err = findElement("a.list-group-item").Click()
+ if err != nil {
+ panic(err)
+ }
+
}
func findElement(selector string) selenium.WebElement {
@@ -160,6 +220,23 @@ func findElements(selector string) []selenium.WebElement {
return elements
}
+func login(username, password string) {
+ err := findElement("#username").SendKeys(username)
+ if err != nil {
+ panic(err)
+ }
+
+ err = findElement("#password").SendKeys(password)
+ if err != nil {
+ panic(err)
+ }
+
+ err = findElement("button").Click()
+ if err != nil {
+ panic(err)
+ }
+}
+
func logout() {
err := findElement("a#logout").Click()
if err != nil {
diff --git a/templates/layout/base.html.tpl b/templates/layout/base.html.tpl
index 3855fedb..45f4c01e 100644
--- a/templates/layout/base.html.tpl
+++ b/templates/layout/base.html.tpl
@@ -43,7 +43,7 @@
Gare
Domande
Risposte
- Scuole
+ Scuole
Partecipanti
Prove
{{- end -}}
diff --git a/templates/schools_show.html.tpl b/templates/schools_show.html.tpl
index bd3dc918..8cfae7fb 100644
--- a/templates/schools_show.html.tpl
+++ b/templates/schools_show.html.tpl
@@ -19,6 +19,12 @@
messaggio non fosse stato recapitato nella cartella "Posta in
arrivo" si prega di controllare la cartella "Spam".
+
+ Le credenziali generate sono:
+
+ - Username
- {{.Data.Username}}
+ - Password
- {{.Data.Password}}
+
Ora รจ possibile uscire da questa sessione e
utilizzare le credenziali ricevute per iscrivere gli studenti alla