<commit_before>package templates

import (
	"bytes"
	"fmt"
	"html/template"
	"io/ioutil"
	"net/url"
	"path"
	"testing"

	"github.com/NyaaPantsu/nyaa/utils/validator/announcement"

	"strings"

	"time"

	"github.com/CloudyKit/jet"
	"github.com/NyaaPantsu/nyaa/config"
	"github.com/NyaaPantsu/nyaa/models"
	"github.com/NyaaPantsu/nyaa/utils/filelist"
	"github.com/NyaaPantsu/nyaa/utils/oauth2/client"
	"github.com/NyaaPantsu/nyaa/utils/publicSettings"
	"github.com/NyaaPantsu/nyaa/utils/validator/api"
	"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
	"github.com/NyaaPantsu/nyaa/utils/validator/user"
	"github.com/gin-gonic/gin"
)

// run before router/init.go:init()
var _ = func() (_ struct{}) {
	gin.SetMode(gin.TestMode)
	config.Configpaths[1] = path.Join("..", config.Configpaths[1])
	config.Configpaths[0] = path.Join("..", config.Configpaths[0])
	config.Reload()
	return
}()

func TestTemplates(t *testing.T) {
	//var View = jet.NewHTMLSet(TemplateDir)
	fmt.Print("JetTest Template started\n")

	walkDirTest("/", t)

}

type ContextTest map[string]func(jet.VarMap) jet.VarMap

