# -*- coding: utf-8 -*-
import unittest
import sys
import os
sys.path.append(os.path.realpath(__file__ + "/../../../"))

import tests.common
from core.localisation import _
import json


class openTests(tests.common.common):
	def test_no_container_given_text(self):
		self.rpgText.setAction([_('OPEN_COMMAND')])
		output = self.rpgText._runAction()
		self.assertTrue(output == _('ERROR_OPEN_NO_CONTAINER_PROVIDED'))

	def test_no_container_given_json(self):
		self.rpgJSON.setAction([_('OPEN_COMMAND')])
		output = self.rpgJSON._runAction()
		self.assertTrue(output == {"error": {"message": _('ERROR_OPEN_NO_CONTAINER_PROVIDED'), "code": 1}})

	def test_container_not_found_here_text(self):
		self.rpgText.setAction([_('OPEN_COMMAND'), 'box'])
		output = self.rpgText._runAction()
		self.assertTrue(output == _('ERROR_OPEN_CONTAINER_NOT_AVAILABLE'))

	def test_container_not_found_here_json(self):
		self.rpgJSON.setAction([_('OPEN_COMMAND'), 'box'])
		output = self.rpgJSON._runAction()
		self.assertTrue(output == {"error": {"message": _('ERROR_OPEN_CONTAINER_NOT_AVAILABLE'), "code": 1}})

	def test_unknown_container_type_text(self):
		self.rpgText.setAction([_('OPEN_COMMAND'), 'some-container'])
		output = self.rpgText._runAction()
		self.assertTrue(output == _('ERROR_UNKNOWN_ITEM_CONTAINER_TYPE_LABEL'))

	def test_unknown_container_type_json(self):
		self.rpgJSON.setAction([_('OPEN_COMMAND'), 'some-container'])
		output = self.rpgJSON._runAction()
		self.assertTrue(output == {"error": {"message": _('ERROR_UNKNOWN_ITEM_CONTAINER_TYPE_LABEL'), "code": 1}})

	def test_multiple_container_of_given_type_text(self):
		pass

	def test_multiple_container_of_given_type_json(self):
		pass

	def test_single_container_of_given_type_text(self):
		self.rpgText.setAction([_('OPEN_COMMAND'), 'chest'])
		output = self.rpgText._runAction()
		expected = [
			_('ITEMS_IN_CONTAINER_%s') % 'chest',
			'  4 Heavy breastplate'
		]
		self.assertTrue(output == '\n'.join(expected))

	def test_single_container_of_given_type_json(self):
		self.rpgJSON.setAction([_('OPEN_COMMAND'), 'chest'])
		output = self.rpgJSON._runAction()
		self.assertTrue(output == {'items': [{'name': 'Heavy breastplate', 'quantity': 4}], 'container_type': 'chest'})

	def test_container_number_provided_text(self):
		pass

	def test_container_number_provided_json(self):
		pass

@@ -1624,75 +1624,436 @@
 :%0A%09%09
-pass%0A%0A%09def test_multiple_container_of_given_type_json(self):%0A%09%09pass
+self.rpgText.setAction(%5B_('OPEN_COMMAND'), 'wardrobe'%5D)%0A%09%09output = self.rpgText._runAction()%0A%09%09self.assertTrue(output == _('ERROR_OPEN_MULTIPLE_CONTAINERS_AVAILABLE'))%0A%0A%09def test_multiple_container_of_given_type_json(self):%0A%09%09self.rpgJSON.setAction(%5B_('OPEN_COMMAND'), 'wardrobe'%5D)%0A%09%09output = self.rpgJSON._runAction()%0A%09%09self.assertTrue(output == %7B%22error%22: %7B%22message%22: _('ERROR_OPEN_MULTIPLE_CONTAINERS_AVAILABLE'), %22code%22: 1%7D%7D)
 %0A%0A%09d

test added to open a container where multiples of this type are in the same area