Esempio n. 1
0
    def patch_case_request_title(self,
                                 case_request=None,
                                 case_request_id=None,
                                 payload=None):
        if not case_request and case_request_id:
            case_request = self.get_case_request_by_id(
                case_request_id=case_request_id)
        elif not case_request:
            raise ValueError(
                'Must specify case object or case id to patch description.')

        url = extract(body=case_request.json(),
                      path="$.links[?(@.rel=='modifytitle')].href")

        json = MongoDBConnection(db='TestData', coll='JsonModels')
        json = json.coll.find_one({'json_model': 'modify_case_request_title'},
                                  {
                                      'payload': 1,
                                      '_id': 0
                                  })

        if not payload:
            payload = json.get('payload')

        payload = update_json(body=payload,
                              values={
                                  '$.caseTitle':
                                  "aut_test_%s" %
                                  datetime.now().strftime("DS1_%Y%m%d_%H%M")
                              })
        r = self._user.patch(url=url, payload=payload)
        return r
Esempio n. 2
0
    def load_test_user_env(country, user_type, legal_entity_id=None):
        users = MongoDBConnection(db='TestData', coll='Users')
        types = MongoDBConnection(db='TestData', coll='UserTypes')

        user_type = types.coll.find_one({'type': user_type})

        if legal_entity_id:
            user = users.coll.find_one({
                'user_type.$id':
                user_type['_id'],
                'env':
                env,
                'country':
                country,
                'legalEntity.legalEntityId':
                legal_entity_id
            })
        else:
            user = users.coll.find_one({
                'user_type.$id': user_type['_id'],
                'env': env,
                'country': country
            })
        if not user:
            skip(
                'User not found, check test data in DB. User info: \n env: %s, country: %s, type: %s'
                % (env, country, user_type['type']))

        return user
    def calculate_opp_bl_body(self, config, values):
        bl_model = MongoDBConnection(db='TestData', coll='JsonModels')
        opp_type = MongoDBConnection(db='TestData', coll='OpportunityTypes')
        opp_type = opp_type.coll.find_one({'type': self._code})

        bl_model = bl_model.coll.find_one({'json_model':'businesslines',
                                           'opportunity_type.$id': opp_type['_id']},
                                          {'payload': 1, '_id':0})['payload']

        bls = []
        for value in values:
            for i in range(0, len(config)):
                if value == config[i]['businessLineId'] and self._code == "O":
                    body_bl = extract(body=bl_model, path='$.opportunityBusinessLines')[0]
                    body_bl = update_json(body=body_bl, values={
                        '$..businessLineId': value,
                        '$..volume.estimated.comment': 'Automated test comment',
                        '$..volume.estimated.quantity.amount': 1000,
                        '$..volume.estimated.quantity.unitOfMeasure.unitId': extract(body=config[i],
                                                                                     path='$.businesslineConfiguration.defaultUnitOfMeasure.unitId')
                    })
                    bls.append(deepcopy(body_bl))
                elif value == config[i]['businessLineId']:
                    body_bl = extract(body=bl_model, path='$.opportunityBusinessLines..businessLine')
                    body_bl = update_json(body=body_bl, values={"$.businessLineId": value})
                    bls.append({"businessLine": deepcopy(body_bl)})

        body = {'opportunityBusinessLines': []}
        body = update_json(body=body, values={'$.opportunityBusinessLines': bls})

        return body
Esempio n. 4
0
    def patch_case_request_description(self,
                                       case_request=None,
                                       case_request_id=None,
                                       payload=None):
        if not case_request and case_request_id:
            case_request = self.get_case_request_by_id(
                case_request_id=case_request_id)
        elif not case_request:
            raise ValueError(
                'Must specify case object or case id to patch description.')

        url = extract(body=case_request.json(),
                      path="$.links[?(@.rel=='modifydescription')].href")

        json = MongoDBConnection(db='TestData', coll='JsonModels')
        json = json.coll.find_one(
            {'json_model': 'modify_case_request_description'}, {
                'payload': 1,
                '_id': 0
            })
        if not payload:
            payload = json.get('payload')

        r = self._user.patch(url=url, payload=payload)
        return r
Esempio n. 5
0
    def post_new_case_request(self, customer_id=None, payload=None):
        json = MongoDBConnection(db='TestData', coll='JsonModels')
        json = json.coll.find_one({'json_model': 'new_case_request'}, {
            'payload': 1,
            'url': 1,
            '_id': 0
        })
        url = json.get('url')

        if not payload and customer_id:
            payload = update_json(body=json.get('payload'),
                                  values={'$..customerId': customer_id})

        r = self._user.post(url=url, payload=payload)
        return r
Esempio n. 6
0
 def get_case_request_by_id(self, case_request_id):
     json = MongoDBConnection(db='TestData', coll='JsonModels')
     json = json.coll.find_one({'json_model': 'new_case_request'}, {
         'url': 1,
         '_id': 0
     })['url']
     url = '/'.join([json, str(case_request_id)])
     case_request = self._user.get(url=url)
     return case_request
 def prepare_contact_payload(self, contact_id):
     payload = MongoDBConnection(db='TestData', coll='JsonModels')
     payload = payload.coll.find_one({'json_model': 'modify_case_contacts'},
                                     {
                                         'payload': 1,
                                         '_id': 0
                                     })['payload']
     payload = update_json(
         body=payload,
         values={'$.caseContacts..contact.contactId': contact_id})
     return payload
 def prepare_case_business_line_payload(self, businessline_id):
     payload = MongoDBConnection(db='TestData', coll='JsonModels')
     payload = payload.coll.find_one(
         {'json_model': 'modify_case_businesslines'}, {
             'payload': 1,
             '_id': 0
         })['payload']
     payload = update_json(
         body=payload,
         values={
             '$.caseBusinessLines..businessLine.businessLineId':
             businessline_id
         })
     return payload
 def __init__(self, user, code):
     super().__init__(user, code)
     self._user = user
     self._code = code
     self._config = super().set_opp_config()
     self._conn = MongoDBConnection(db='TestData', coll='Addresses')
Esempio n. 10
0
 def __init__(self, env, layer):
     self._config = MongoDBConnection(db='TestData', coll='Environments')
     self.env = env
     self.base_url = self.configure_environment(env, layer)
Esempio n. 11
0
 def fetch_db(self, db='TestData', coll=None):
     conn = MongoDBConnection(db=db, coll=coll)
     return conn
Esempio n. 12
0
import argparse
import sys

from scripts.mongo_tools_script.mongo_connection import MongoDBConnection

print('=' * 40)
print('Mongo tools script launched!')
print('=' * 40)
d = MongoDBConnection()

print('> Setting parsers...')
parser = argparse.ArgumentParser(
    description='Set of tools to manipulate test data of local MongoDB.')
parser.add_argument(
    '--backupdir',
    metavar='<OUTPUT_PATH>',
    help='Set path to backup directory where to save the files.')
parser.add_argument(
    '--homedir',
    metavar='<HOMEDIR_PATH>',
    help='Set path to home directory where MongoDB is installed.')
parser.add_argument(
    '-r',
    '--restore',
    default=0,
    const=1,
    action='store_const',
    help='Set this flag to restore TestData files. Usually used after backup.')
parser.add_argument(
    '-d',
    '--dump',