import cherrypy
from cherrypy.test import helper

from python_utility.spreadsheet.spreadsheet_service import SpreadsheetService


class SpreadsheetWebTest(helper.CPWebCase):
    @staticmethod
    def setup_server():
        cherrypy.tree.mount(SpreadsheetService(), '/', {})

    def test_status(self):
        self.getPage("/status")
        self.assertStatus('200 OK')

    def test_spreadsheet_search_missing(self):
        body = '{}'
        headers = [('Content-Type', 'application/json'),
                   ('Content-Length', str(len(body)))]
        self.getPage("/spreadsheet", method='POST', headers=headers, body=body)
        self.assertBody('"search missing"')
        self.assertStatus('200 OK')

    def test_spreadsheet_replace_missing(self):
        body = '{"search": "test"}'
        headers = [('Content-Type', 'application/json'),
                   ('Content-Length', str(len(body)))]
        self.getPage("/spreadsheet", method='POST', headers=headers, body=body)
        self.assertBody('"replace missing"')
        self.assertStatus('200 OK')

@@ -1042,28 +1042,405 @@
 self.assertStatus('200 OK')%0A
+%0A    def test_spreadsheet_x_offset_missing(self):%0A        body = '%7B%22search%22: %22foo%22, %22replace%22: %22bar%22%7D'%0A        headers = %5B('Content-Type', 'application/json'),%0A                   ('Content-Length', str(len(body)))%5D%0A        self.getPage(%22/spreadsheet%22, method='POST', headers=headers, body=body)%0A        self.assertBody('%22x-offset missing%22')%0A        self.assertStatus('200 OK')%0A

add x-offset missing case