Andrea Fazzi 6 лет назад
Родитель
Сommit
e51751e791

+ 8 - 0
handlers/Makefile

@@ -0,0 +1,8 @@
+PHONY: all
+
+test:
+	docker-compose -f "compose/docker-compose.yml" down -v
+	docker-compose -f "compose/docker-compose.yml" up -d
+	go test
+
+all: test

+ 10 - 0
handlers/compose/db.env

@@ -0,0 +1,10 @@
+MYSQL_ROOT_PASSWORD=karmen
+MYSQL_PASSWORD=karmen
+MYSQL_DATABASE=karmen_test
+MYSQL_USER=karmen
+
+
+
+
+
+

+ 21 - 0
handlers/compose/docker-compose.yml

@@ -0,0 +1,21 @@
+version: "3.3"
+
+services:
+
+  db:
+    image: mariadb
+    container_name: karmen_test_handlers_db
+    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
+    ports:
+      - 3306:3306
+    volumes:
+      - db:/var/lib/mysql
+      - ./sql:/docker-entrypoint-initdb.d
+    env_file:
+      - db.env
+      
+volumes:
+  db:
+  
+
+      

+ 441 - 0
handlers/compose/sql/karmen_test.sql

@@ -0,0 +1,441 @@
+-- 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-08-24 17:26:35',NULL,'1 A',3,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,
+  PRIMARY KEY (`id`),
+  KEY `idx_departments_deleted_at` (`deleted_at`)
+) ENGINE=InnoDB 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 */;
+/*!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,
+  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-08-24 17:09:21',NULL,'MATEMATICA',0),(2,'2018-08-24 17:09:35','2018-08-24 17:09:35',NULL,'ITALIANO',0),(3,'2018-08-24 17:09:44','2018-08-24 17:09:44',NULL,'INGLESE',0),(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-08-24 17:22:31',NULL,'FRANCESE',0),(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,
+  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),(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),(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),(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),(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),(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),(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),(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),(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);
+/*!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-08-24 18:49:02

+ 51 - 2
handlers/handlers_test.go

@@ -5,9 +5,12 @@ import (
 	"net/http"
 	"net/http/httptest"
 	"testing"
+	"time"
 
+	"github.com/jinzhu/gorm"
 	"github.com/remogatto/prettytest"
 	"gogs.carducci-dante.gov.it/karmen/core/config"
+	"gogs.carducci-dante.gov.it/karmen/core/orm"
 )
 
 var (
@@ -28,7 +31,27 @@ func TestRunner(t *testing.T) {
 }
 
 func (t *testSuite) BeforeAll() {
-	err := config.ReadFile("testdata/config.yaml", config.Config)
+
+	var (
+		db  *gorm.DB
+		err error
+	)
+
+	connected := false
+	for !connected {
+		time.Sleep(10 * time.Second)
+		db, err = orm.New("karmen:karmen@/karmen_test?charset=utf8&parseTime=True&loc=Local")
+		if err != nil {
+			time.Sleep(5 * time.Second)
+			continue
+		}
+		connected = true
+	}
+
+	orm.Use(db)
+	orm.AutoMigrate()
+
+	err = config.ReadFile("testdata/config.yaml", config.Config)
 	if err != nil {
 		panic(err)
 	}
@@ -57,5 +80,31 @@ func (t *testSuite) BeforeAll() {
 
 }
 
-func (t *testSuite) TestGetToken() {
+func (t *testSuite) TestTeachersJSON() {
+	var teachers []*orm.Teacher
+
+	req, err := http.NewRequest("GET", "/teachers?format=json", nil)
+	if err != nil {
+		panic(err)
+	}
+
+	pattern := PathPattern{
+		"/api/%s",
+		"/%s?format=json&tpl_layout=base&tpl_content=%s",
+		[]string{"GET"},
+	}
+
+	rr := httptest.NewRecorder()
+	modelHandler("teachers", pattern).ServeHTTP(rr, req)
+
+	t.Equal(http.StatusOK, rr.Code)
+
+	if !t.Failed() {
+		err := json.Unmarshal(rr.Body.Bytes(), &teachers)
+		t.Nil(err)
+		if !t.Failed() {
+			t.Equal("AGOSTINO", teachers[0].Surname)
+		}
+	}
+
 }