def set_customer(self, customer): if customer != BASE_DATABASE: c = self.find({'domain': customer}) if c.data is not None: return MongoEngine().set_collection_name(c.data['db_name']) else: MongoEngine().set_collection_name(BASE_DATABASE)
def __init__(self, *args, **kwargs): super(AnsibleEngineTests, self).__init__(*args, **kwargs) # Drop previous database Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'hosts') MongoEngine().drop_collection(TESTING_DATABASE, 'playbooks')
def __init__(self, *args, **kwargs): super(DumpTests, self).__init__(*args, **kwargs) # Drop previous database Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'hosts') MongoEngine().drop_collection(TESTING_DATABASE, 'playbooks') self.root = './' self.base_path = 'files-generated' self.domain = 'domain.com' self.sub_path_hosts = 'hosts' self.sub_path_playbooks = 'playbooks'
def get(): mongo = MongoEngine().status() docker = DockerEngine().status() hc = mongo['is_up'] and docker['is_up'] code = 200 if hc else 500 return { 'ok': hc }, code
def get(): user = Login().get_username(request.headers['x-access-token']) is_admin = User().is_admin(user) return { 'mongo': MongoEngine().status(is_admin), 'docker': DockerEngine().status() }, 200
def is_customer(self, customer): MongoEngine().set_collection_name(BASE_DATABASE) if customer == '': return True elif customer != BASE_DATABASE: c = self.find({'domain': customer}) if c.data is not None and c.data['enabled']: return True return False
def setUp(self): Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'users') User().insert({ 'type': 'admin', 'first_name': 'admin', 'last_name': 'admin', 'username': '******', 'email': '*****@*****.**', 'password': '******' })
def setUp(self): Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'customers') User().insert({ 'type': 'admin', 'first_name': 'admin-user', 'last_name': 'admin-user', 'username': '******', 'email': 'admin-user', 'password': '******' }) logged_user = Login().login(Auth('admin-user', 'admin-user')) self.headers = { 'Content-Type': 'application/json', 'x-access-token': logged_user.data['token'] }
def __new__(cls, *args, **kwargs): if not cls.engine: cls.engine = super(TestingLogin, cls).__new__(cls, *args, **kwargs) Customer().set_customer(TESTING_DATABASE) MongoEngine().drop(TESTING_DATABASE) User().insert({ 'type': 'admin', 'first_name': 'admin', 'last_name': 'admin', 'username': '******', 'email': '*****@*****.**', 'password': '******' }) logged_user = Login().login(Auth('admin', 'admin')) cls.headers = { 'Content-Type': 'application/json', 'x-access-token': logged_user.data['token'] } return cls.engine
def insert(self, item=None): if item is None or not item or \ 'domain' not in item or 'db_name' not in item: return False self.set_customer(BASE_DATABASE) if MongoEngine().get_client() is not None: found = self.find(criteria={ 'domain': item['domain'], 'db_name': item['db_name'] }, projection={ 'domain': 1, 'db_name': 1 }).data if found is not None: return False insertion = super().insert(data=item) return insertion
def __init__(self, *args, **kwargs): super(UserTests, self).__init__(*args, **kwargs) # Drop previous database Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'users')
def setUp(self): Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'hosts') MongoEngine().drop_collection(TESTING_DATABASE, 'playbooks')
def cursor(self): if self.table_name != '': return MongoEngine().get_client()[self.table_name] return None
def setUp(self): Customer().set_customer(TESTING_DATABASE) MongoEngine().drop_collection(TESTING_DATABASE, 'machines')