Esempio n. 1
0
    def test_templateResponse(self):
        '''This tests the setMockRespond method using a template
        the format of the string.
        '''
        # Register the template that will be used later with the key-value pairs.
        mslclient.registerTemplate("localhost", "8001",
                "[{\"label\":\"{{param1}}\"},{\"label\":\"{{param2}}\"}]", "example")

        # Clear the autocomplete to make sure this test starts from scratch.
        autocomplete = chrome.find_element_by_id('autocomplete')        

        autocomplete.clear()
        chrome.find_element_by_id('postRequest').click()
        time.sleep(1)

        # Setup all of the needed data like request path, key-value pairs, and template id.        
        configurations = {}
        configurations["requestPath"] = "/services/getlanguages"
        configurations["contentType"] = "application/json"
        configurations["statusCode"] = "200"
        configurations["delayTime"] = "0"
        
        # The values that are to replace the keys in the registered template.
        keyVals = {}
        keyVals["param1"] = "German"
        keyVals["param2"] = "English"
        
        configurations["keyValues"] = keyVals
        configurations["id"] = "example"
        
        # Actually make the call  to register this information.
        mslclient.setMockRespond("localhost", "8001", configurations)

        # Trigger event that fires off request.
        autocomplete.send_keys('J')
        
        time.sleep(1)
        # Grab the dropdown elements and validate the data against the registered response.
        elementOne = chrome.find_element_by_xpath('.//ul[contains(@class, "ui-autocomplete")]/li[1]')
        elementTwo = chrome.find_element_by_xpath('.//ul[contains(@class, "ui-autocomplete")]/li[2]')

         
        assert elementOne.get_attribute("textContent") == 'German'
        assert elementTwo.get_attribute("textContent") == 'English'
        
        autocomplete.clear()
Esempio n. 2
0
    def test_unRegisterMock(self):
        '''This is used to test unregistering a request path.'''

        # Clear the autocomplete to make sure this test starts from scratch.
        autocomplete = chrome.find_element_by_id('autocomplete')        

        autocomplete.clear()
        chrome.find_element_by_id('postRequest').click()
        time.sleep(1)

        # Setup all of the needed data like request path, the response, function
        # for formatting, etc.
        configurations = {}
        configurations["requestPath"] = "/services/getlanguages"
        configurations["responseText"] = "{\"label\":\"Java\"},{\"label\":\"Perl\"}"
        configurations["contentType"] = "application/json"
        configurations["eval"] = "function (req,responseText) { return '[' + responseText + ']'; }"
        configurations["statusCode"] = "200"
        configurations["delayTime"] = "0"
        
        # Actually make the call  to register this information.
        mslclient.setMockRespond("localhost", "8001", configurations)
        
        # Trigger event that fires off request.
        autocomplete.send_keys('J')
        
        time.sleep(1)

        # Grab the dropdown elements and validate the data against the registered response to
        # make sure the initial register worked.
        elementOne = chrome.find_element_by_xpath('.//ul[contains(@class, "ui-autocomplete")]/li[1]')
        elementTwo = chrome.find_element_by_xpath('.//ul[contains(@class, "ui-autocomplete")]/li[2]')

         
        assert elementOne.get_attribute("textContent") == 'Java'
        assert elementTwo.get_attribute("textContent") == 'Perl'

        # Unregister the request path
        mslclient.unRegisterMock("localhost", "8001", '/services/getlanguages')
        autocomplete.clear()
        chrome.find_element_by_id('postRequest').click()

        autocomplete.send_keys('J')
        assert elementOne.is_displayed() == False