Exemplo n.º 1
0
    def test_main(self):
        # user adds a house code to the database
        self.post_house_code('FA-32')

        # user reloads the api page
        self.initialise_page()
        h2 = self.section.find_element_by_tag_name('h2')
        self.assertEqual(h2.text, 'POST /api/led/<house-code>')
        # user inputs valid input
        self.house_code_input.send_keys('FA-32')
        self.colour_input.send_keys('0')
        self.state_input.send_keys('0')
        self.repeat_interval_input.send_keys('120')
        self.form.submit()
        self.assertEqual(self.browser.current_url,
                         self.server_url + '/api/led/FA-32')
        json_response = self.get_json_response()
        self.assertEqual(json_response['status'], 200)
        self.assertEqual(json_response['content'], None)

        # TODO: User needs to be able to see the result
        # Currently the LED post does not affect the cache and is just a dummy function

        # user reloads api page
        # user inputs non existent house code
        self.initialise_page()
        self.house_code_input.send_keys('FA-33')
        self.form.submit()
        json_response = self.get_json_response()
        self.assertEqual(json_response['status'], INVALID_INPUT_STATUS)
        self.assertEqual(json_response['errors'],
                         [HOUSE_CODE_NOT_FOUND_MSG.format('FA-33')])

        # user inputs empty string for the colour
        self.initialise_page()
        self.house_code_input.send_keys('FA-32')
        self.form.submit()
        json_response = self.get_json_response()
        self.assertEqual(json_response['status'], INVALID_INPUT_STATUS)
        self.assertIn(INVALID_LED_COLOUR_MSG.format(''),
                      json_response['errors'])
        self.assertIn(INVALID_LED_STATE_MSG.format(''),
                      json_response['errors'])
        self.assertIn(INVALID_LED_REPEAT_INTERVAL_MSG.format(''),
                      json_response['errors'])
Exemplo n.º 2
0
    def test_main(self):
        # user adds a house code to the database
        self.post_house_code('FA-32')

        # user reloads the api page
        self.initialise_page()
        h2 = self.section.find_element_by_tag_name('h2')
        self.assertEqual(h2.text, 'POST /api/led/<house-code>')
        # user inputs valid input
        self.house_code_input.send_keys('FA-32')
        self.colour_input.send_keys('0')
        self.state_input.send_keys('0')
        self.repeat_interval_input.send_keys('120')
        self.form.submit()
        self.assertEqual(self.browser.current_url, self.server_url + '/api/led/FA-32')
        json_response = self.get_json_response()
        self.assertEqual(json_response['status'], 200)
        self.assertEqual(json_response['content'], None)
        
        # TODO: User needs to be able to see the result
        # Currently the LED post does not affect the cache and is just a dummy function

        # user reloads api page
        # user inputs non existent house code
        self.initialise_page()
        self.house_code_input.send_keys('FA-33')
        self.form.submit()
        json_response = self.get_json_response()
        self.assertEqual(json_response['status'], INVALID_INPUT_STATUS)
        self.assertEqual(json_response['errors'], [HOUSE_CODE_NOT_FOUND_MSG.format('FA-33')])

        # user inputs empty string for the colour
        self.initialise_page()
        self.house_code_input.send_keys('FA-32')
        self.form.submit()
        json_response = self.get_json_response()
        self.assertEqual(json_response['status'], INVALID_INPUT_STATUS)
        self.assertIn(INVALID_LED_COLOUR_MSG.format(''), json_response['errors'])
        self.assertIn(INVALID_LED_STATE_MSG.format(''), json_response['errors'])
        self.assertIn(INVALID_LED_REPEAT_INTERVAL_MSG.format(''), json_response['errors'])
Exemplo n.º 3
0
 def test_blank_state(self):
     hc = HouseCode.objects.create(code='FA-32')
     response = self.client.post('/api/led/FA-32', data={'state': ''})
     response = json.loads(response.content)
     self.assertEqual(response['status'], INVALID_INPUT_STATUS)
     self.assertIn(INVALID_LED_STATE_MSG.format(''), response['errors'])
Exemplo n.º 4
0
 def test_blank_state(self):
     hc = HouseCode.objects.create(code='FA-32')
     response = self.client.post('/api/led/FA-32', data={'state': ''})
     response = json.loads(response.content)
     self.assertEqual(response['status'], INVALID_INPUT_STATUS)
     self.assertIn(INVALID_LED_STATE_MSG.format(''), response['errors'])