func walkDirTest(dir string, t *testing.T) {
	fu := "http://nyaa.cat"
	em := "<EMAIL>"

	fakeTag := &models.Tag{1, 1, "12345", "anidbid", 1, 0, true}
	fakeUser := &models.User{1, "test", "test", "test", 1, time.Now(), time.Now(), "test", time.Now(), "en", "test", "test", "test", "test", "test", "test", "test", "test", "test", 0.0, []models.User{}, []models.User{}, "test", []models.Torrent{}, []models.Notification{}, 1, models.UserSettings{}, []models.Tag{*fakeTag}}
	fakeComment := &models.Comment{1, 1, 1, "test", time.Now(), time.Now(), nil, &models.Torrent{}, fakeUser}
	fakeScrapeData := &models.Scrape{1, 0, 0, 10, time.Now()}
	fakeFile := &models.File{1, 1, "l12:somefile.mp4e", 3}
	fakeLanguages := []string{"fr", "en"}
	fakeTorrent := &models.Torrent{1, "test", "test", 3, 12, 1, false, time.Now(), 1, 0, 3, "test", "test", "test", 12, 12, 12, "RJ001001", "", "", "", nil, fakeUser, "test", []models.OldComment{}, []models.Comment{*fakeComment, *fakeComment}, []models.Tag{*fakeTag, *fakeTag}, fakeScrapeData, []models.File{*fakeFile}, fakeLanguages}
	fakeActivity := &models.Activity{1, "t", "e", "s", 1, fakeUser}
	fakeDB := &models.DatabaseDump{time.Now(), 3, "test", "test"}
	fakeLanguage := &publicSettings.Language{"English", "en", "en-us"}
	fakeTorrentRequest := &torrentValidator.TorrentRequest{Name: "test", Magnet: "", Category: "", Remake: false, Description: "", Status: 1, Hidden: false, CaptchaID: "", WebsiteLink: "", Languages: nil, Infohash: "", SubCategoryID: 0, CategoryID: 0, Filesize: 0, Filepath: "", FileList: nil, Trackers: nil, Tags: torrentValidator.TagsRequest{}}
	fakeLogin := &userValidator.LoginForm{"test", "test", "/", "false"}
	fakeRegistration := &userValidator.RegistrationForm{"test", "", "test", "test", "xxxx", "1"}
	fakeReport := &models.TorrentReport{1, "test", 1, 1, time.Now(), fakeTorrent, fakeUser}
	fakeOauthForm := apiValidator.CreateForm{"", "f", []string{fu}, []string{}, []string{}, "", "fedr", fu, fu, fu, fu, []string{em}, ""}
	fakeOauthModel := fakeOauthForm.Bind(&models.OauthClient{})
	fakeClient := client.Client{"", "", "", []string{""}, []string{""}, []string{""}, "", "", "", "", "", "", []string{""}, false}
	fakeAnnouncement := announcementValidator.CreateForm{1, "", 2}
	fakeNotification := &models.Notification{1, "test", true, "test", "test", time.Now(), 1}

	contextvariables := ContextTest{
		"dumps.jet.html": func(variables jet.VarMap) jet.VarMap {
			variables.Set("GPGLink", "test")
			variables.Set("ListDumps", []models.DatabaseDumpJSON{fakeDB.ToJSON(), fakeDB.ToJSON()})
			return variables
		},
		"activities.jet.html": func(variables jet.VarMap) jet.VarMap {
			variables.Set("Models", []models.Activity{*fakeActivity})
			return variables
		},
		"listing.jet.html": func(variables jet.VarMap) jet.VarMap {
			variables.Set("Models", []models.TorrentJSON{fakeTorrent.ToJSON(), fakeTorrent.ToJSON()})
			return variables<commit_msg>Update template_test.go<commit_after>package templates

import (
	"bytes"
	"fmt"
	"html/template"
	"io/ioutil"
	"net/url"
	"path"
	"testing"

	"github.com/NyaaPantsu/nyaa/utils/validator/announcement"

	"strings"

	"time"

	"github.com/CloudyKit/jet"
	"github.com/NyaaPantsu/nyaa/config"
	"github.com/NyaaPantsu/nyaa/models"
	"github.com/NyaaPantsu/nyaa/utils/filelist"
	"github.com/NyaaPantsu/nyaa/utils/oauth2/client"
	"github.com/NyaaPantsu/nyaa/utils/publicSettings"
	"github.com/NyaaPantsu/nyaa/utils/validator/api"
	"github.com/NyaaPantsu/nyaa/utils/validator/torrent"
	"github.com/NyaaPantsu/nyaa/utils/validator/user"
	"github.com/gin-gonic/gin"
)

// run before router/init.go:init()
var _ = func() (_ struct{}) {
	gin.SetMode(gin.TestMode)
	config.Configpaths[1] = path.Join("..", config.Configpaths[1])
	config.Configpaths[0] = path.Join("..", config.Configpaths[0])
	config.Reload()
	return
}()

func TestTemplates(t *testing.T) {
	//var View = jet.NewHTMLSet(TemplateDir)
	fmt.Print("JetTest Template started\n")

	walkDirTest("/", t)

}

type ContextTest map[string]func(jet.VarMap) jet.VarMap

func walkDirTest(dir string, t *testing.T) {
	fu := "http://nyaa.cat"
	em := "<EMAIL>"

	fakeTag := &models.Tag{1, 1, "12345", "anidbid", 1, 0, true}
	fakeUser := &models.User{1, "test", "test", "test", 1, time.Now(), time.Now(), "test", time.Now(), "en", "test", "test", "test", "test", "test", "test", "test", "test", "test", 0.0, []models.User{}, []models.User{}, "test", []models.Torrent{}, []models.Notification{}, 1, models.UserSettings{}, []models.Tag{*fakeTag}}
	fakeComment := &models.Comment{1, 1, 1, "test", time.Now(), time.Now(), nil, &models.Torrent{}, fakeUser}
	fakeScrapeData := &models.Scrape{1, 0, 0, 10, time.Now()}
	fakeFile := &models.File{1, 1, "l12:somefile.mp4e", 3}
	fakeLanguages := []string{"fr", "en"}
	fakeTorrent := &models.Torrent{1, "test", "test", 3, 12, 1, false, time.Now(), 1, 0, 3, "test", "test", "test", 12, 12, 12, "RJ001001", "", "", "", nil, fakeUser, "test", []models.OldComment{}, []models.Comment{*fakeComment, *fakeComment}, []models.Tag{*fakeTag, *fakeTag}, fakeScrapeData, []models.File{*fakeFile}, fakeLanguages}
	fakeActivity := &models.Activity{1, "t", "e", "s", 1, fakeUser}
	fakeDB := &models.DatabaseDump{time.Now(), 3, "test", "test"}
	fakeLanguage := &publicSettings.Language{"English", "en", "en-us"}
	fakeTorrentRequest := &torrentValidator.TorrentRequest{Name: "test", Magnet: "", Category: "", Remake: false, Description: "", Status: 1, Hidden: false, CaptchaID: "", WebsiteLink: "", Languages: nil, Infohash: "", SubCategoryID: 0, CategoryID: 0, Filesize: 0, Filepath: "", FileList: nil, Trackers: nil, Tags: torrentValidator.TagsRequest{}}
	fakeLogin := &userValidator.LoginForm{"test", "test", "/", "false"}
	fakeRegistration := &userValidator.RegistrationForm{"test", "", "test", "test", "xxxx", "1"}
	fakeReport := &models.TorrentReport{1, "test", 1, 1, time.Now(), fakeTorrent, fakeUser}
	fakeOauthForm := apiValidator.CreateForm{"", "f", []string{fu}, []string{}, []string{}, "", "fedr", fu, fu, fu, fu, []string{em}, ""}
	fakeOauthModel := fakeOauthForm.Bind(&models.OauthClient{})
	fakeClient := client.Client{"", "", "", []string{""}, []string{""}, []string{""}, "", "", "", "", "", "", []string{""}, false}
	fakeAnnouncement := announcementValidator.CreateForm{1, "", 2}
	fakeNotification := &models.Notification{1, "test", true, "test", "test", time.Now(), time.Now(), 1}

	contextvariables := ContextTest{
		"dumps.jet.html": func(variables jet.VarMap) jet.VarMap {
			variables.Set("GPGLink", "test")
			variables.Set("ListDumps", []models.DatabaseDumpJSON{fakeDB.ToJSON(), fakeDB.ToJSON()})
			return variables
		},
		"activities.jet.html": func(variables jet.VarMap) jet.VarMap {
			variables.Set("Models", []models.Activity{*fakeActivity})
			return variables
		},
		"listing.jet.html": func(variables jet.VarMap) jet.VarMap {
			variables.Set("Models", []models.TorrentJSON{fakeTorrent.ToJSON(), fakeTorrent.ToJSON()})
			return variables
{'fraction_non_alphanumeric': 0.21855541718555418, 'fraction_numerical': 0.016936488169364883, 'mean_word_length': 5.7544154751892345, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2730917', 'n_tokens_mistral': 3092, 'n_tokens_neox': 2931, 'n_words': 559}