# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# License: MIT. See LICENSE
import unittest

import frappe
from frappe.utils import set_request
from frappe.website.serve import get_response

test_dependencies = ["Blog Post"]


class TestWebsiteRouteMeta(unittest.TestCase):
	def test_meta_tag_generation(self):
		blogs = frappe.get_all(
			"Blog Post", fields=["name", "route"], filters={"published": 1, "route": ("!=", "")}, limit=1
		)

		blog = blogs[0]

		# create meta tags for this route
		doc = frappe.new_doc("Website Route Meta")
		doc.append("meta_tags", {"key": "type", "value": "blog_post"})
		doc.append("meta_tags", {"key": "og:title", "value": "My Blog"})
		doc.name = blog.route
		doc.insert()

		# set request on this route
		set_request(path=blog.route)
		response = get_response()

		self.assertTrue(response.status_code, 200)

		html = response.get_data().decode()

		self.assertTrue("""<meta name="type" content="blog_post">""" in html)
		self.assertTrue("""<meta property="og:title" content="My Blog">""" in html)

	def tearDown(self):
		frappe.db.rollback()

[((15, 10, 17, 3), 'frappe.get_all', 'frappe.get_all', (), '', False, 'import frappe\n'), ((22, 8, 22, 44), 'frappe.new_doc', 'frappe.new_doc', ({(22, 23, 22, 43): '"""Website Route Meta"""'}, {}), "('Website Route Meta')", False, 'import frappe\n'), ((29, 2, 29, 30), 'frappe.utils.set_request', 'set_request', (), '', False, 'from frappe.utils import set_request\n'), ((30, 13, 30, 27), 'frappe.website.serve.get_response', 'get_response', ({}, {}), '()', False, 'from frappe.website.serve import get_response\n'), ((40, 2, 40, 22), 'frappe.db.rollback', 'frappe.db.rollback', ({}, {}), '()', False, 'import frappe\n')]