Ejemplo n.º 1
0
 def login(self, args):
     try:
         query = self.get_login_query(args)
         print Request.prettifyxml(query)
         reply = self.request(query)
         print Request.prettifyxml(reply)
     except Error as e:
         Error.die(2, 'failed perform login request')
     error = None
     try:
         response = Response.parsexml(reply)
         data = response.data
         pprint(data)
     except Error as e:
         error = e.message
         data = e.data
     if error is not None and data['result_code'] != '2002':
         Error.die(2, 'bad login response', data)
     print 'LOGIN OK'
Ejemplo n.º 2
0
 def build(config, greeting, args={}):
     if not args.get("login"):
         args["login"] = config["epp"]["login"]
     if not args.get("pw"):
         args["pw"] = config["epp"]["password"]
     if not greeting:
         Error.die(4, "no greeting given")
     greeting = Response.parsexml(greeting)
     if not args.get("objURIs"):
         args["objURIs"] = greeting.get("objURIs")
         for uri in list(args["objURIs"]):
             if not uri in Request.modules:
                 del args["objURIs"][uri]
     if not args.get("extURIs"):
         args["extURIs"] = greeting.get("extURIs")
         for uri in list(args["extURIs"]):
             if not uri in Request.modules:
                 del args["extURIs"][uri]
     return Request.build("epp:login", args)
Ejemplo n.º 3
0
 def build(config, greeting, args={}):
     if not args.get('login'):
         args['login'] = config['epp']['login']
     if not args.get('pw'):
         args['pw'] = config['epp']['password']
     if not greeting:
         Error.die(4, 'no greeting given')
     greeting = Response.parsexml(greeting)
     if not args.get('objURIs'):
         args['objURIs'] = greeting.get('objURIs')
         for uri in args['objURIs']:
             if not uri in Request.modules:
                 args['objURIs'].remove(uri)
     if not args.get('extURIs'):
         args['extURIs'] = greeting.get('extURIs')
         for uri in args['extURIs']:
             if not uri in Request.modules:
                 args['extURIs'].remove(uri)
     args['command'] = 'epp:login'
     return Request.build(args)
Ejemplo n.º 4
0
    def assertRequest(self, query, data):
        request = Request.build(data)
        test = Request.prettifyxml(str(request))

        self.assertEqual(query.strip(), test.strip())
Ejemplo n.º 5
0
 def test_get_xml_from_xml(self):
     data = self.HELLO_DATA
     xml = str(Request.build(data))
     request = SmartRequest(xml)
     self.assertEqual(xml, request.get_query())
Ejemplo n.º 6
0
class TestSmartRequest(unittest.TestCase):
    def test_get_xml_from_xml(self):
        data = self.HELLO_DATA
        xml = str(Request.build(data))
        request = SmartRequest(xml)
        self.assertEqual(xml, request.get_query())

    def test_get_xml_from_dict(self):
        data = self.HELLO_DATA
        xml = str(Request.build(data))
        request = SmartRequest(data)
        self.assertEqual(xml, request.get_query())

    def test_get_xml_from_json(self):
        data = self.HELLO_DATA
        xml = str(Request.build(data))
        request = SmartRequest(json.dumps(data))
        self.assertEqual(xml, request.get_query())

    def test_perform_xml(self):
        data = self.HELLO_DATA
        xml = str(Request.build(data))
        reply = SmartRequest(xml).perform(self.make_response, self.relogin)
        self.assertEqual(self.make_response(xml), reply)

    def test_perform_dict(self):
        data = self.HELLO_DATA
        xml = str(Request.build(data))
        reply = SmartRequest(data).perform(self.make_response, self.relogin)
        self.assertEqual({'svID': 'test'}, reply)

    def test_perform_json(self):
        data = self.HELLO_DATA
        xml = str(Request.build(data))
        reply = SmartRequest(json.dumps(data)).perform(self.make_response,
                                                       self.relogin)
        self.assertEqual('{"svID": "test"}', reply)

    def test_perform_xml_error(self):
        reply = SmartRequest('test').perform(self.raise_error, self.relogin)
        self.assertEqual(self.TEST_ERROR, reply)

    def test_perform_dict_error(self):
        data = self.HELLO_DATA
        reply = SmartRequest(data).perform(self.raise_error, self.relogin)
        self.assertEqual({'_error': self.TEST_ERROR}, reply)

    def test_perform_json_error(self):
        data = self.HELLO_DATA
        reply = SmartRequest(json.dumps(data)).perform(self.raise_error,
                                                       self.relogin)
        self.assertEqual(json.dumps({'_error': self.TEST_ERROR}), reply)

    HELLO_DATA = {'command': 'epp:hello'}

    HELLO = str(Request.build(HELLO_DATA))

    GREETING = '''<?xml version="1.0" ?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
    <greeting>
        <svID>test</svID>
    </greeting>
</epp>'''

    def make_response(self, query):
        if query == self.HELLO:
            return self.GREETING
        return 'UNKNOWN QUERY'

    def relogin(self):
        pass

    TEST_ERROR = 'test error'

    def raise_error(self, query):
        raise Exception(self.TEST_ERROR)
Ejemplo n.º 7
0
 def test_perform_json(self):
     data = self.HELLO_DATA
     xml = str(Request.build(data))
     reply = SmartRequest(json.dumps(data)).perform(self.make_response,
                                                    self.relogin)
     self.assertEqual('{"svID": "test"}', reply)
Ejemplo n.º 8
0
 def test_perform_dict(self):
     data = self.HELLO_DATA
     xml = str(Request.build(data))
     reply = SmartRequest(data).perform(self.make_response, self.relogin)
     self.assertEqual({'svID': 'test'}, reply)
Ejemplo n.º 9
0
 def test_perform_xml(self):
     data = self.HELLO_DATA
     xml = str(Request.build(data))
     reply = SmartRequest(xml).perform(self.make_response, self.relogin)
     self.assertEqual(self.make_response(xml), reply)