Example #1
0
    def test_decode(self):
        d = ' 20070908T07:11:13  '
        t1 = xmlrpclib.DateTime()
        t1.decode(d)
        tref = xmlrpclib.DateTime(datetime.datetime(2007, 9, 8, 7, 11, 13))
        self.assertEqual(t1, tref)

        t2 = xmlrpclib._datetime(d)
        self.assertEqual(t2, tref)
Example #2
0
 def delete_subscriber_sdp(self, subno):
     dict_response = {'response': -100, 'subno': subno}
     isodatetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetime) + '+0000')
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno,
         "originOperatorID": "EveraldoMenout"
     }
     res = self.run_rpc_command(parameters, 'DeleteSubscriber')
     dict_response['response'] = res[0][0]['responseCode']
     return dict_response
 def test_load_standard_types(self):
     check = self.check_loads
     check('string', 'string')
     check('<string>string</string>', 'string')
     check('<string>𝔘𝔫𝔦𝔠𝔬𝔡𝔢 string</string>', '𝔘𝔫𝔦𝔠𝔬𝔡𝔢 string')
     check('<int>2056183947</int>', 2056183947)
     check('<int>-2056183947</int>', -2056183947)
     check('<i4>2056183947</i4>', 2056183947)
     check('<double>46093.78125</double>', 46093.78125)
     check('<boolean>0</boolean>', False)
     check('<base64>AGJ5dGUgc3RyaW5n/w==</base64>',
           xmlrpclib.Binary(b'\x00byte string\xff'))
     check('<base64>AGJ5dGUgc3RyaW5n/w==</base64>',
           b'\x00byte string\xff',
           use_builtin_types=True)
     check('<dateTime.iso8601>20050210T11:41:23</dateTime.iso8601>',
           xmlrpclib.DateTime('20050210T11:41:23'))
     check('<dateTime.iso8601>20050210T11:41:23</dateTime.iso8601>',
           datetime.datetime(2005, 2, 10, 11, 41, 23),
           use_builtin_types=True)
     check(
         '<array><data><value><int>1</int></value><value><int>2</int></value></data></array>',
         [1, 2])
     check(
         '<struct><member><name>b</name><value><int>2</int></value></member><member><name>a</name><value><int>1</int></value></member></struct>',
         {
             'a': 1,
             'b': 2
         })
 def test_bug_1164912(self):
     d = xmlrpclib.DateTime()
     (new_d, ), dummy = xmlrpclib.loads(
         xmlrpclib.dumps((d, ), methodresponse=True))
     self.assertIsInstance(new_d.value, str)
     s = xmlrpclib.dumps((new_d, ), methodresponse=True)
     self.assertIsInstance(s, str)
Example #5
0
    def update_tempblock(self, subno, flag=True):
        dict_response = {'response': -100, 'subno': subno}
        isodatetime = client.DateTime(time.time())
        transdate = client.DateTime(str(isodatetime) + '+0000')
        parameters = {
            "originNodeType": "EXT",
            "originHostName": "SHAREDACCOUNT",
            "originTransactionID": "123455",
            "originTimeStamp": transdate,
            "subscriberNumberNAI": 2,
            "subscriberNumber": subno,
            'temporaryBlockedFlag': flag
        }
        res = self.run_rpc_command(parameters, 'UpdateTemporaryBlocked')

        dict_response['response'] = res[0][0]['responseCode']
        return dict_response
Example #6
0
 def run_rpc_command(self, params, method):
     response = None
     try:
         isodatetimetime = client.DateTime(time.time())
         transdate = client.DateTime(str(isodatetimetime) + '+0000')
         params["originTimeStamp"] = transdate
         xml_request = client.dumps((params, ), method)
         #print(params)
         self.headers['Content-length'] = len(xml_request)
         self.rpcserver.request("POST", "/Air", "", self.headers)
         self.rpcserver.send(xml_request.encode())
         rpc_response = self.rpcserver.getresponse()
         xml_response = rpc_response.read()
         response = client.loads(xml_response)
     except client.Fault as e:
         print("There is an error. FaultError: {}, FaultString: {}".format(
             e.faultCode, e.faultString))
     return response
