# -*- 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, 'frappe.get_all', 'frappe.get_all', (['"""Blog Post"""'], {'fields': "['name', 'route']", 'filters': "{'published': 1, 'route': ('!=', '')}", 'limit': '(1)'}), False, 'import frappe\n'), (22, 'frappe.new_doc', 'frappe.new_doc', (['"""Website Route Meta"""'], {}), False, 'import frappe\n'), (29, 'frappe.utils.set_request', 'set_request', ([], {'path': 'blog.route'}), False, 'from frappe.utils import set_request\n'), (30, 'frappe.website.serve.get_response', 'get_response', ([], {}), False, 'from frappe.website.serve import get_response\n'), (40, 'frappe.db.rollback', 'frappe.db.rollback', ([], {}), False, 'import frappe\n')]