import jingrow
from jingrow.core.pagetype.pagetype.test_pagetype import new_pagetype
from jingrow.tests.utils import JingrowTestCase


class TestRating(JingrowTestCase):
	def setUp(self):
		pg = new_pagetype(
			fields=[
				{
					"fieldname": "rating",
					"fieldtype": "Rating",
					"label": "rating",
					"reqd": 1,  # mandatory
				},
			],
		)
		pg.insert()
		self.pagetype_name = pg.name

	def test_negative_rating(self):
		pg = jingrow.new_pg(pagetype=self.pagetype_name, rating=-1)
		pg.insert()
		self.assertEqual(pg.rating, 0)

	def test_positive_rating(self):
		pg = jingrow.new_pg(pagetype=self.pagetype_name, rating=5)
		pg.insert()
		self.assertEqual(pg.rating, 1)