Example #7
0
 def install_subscriber_sdp(self, subno, serv_class, is_blocked):
     dict_response = {'response': -100, 'subno': subno}
     isodatetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetime) + '+0000')
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno,
         "originOperatorID": "EveraldoMenout",
         "serviceClassNew": serv_class,
         'temporaryBlockedFlag': is_blocked
     }
     res = self.run_rpc_command(parameters, 'InstallSubscriber')
     dict_response['response'] = res[0][0]['responseCode']
     return dict_response
Example #8
0
 def delete_offer(self, subno, offer_id):
     dict_response = {'response': -100, 'subno': subno}
     isodatetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetime) + '+0000')
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno,
         "offerID": offer_id
     }
     self.headers['User-Agent'] = 'GPRSBUNDLE/4.2/1.0'
     res = self.run_rpc_command(parameters, 'DeleteOffer')
     self.headers['User-Agent'] = 'GPRSBUNDLE/4.0/1.0'  # Turn to default
     dict_response['response'] = res[0][0]['responseCode']
     return dict_response
Example #9
0
 def get_balance_date(self, subno, ded_account_id=2):
     dict_response = {'response': -100, 'subno': subno}
     isodatetimetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetimetime) + '+0000')
     params = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno
     }
     res = self.run_rpc_command(params, 'GetBalanceAndDate')
     response_code = res[0][0]['responseCode']
     dict_response['response'] = response_code
     if response_code == 0:
         dict_response['ma'] = int(res[0][0]['accountValue1']) / 100
         davalue = self.get_da_amount2(
             res[0][0]['dedicatedAccountInformation'], ded_account_id)
         dict_response['da'] = int(davalue)
     return dict_response
Example #10
0
 def test_datetime_before_1900(self):
     dt = datetime.datetime(1, 2, 10, 11, 41, 23)
     self.assertEqual(dt, xmlrpclib.DateTime('00010210T11:41:23'))
     s = xmlrpclib.dumps((dt, ))
     result, m = xmlrpclib.loads(s, use_builtin_types=True)
     newdt, = result
     self.assertEqual(newdt, dt)
     self.assertIs(type(newdt), datetime.datetime)
     self.assertIsNone(m)
     result, m = xmlrpclib.loads(s, use_builtin_types=False)
     newdt, = result
     self.assertEqual(newdt, dt)
     self.assertIs(type(newdt), xmlrpclib.DateTime)
     self.assertIsNone(m)
Example #11
0
 def set_offer(self, subno, offer_id, offer_type=0, expiry_date=None):
     dict_response = {'response': -100, 'subno': subno}
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno,
         "offerID": offer_id,
         "offerType": offer_type
     }
     if expiry_date != None:
         if offer_type == OfferTypes['NORMAL']:
             parameters['expiryDate'] = client.DateTime(expiry_date +
                                                        '+0000')
         else:
             parameters['expiryDateTime'] = client.DateTime(expiry_date +
                                                            '+0000')
     self.headers['User-Agent'] = 'GPRSBUNDLE/4.2/1.0'
     res = self.run_rpc_command(parameters, 'UpdateOffer')
     self.headers['User-Agent'] = 'GPRSBUNDLE/4.0/1.0'  # Turn to default
     dict_response['response'] = res[0][0]['responseCode']
     return dict_response
Example #12
0
 def update_balance_date(self, subno, amount, isabsolute=False):
     if type(amount) != float and type(amount) != int:
         raise ValueError(
             "amount should be an int or float. A string was passed instead."
         )
     amount = round(amount * 100)
     isodatetimetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetimetime) + '+0000')
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno,
         "transactionCurrency": "CFA"
     }
     if isabsolute:
         parameters['mainAccountValueNew'] = str(amount)
     else:
         parameters['adjustmentAmountRelative'] = str(amount)
     res = self.run_rpc_command(parameters, 'UpdateBalanceAndDate')
     return res[0][0]['responseCode']
Example #13
0
 def get_user_details(self, subno):
     dict_response = {'response': -100, 'subno': subno}
     isodatetimetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetimetime) + '+0000')
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno
     }
     res = self.run_rpc_command(parameters, 'GetAccountDetails')
     response_code = res[0][0]['responseCode']
     dict_response['response'] = response_code
     if response_code == 0:
         dict_response['sc'] = res[0][0]['serviceClassCurrent']
         dict_response['languageId'] = res[0][0]['languageIDCurrent']
         dict_response['isActive'] = res[0][0]['accountFlags'][
             'activationStatusFlag']
         if (dict_response['isActive']):
             dict_response['activationDate'] = res[0][0]['activationDate']
     return dict_response
