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
 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
Esempio n. 4
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 = extract(body=json, path='$.url')

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

        r = self._user.post(url=url, payload=payload)
        return r
Esempio n. 5
0
    def restore_db(self, directory=None):
        print('> Restoring local MongoDB files...')
        with open(self._config_path, 'r+') as f:
            config = f.read()
            config = string_to_json(config)

            home = extract(body=config, path='$.homedir')
            backup = extract(body=config, path='$.backupdir')

        if not os.path.isdir(home):
            print('The path specified for home does not exist: %s' % home)
            sys.exit(1)
        if not os.path.isdir(backup):
            print('The path specified for backup does not exist: %s' % backup)
            sys.exit(1)

        all_subdirs = [d for d in os.listdir(backup) if os.path.isdir(backup)]
        latest_subdir = max(all_subdirs)

        home = os.path.join(os.path.abspath(home), 'mongorestore.exe')
        if directory:
            restore = os.path.join(backup, directory)
        else:
            restore = os.path.join(backup, latest_subdir)

        try:
            if os.path.exists(home):
                if os.path.exists(restore):
                    print('Restoring files from: %s' % restore)
                    subprocess.run('%s %s' % (home, restore))
                    print(
                        '> Updating mongo_tools_config.json file last update.')
                    with open(self._config_path, 'w+') as f:
                        config = update_json(
                            body=config,
                            values={'$.lastupdate': latest_subdir})
                        config = dumps(config)
                        f.write(config)
                    print('> Backup done!')
                else:
                    raise ValueError
            else:
                raise ValueError
        except Exception as e:
            print('Could not find make restore.')
            print('Check paths: \n homedir: %s \n restore from: %s' %
                  (home, restore))
            print('Error thrown: \n %s' % e)
Esempio n. 6
0
    def backup_db(self, backup_url=None):
        print('> Starting backup...')
        with open(self._config_path, 'r+') as f:
            config = f.read()
            config = string_to_json(config)

            home = extract(body=config, path='$.homedir')
            backup = extract(
                body=config,
                path='$.backupdir') if not backup_url else backup_url

        if not os.path.isdir(home):
            print('The path specified for home does not exist: %s' % home)
            sys.exit()
        if not os.path.isdir(backup):
            print('The path specified for backup does not exist: %s' % backup)
            sys.exit()

        timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
        output = os.path.join(backup, timestamp)
        os.mkdir(output)

        home = os.path.join(os.path.abspath(home), 'mongodump.exe')

        try:
            if os.path.exists(home):
                if os.path.exists(output):
                    print('> Making backup in: %s' % output)
                    subprocess.run('%s --out %s' % (home, output))
                    print(
                        '> Updating mongo_tools_config.json file last update.')
                    with open(self._config_path, 'w+') as f:
                        config = update_json(
                            body=config, values={'$.lastupdate': timestamp})
                        config = dumps(config)
                        f.write(config)
                    print('> Backup done!')
                else:
                    raise ValueError
            else:
                raise ValueError
        except ValueError as e:
            os.removedirs(output)
            if not os.path.exists(backup):
                os.mkdir(backup)
            print('Could not find paths. Backup directory was deleted.')
            print('Check paths: \n homedir: %s \n backupdir: %s' %
                  (home, output))
Esempio n. 7
0
    def config_db(self, **kwargs):
        print('> Updating path..')
        with open(self._config_path, 'r') as f:
            data = f.read()
            data = string_to_json(data)

            json_values = dict()
        for k in kwargs.keys():
            json_values['$.%s' % k] = kwargs[k]

        data = update_json(body=data,
                           values=json_values) if json_values else None

        if data:
            with open(self._config_path, 'w') as f:
                data = dumps(data)
                f.write(data)
Esempio n. 8
0
    def login(self):
        api = ConfigLogin().configure_test_data_login(env=self._env)
        headers = api.get("headers")
        body = api.get("body")

        body = update_json(body=body, values={
            "username": self._user,
            "password": self._password
        })

        url = api.get("url")
        self._session = self.post(url=url, data=body, headers=headers, login=True)
        self.store_session_id(response=self._session)
        self.store_user_roles(response=self._session)

        print('\n User logged in: %s' % self._user)
        print('LegalEntity chosen: %s' % self._legal_entity)
        print('-' * 20)

        return self._session