From a2af636a85bd89665532ee68555b4757f1dd3d34 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Mon, 13 Jan 2020 08:14:58 +0100 Subject: [PATCH] Working on handlers<->orm test --- handlers/compose/db.env | 8 +- handlers/compose/sql/karmen_test.sql | 445 ------------------ .../compose}/sql/oef_test.sql | 0 handlers/handlers_test.go | 39 +- handlers/testdata/config.yaml | 2 +- .../{teachers.html.tpl => contests.html.tpl} | 0 6 files changed, 41 insertions(+), 453 deletions(-) delete mode 100644 handlers/compose/sql/karmen_test.sql rename {compose => handlers/compose}/sql/oef_test.sql (100%) rename handlers/testdata/templates/{teachers.html.tpl => contests.html.tpl} (100%) diff --git a/handlers/compose/db.env b/handlers/compose/db.env index ec17e309..762f78bb 100644 --- a/handlers/compose/db.env +++ b/handlers/compose/db.env @@ -1,7 +1,7 @@ -MYSQL_ROOT_PASSWORD=karmen -MYSQL_PASSWORD=karmen -MYSQL_DATABASE=karmen_test -MYSQL_USER=karmen +MYSQL_ROOT_PASSWORD=oef +MYSQL_PASSWORD=oef +MYSQL_DATABASE=oef_test +MYSQL_USER=oef diff --git a/handlers/compose/sql/karmen_test.sql b/handlers/compose/sql/karmen_test.sql deleted file mode 100644 index e1330984..00000000 --- a/handlers/compose/sql/karmen_test.sql +++ /dev/null @@ -1,445 +0,0 @@ --- MySQL dump 10.16 Distrib 10.3.9-MariaDB, for debian-linux-gnu (x86_64) --- --- Host: localhost Database: karmen_dev --- ------------------------------------------------------ --- Server version 10.3.9-MariaDB-1:10.3.9+maria~bionic - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `activities` --- - -DROP TABLE IF EXISTS `activities`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `activities` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `class_id` int(10) unsigned DEFAULT NULL, - `teacher_id` int(10) unsigned DEFAULT NULL, - `subject_id` int(10) unsigned DEFAULT NULL, - `hours` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_activities_deleted_at` (`deleted_at`) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `activities` --- - -LOCK TABLES `activities` WRITE; -/*!40000 ALTER TABLE `activities` DISABLE KEYS */; -INSERT INTO `activities` VALUES (1,'2018-08-24 17:17:22','2018-08-24 17:17:22',NULL,'1 A MATEMATICA 2h',1,1,1,2),(2,'2018-08-24 17:18:01','2018-08-24 17:18:01',NULL,'1 A INGLESE 2h',1,2,3,2),(3,'2018-08-24 17:18:26','2018-08-24 17:18:26',NULL,'1 A ITALIANO 5h',1,3,2,5),(4,'2018-08-24 17:23:58','2018-08-24 17:23:58',NULL,'1 A STORIA DELL\'ARTE 2h',1,5,4,2),(5,'2018-08-24 17:24:20','2018-08-24 17:24:20',NULL,'1 A TECNOLOGIA 2h',1,4,9,2),(6,'2018-08-24 17:24:41','2018-08-24 17:24:41',NULL,'1 A FRANCESE 2h',1,7,7,2),(7,'2018-08-24 17:25:13','2018-08-24 17:25:13',NULL,'1 A RELIGIONE 2h',1,9,6,2),(8,'2018-08-24 17:25:44','2018-08-24 17:25:44',NULL,'1 A STORIA 2h',1,6,8,2),(9,'2018-08-24 17:26:15','2018-08-24 17:26:15',NULL,'1 A SCIENZE 2h',1,8,5,2); -/*!40000 ALTER TABLE `activities` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `administratives` --- - -DROP TABLE IF EXISTS `administratives`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `administratives` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `surname` varchar(255) DEFAULT NULL, - `username` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `email` varchar(255) DEFAULT NULL, - `telephone_number` varchar(255) DEFAULT NULL, - `role` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_administratives_deleted_at` (`deleted_at`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `administratives` --- - -LOCK TABLES `administratives` WRITE; -/*!40000 ALTER TABLE `administratives` DISABLE KEYS */; -/*!40000 ALTER TABLE `administratives` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `classes` --- - -DROP TABLE IF EXISTS `classes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `classes` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `coordinator_id` int(10) unsigned DEFAULT NULL, - `minuter_id` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_classes_deleted_at` (`deleted_at`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `classes` --- - -LOCK TABLES `classes` WRITE; -/*!40000 ALTER TABLE `classes` DISABLE KEYS */; -INSERT INTO `classes` VALUES (1,'2018-08-24 17:11:29','2018-09-14 08:32:37',NULL,'1 A',0,2),(2,'2018-08-24 17:12:43','2018-08-24 17:12:43','2018-08-24 17:17:01','1 A',1,2); -/*!40000 ALTER TABLE `classes` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `department_teachers` --- - -DROP TABLE IF EXISTS `department_teachers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `department_teachers` ( - `department_id` int(10) unsigned NOT NULL, - `teacher_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`department_id`,`teacher_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `department_teachers` --- - -LOCK TABLES `department_teachers` WRITE; -/*!40000 ALTER TABLE `department_teachers` DISABLE KEYS */; -/*!40000 ALTER TABLE `department_teachers` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `departments` --- - -DROP TABLE IF EXISTS `departments`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `departments` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `coordinator_id` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_departments_deleted_at` (`deleted_at`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `departments` --- - -LOCK TABLES `departments` WRITE; -/*!40000 ALTER TABLE `departments` DISABLE KEYS */; -INSERT INTO `departments` VALUES (1,'2018-09-13 16:21:31','2018-09-13 16:30:10',NULL,'LINGUE STRANIERE',NULL),(4,'2018-09-14 07:17:59','2018-09-14 08:24:29',NULL,'MATEMATICA',1); -/*!40000 ALTER TABLE `departments` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `directors` --- - -DROP TABLE IF EXISTS `directors`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `directors` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `surname` varchar(255) DEFAULT NULL, - `username` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `email` varchar(255) DEFAULT NULL, - `telephone_number` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_directors_deleted_at` (`deleted_at`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `directors` --- - -LOCK TABLES `directors` WRITE; -/*!40000 ALTER TABLE `directors` DISABLE KEYS */; -/*!40000 ALTER TABLE `directors` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `issues` --- - -DROP TABLE IF EXISTS `issues`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `issues` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `description` varchar(255) DEFAULT NULL, - `type` int(10) unsigned DEFAULT NULL, - `reported` tinyint(1) DEFAULT NULL, - `teacher_id` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_issues_deleted_at` (`deleted_at`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `issues` --- - -LOCK TABLES `issues` WRITE; -/*!40000 ALTER TABLE `issues` DISABLE KEYS */; -/*!40000 ALTER TABLE `issues` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `schools` --- - -DROP TABLE IF EXISTS `schools`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `schools` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `address` varchar(255) DEFAULT NULL, - `domain` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_schools_deleted_at` (`deleted_at`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `schools` --- - -LOCK TABLES `schools` WRITE; -/*!40000 ALTER TABLE `schools` DISABLE KEYS */; -INSERT INTO `schools` VALUES (1,'2018-08-24 17:19:56','2018-08-24 17:19:56',NULL,'Scuola media inferiore \"Leonardo da Vinci\"','via Castroneria 4, Perlizzi (TN)','scuolamediadavinci.gov.it'); -/*!40000 ALTER TABLE `schools` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `students` --- - -DROP TABLE IF EXISTS `students`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `students` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `surname` varchar(255) DEFAULT NULL, - `username` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `email` varchar(255) DEFAULT NULL, - `telephone_number` varchar(255) DEFAULT NULL, - `plain_password` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_students_deleted_at` (`deleted_at`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `students` --- - -LOCK TABLES `students` WRITE; -/*!40000 ALTER TABLE `students` DISABLE KEYS */; -/*!40000 ALTER TABLE `students` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `subjects` --- - -DROP TABLE IF EXISTS `subjects`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `subjects` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `department_id` int(10) unsigned DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_subjects_deleted_at` (`deleted_at`) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `subjects` --- - -LOCK TABLES `subjects` WRITE; -/*!40000 ALTER TABLE `subjects` DISABLE KEYS */; -INSERT INTO `subjects` VALUES (1,'2018-08-24 17:09:21','2018-09-14 07:31:50',NULL,'MATEMATICA',4),(2,'2018-08-24 17:09:35','2018-08-24 17:09:35',NULL,'ITALIANO',0),(3,'2018-08-24 17:09:44','2018-09-14 07:14:36',NULL,'INGLESE',1),(4,'2018-08-24 17:21:29','2018-08-24 17:21:29',NULL,'STORIA DELL\'ARTE',0),(5,'2018-08-24 17:21:44','2018-08-24 17:21:44',NULL,'SCIENZE',0),(6,'2018-08-24 17:21:59','2018-08-24 17:21:59',NULL,'RELIGIONE',0),(7,'2018-08-24 17:22:31','2018-09-13 16:52:35',NULL,'FRANCESE',1),(8,'2018-08-24 17:23:19','2018-08-24 17:23:19',NULL,'STORIA',0),(9,'2018-08-24 17:23:33','2018-08-24 17:23:33',NULL,'TECNOLOGIA',0); -/*!40000 ALTER TABLE `subjects` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `teacher_classes` --- - -DROP TABLE IF EXISTS `teacher_classes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `teacher_classes` ( - `teacher_id` int(10) unsigned NOT NULL, - `class_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`teacher_id`,`class_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `teacher_classes` --- - -LOCK TABLES `teacher_classes` WRITE; -/*!40000 ALTER TABLE `teacher_classes` DISABLE KEYS */; -INSERT INTO `teacher_classes` VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1); -/*!40000 ALTER TABLE `teacher_classes` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `teacher_subjects` --- - -DROP TABLE IF EXISTS `teacher_subjects`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `teacher_subjects` ( - `subject_id` int(10) unsigned NOT NULL, - `teacher_id` int(10) unsigned NOT NULL, - PRIMARY KEY (`subject_id`,`teacher_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `teacher_subjects` --- - -LOCK TABLES `teacher_subjects` WRITE; -/*!40000 ALTER TABLE `teacher_subjects` DISABLE KEYS */; -INSERT INTO `teacher_subjects` VALUES (1,1),(2,3),(3,2),(4,5),(5,8),(6,9),(7,7),(8,6),(9,4); -/*!40000 ALTER TABLE `teacher_subjects` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `teachers` --- - -DROP TABLE IF EXISTS `teachers`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `teachers` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `surname` varchar(255) DEFAULT NULL, - `username` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `email` varchar(255) DEFAULT NULL, - `telephone_number` varchar(255) DEFAULT NULL, - `hours` int(11) DEFAULT NULL, - `curr_hours` int(11) DEFAULT NULL, - `the_boss_id` int(10) unsigned DEFAULT NULL, - `plain_password` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_teachers_deleted_at` (`deleted_at`) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `teachers` --- - -LOCK TABLES `teachers` WRITE; -/*!40000 ALTER TABLE `teachers` DISABLE KEYS */; -INSERT INTO `teachers` VALUES (1,'2018-08-24 17:06:38','2018-08-24 17:17:22',NULL,'Amilcare','AGOSTINO','amilcare.agostino','TpbbDZmSdjzOzEcm5797h2TXY/hzYWx0','amilcare.agostino@foo.org','',18,2,0,NULL),(2,'2018-08-24 17:06:58','2018-08-24 17:18:01',NULL,'Assuntina','DONADONI','assuntina.donadoni','Fi28Y8Q76pqz3ggoAuXvMNliew9zYWx0','assuntina.donadoni@foo.org','',18,2,0,NULL),(3,'2018-08-24 17:07:14','2018-08-24 17:18:26',NULL,'Costanza','LUNGA','costanza.lunga','//XInIkvIeMYj0+x9AsabCyA8zVzYWx0','costanza.lunga@foo.org','',18,5,0,NULL),(4,'2018-08-24 17:07:28','2018-08-24 17:24:20',NULL,'Giacomo','DEL BEN','giacomo.delben','TTdp/vYL+NjgJZTErlceSVwCa1lzYWx0','giacomo.delben@foo.org','',18,2,0,NULL),(5,'2018-08-24 17:07:51','2018-08-24 17:23:58',NULL,'Giorgio','ARISTI','giorgio.aristi','bbtj5tK+TSBKd38G/zHK6TUo0JZzYWx0','giorgio.aristi@foo.org','',18,2,0,NULL),(6,'2018-08-24 17:08:12','2018-08-24 17:25:44',NULL,'Vittoria','GIRONI','vittoria.gironi','jS5M30Y9d5JUsyXSfxU1Vz4Tmc1zYWx0','vittoria.gironi@foo.org','',18,2,0,NULL),(7,'2018-08-24 17:08:33','2018-08-24 17:24:41',NULL,'Francesco','DELLE ROSE','francesco.dellerose','9HakZF2Oh1vZy+8J/doqR1Jpr/lzYWx0','francesco.dellerose@foo.org','',18,2,0,NULL),(8,'2018-08-24 17:08:51','2018-08-24 17:26:15',NULL,'Andrea','PETRUZZELLI','andrea.petruzzelli','enbmvOYnUs/2IkttlR90h3oJC9dzYWx0','andrea.petruzzelli@foo.org','',18,2,0,NULL),(9,'2018-08-24 17:09:07','2018-08-24 17:25:13',NULL,'Piero','FRANCESCHINI','piero.franceschini','eGAGAG9etZ+rehwW0A/KRWt/7CFzYWx0','piero.franceschini@foo.org','',18,2,0,NULL); -/*!40000 ALTER TABLE `teachers` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `the_bosses` --- - -DROP TABLE IF EXISTS `the_bosses`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `the_bosses` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - `deleted_at` timestamp NULL DEFAULT NULL, - `name` varchar(255) DEFAULT NULL, - `surname` varchar(255) DEFAULT NULL, - `username` varchar(255) DEFAULT NULL, - `password` varchar(255) DEFAULT NULL, - `email` varchar(255) DEFAULT NULL, - `telephone_number` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `idx_the_bosses_deleted_at` (`deleted_at`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `the_bosses` --- - -LOCK TABLES `the_bosses` WRITE; -/*!40000 ALTER TABLE `the_bosses` DISABLE KEYS */; -/*!40000 ALTER TABLE `the_bosses` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2018-09-14 8:42:51 diff --git a/compose/sql/oef_test.sql b/handlers/compose/sql/oef_test.sql similarity index 100% rename from compose/sql/oef_test.sql rename to handlers/compose/sql/oef_test.sql diff --git a/handlers/handlers_test.go b/handlers/handlers_test.go index f2bc9c41..b15b30cb 100644 --- a/handlers/handlers_test.go +++ b/handlers/handlers_test.go @@ -1,7 +1,9 @@ package handlers import ( + "context" "encoding/json" + "log" "net/http" "net/http/httptest" "net/url" @@ -12,6 +14,7 @@ import ( "git.andreafazzi.eu/andrea/oef/config" "git.andreafazzi.eu/andrea/oef/orm" "git.andreafazzi.eu/andrea/oef/renderer" + jwt "github.com/dgrijalva/jwt-go" "github.com/jinzhu/gorm" "github.com/remogatto/prettytest" ) @@ -40,6 +43,18 @@ func (t *testSuite) BeforeAll() { err error ) + models := []interface{}{ + &orm.Question{}, + &orm.Answer{}, + &orm.Contest{}, + &orm.Participant{}, + &orm.School{}, + &orm.Response{}, + &orm.User{}, + &orm.Category{}, + &orm.Region{}, + } + // Initialize the ORM connected := false @@ -56,6 +71,11 @@ func (t *testSuite) BeforeAll() { orm.Use(db) orm.AutoMigrate() + // Map the handlers + if err := orm.MapHandlers(models); err != nil { + panic(err) + } + // Initialize the renderers htmlRenderer, err := renderer.NewHTMLRenderer("./testdata/templates/") @@ -118,8 +138,8 @@ func (t *testSuite) BeforeAll() { } -func (t *testSuite) TestGetTeachersHTML() { - req, err := http.NewRequest("GET", "/teachers?format=html&tpl_layout=base&tpl_content=teachers", nil) +func (t *testSuite) TestReadAllContests() { + req, err := http.NewRequest("GET", "/contests?format=html&tpl_layout=base&tpl_content=contests", nil) if err != nil { panic(err) } @@ -131,7 +151,20 @@ func (t *testSuite) TestGetTeachersHTML() { } rr := httptest.NewRecorder() - modelHandler("teachers", pattern).ServeHTTP(rr, req) + + ctx := req.Context() + claims := &jwt.MapClaims{} + log.Print(token) + tkn, err := jwt.ParseWithClaims(token, claims, func(token *jwt.Token) (interface{}, error) { + return config.Config.Keys.JWTSigningKey, nil + }) + if err != nil { + panic(err) + } + ctx = context.WithValue(ctx, "user", tkn) + req = req.WithContext(ctx) + + modelHandler("contests", pattern).ServeHTTP(rr, req) t.Equal(http.StatusOK, rr.Code) diff --git a/handlers/testdata/config.yaml b/handlers/testdata/config.yaml index 877f8616..8bdcdd23 100644 --- a/handlers/testdata/config.yaml +++ b/handlers/testdata/config.yaml @@ -6,7 +6,7 @@ keys: jwt_signing_key: "secret" orm: - connection: "karmen:karmen@tcp(db:3306)/karmen_dev" + connection: "oef:oef@tcp(db:3306)/oef_test" options: "charset=utf8&parseTime=True&loc=Local" automigrate: true reset: false diff --git a/handlers/testdata/templates/teachers.html.tpl b/handlers/testdata/templates/contests.html.tpl similarity index 100% rename from handlers/testdata/templates/teachers.html.tpl rename to handlers/testdata/templates/contests.html.tpl