Example #14
0
 def get_offers(self, subno):
     dict_response = {'response': -100, 'subno': subno}
     isodatetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetime) + '+0000')
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "offerRequestedTypeFlag": "11111111",
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno
     }
     self.headers['User-Agent'] = 'GPRSBUNDLE/4.2/1.0'
     res = self.run_rpc_command(parameters, 'GetOffers')
     self.headers['User-Agent'] = 'GPRSBUNDLE/4.0/1.0'  # Turn to default
     response_code = res[0][0]['responseCode']
     dict_response['response'] = response_code
     offers = []
     offer_type = -1
     if response_code == 0:
         if 'offerInformation' in res[0][0]:
             for offer in res[0][0]['offerInformation']:
                 dict_offers = {}
                 offer_type = offer['offerType']
                 dict_offers['offerType'] = offer_type
                 dict_offers['offerId'] = offer['offerID']
                 if offer_type == 2:
                     dict_offers['startDate'] = offer['startDateTime']
                     dict_offers['expiryDate'] = offer['expiryDateTime']
                 else:
                     dict_offers['startDate'] = offer['startDate']
                     dict_offers['expiryDate'] = offer['expiryDate']
                 offers.append(dict_offers)
     dict_response['offers'] = offers
     return dict_response
Example #15
0
 def update_da_balance(self, subno, daid, amount, expiry_date=None):
     amount = amount * 100
     isodatetimetime = client.DateTime(time.time())
     transdate = client.DateTime(str(isodatetimetime) + '+0000')
     dedicated_account = {
         'dedicatedAccountID': daid,
         'adjustmentAmountRelative': str(amount)
     }
     if expiry_date != None:
         exp_date = client.DateTime(expiry_date + '+0000')
         dedicated_account['expiryDate'] = exp_date
     dalist = [dedicated_account]
     parameters = {
         "originNodeType": "EXT",
         "originHostName": "SHAREDACCOUNT",
         "originTransactionID": "123455",
         "originTimeStamp": transdate,
         "subscriberNumberNAI": 2,
         "subscriberNumber": subno,
         "transactionCurrency": "CFA",
         'dedicatedAccountUpdateInformation': dalist
     }
     res = self.run_rpc_command(parameters, 'UpdateBalanceAndDate')
     return res[0][0]['responseCode']
Example #16
0
def create_draft(post, 
                 title, 
                 categories, 
                 tags, 
                 user, 
                 password):
    """It will create the draft post to the defined wordpress site.
    
    Params:
    =======
    
    post: str
        A string with the converted Jupyter notebook.
    title: str
        The title for the post.
    categories: str
        The categories related with the post. They should already exist.        
    tags: str
        The tags for the post.
    user: str
        The admin of the wordpress site.
    password: str
        The password for the admin of the wordpress site.
    """
    date_created = xmlrpclib.DateTime(datetime.datetime.now())
    status_published = 0
    wp_blogid = ""
    data = {'title': title, 
            'description': post,
            'post_type': 'post',
            'dateCreated': date_created,
            'mt_allow_comments': 'open',
            'mt_allow_pings': 'open',
            'post_status': 'draft',
            'categories': categories, 
            'mt_keywords': tags}
    post_id = server.metaWeblog.newPost(wp_blogid, 
                                        user, 
                                        password, 
                                        data, 
                                        status_published)
    print()
    print('It seems all worked fine!! Check your wordpress site admin.')
    print()
Example #17
0
    def test_current_time(self):
        # Get the current time from xmlrpc.com.  This code exercises
        # the minimal HTTP functionality in xmlrpclib.
        self.skipTest("time.xmlrpc.com is unreliable")
        server = xmlrpclib.ServerProxy("http://time.xmlrpc.com/RPC2")
        try:
            t0 = server.currentTime.getCurrentTime()
        except socket.error as e:
            self.skipTest("network error: %s" % e)

        # Perform a minimal sanity check on the result, just to be sure
        # the request means what we think it means.
        t1 = xmlrpclib.DateTime()

        dt0 = xmlrpclib._datetime_type(t0.value)
        dt1 = xmlrpclib._datetime_type(t1.value)
        if dt0 > dt1:
            delta = dt0 - dt1
        else:
            delta = dt1 - dt0
        # The difference between the system time here and the system
        # time on the server should not be too big.
        self.assertTrue(delta.days <= 1)