예제 #1
0
    def test_unsub(self):
        res = self.app.post(h.url_for(controller='event'), params={'name' : 'nte'})
        urls = fromjson(res.body)
        fire_url = urls['fire']
        subscribe_url = urls['subscribe']

        #subscribe and send a message
        res = self.app.post(subscribe_url, params={'url' : 'http://localhost:10424/morx/fleem', 'method' : 'POST'})
        unsubscribe_url = fromjson(res.body)['unsubscribe']
        
        res = self.app.post(fire_url, params={'morx' : [1], 'fleem' : 2})
        assert fromjson(res.body) == {'status' : "accepted"}

        send_all_pending_events(res)

        #now unsubscribe and send a message
        res = self.app.post(unsubscribe_url)
        assert fromjson(res.body) == {'status' : 'unsubscribed'}
        
        res = self.app.post(fire_url, params={'morx' : [1], 'fleem' : 2})
        assert fromjson(res.body) == {'status' : "accepted"}        
        
        send_all_pending_events(res)

        #we only get the first message
        server_fixture = test_server.server_fixture
        assert server_fixture.requests_received == [{'path': '/morx/fleem', 'params': MultiDict([('fleem', '2'), ('morx', '[1]')]), 'method': 'POST'}]
예제 #2
0
    def test_redirect(self):
        res = self.app.post(h.url_for(controller='event'), params={'name' : 'test_event'})
        urls = fromjson(res.body)
        fire_url = urls['fire']
        subscribe_url = urls['subscribe']
        res = self.app.post(subscribe_url, params={'url' : 'http://localhost:10424/elsewhere', 'method' : 'POST', 'redirections': 0})
        
        res = self.app.post(fire_url, params={'morx' : [1], 'fleem' : 2})
        assert fromjson(res.body) == {'status' : "accepted"}

        send_all_pending_events(res)

        server_fixture = test_server.server_fixture
        assert server_fixture.requests_received == [{'path': '/elsewhere', 'params': MultiDict([('fleem', '2'), ('morx', '[1]')]), 'method': 'POST'}]
예제 #3
0
def decode_encoding_json(text):
    from simplejson import JSONDecodeError
    try:
        return fromjson(text, object_hook=adict)

    except JSONDecodeError:
        text = text.strip()

        if text.startswith('new Object('):
            text = text[11:]
        if text.endswith(')'):
            text = text[:-1]
        text = text.replace("'", '"')

        return fromjson(text, object_hook=adict)
예제 #4
0
    def parse_results(text):
        result = fromjson(text, object_hook=adict)

        if 'errors' in result.response:
            raise RuntimeError(result.response.errors)

        return result.response
예제 #5
0
    try:
        status, body = rest_invoke(server_url + "/event/", method="GET", resp=True)
    except socket.error, e:
        raise RuntimeError("You need a Cabochon server running on port 24532", e)

    if status['status'] != '200':
        raise RuntimeError("You need a Cabochon server running on port 24532")

    event_name = "cabochon_server_library_test_event"

    installer = ServerInstaller(".servers", username=username, password=password)
    installer.addEvent(server_url, event_name, "http://localhost:10424/example/1")
    installer.save()

    #get the fire url

    urls = fromjson(rest_invoke(server_url + "/event", method="POST", params={'name':event_name}))
    fire_url = urls['fire']

    #fire the event
    rest_invoke(server_url + fire_url, method="POST", params={'morx':'fleem'})

    #wait a second
    time.sleep(1)
    #insure that we got it
    assert server_fixture.requests_received == [{'path': '/example/1', 'params': MultiDict([('morx', '"fleem"')]), 'method': 'POST'}], "Actually got %s" % server_fixture.requests_received

    installer2 = ServerInstaller(".servers")

    os.remove(".servers")