Exemple #1
0
    def get(self, serviceName=None):
        parser_dict = LogParser.parseGetParameters()
        if serviceName is None:
            serviceName = getDbName()

        return getLog(serviceName, parser_dict[NUMBER], parser_dict[OFFSET],
                      dateDeserialiser(parser_dict, DATE_FROM),
                      dateDeserialiser(parser_dict, DATE_TO))
Exemple #2
0
def findUsers(number, offset, loginSubstring):
    collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]
    result = list(
        collectionUsers.find({
            LOGIN: {
                '$regex': ".*" + loginSubstring + ".*"
            }
        }).skip(offset).sort(LOGIN).limit(number))
    return result
def addUser(_id, firstName, lastName, email, login):
    return_id = _id
    try:
        findUserById(_id)
    except UserDoesNotExist:
        collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]
        collectionUsers.insert(
            {FIND_KEY_ID: _id, FIRST_NAME: firstName, LAST_NAME: lastName,
             EMAIL: email, LOGIN: login})
    finally:
        return_id = _id
    return return_id
Exemple #4
0
def addUser(_id, firstName, lastName, email, login):
    return_id = _id
    try:
        findUserById(_id)
    except UserDoesNotExist:
        collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]
        collectionUsers.insert(
            {FIND_KEY_ID: _id, FIRST_NAME: firstName, LAST_NAME: lastName, EMAIL: email, LOGIN: login}
        )
    finally:
        return_id = _id
    return return_id
Exemple #5
0
def addLogEntry(dbName, userId, message, level, service='instance'):
    currentDate = datetime.now()
    collection = getDbObject(dbName)[LOG]
    if dbName == getDbName():
        collection.save({USER_ID: userId, DATE: currentDate,
                         MESSAGE: message, LEVEL: level, SERVICE: service})
    else:
        collection.save({
            USER_ID: userId,
            DATE: currentDate,
            MESSAGE: message,
            LEVEL: level
        })
Exemple #6
0
    def get(self, serviceName=None):
        parser_dict = LogParser.parseGetParameters()
        if serviceName is None:
            serviceName = getDbName()

        return getLog(
            serviceName,
            parser_dict[NUMBER],
            parser_dict[OFFSET],
            dateDeserialiser(
                parser_dict,
                DATE_FROM),
            dateDeserialiser(
                parser_dict,
                DATE_TO))
Exemple #7
0
def addLogEntry(dbName, userId, message, level, service='instance'):
    currentDate = datetime.now()
    collection = getDbObject(dbName)[LOG]
    if dbName == getDbName():
        collection.save({
            USER_ID: userId,
            DATE: currentDate,
            MESSAGE: message,
            LEVEL: level,
            SERVICE: service
        })
    else:
        collection.save({
            USER_ID: userId,
            DATE: currentDate,
            MESSAGE: message,
            LEVEL: level
        })
Exemple #8
0
def getDbObject(dbName=getDbName()):
    return getClientObject()[dbName]
Exemple #9
0
def findUsers(number, offset, loginSubstring):
    collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]
    result = list(
        collectionUsers.find({LOGIN: {"$regex": ".*" + loginSubstring + ".*"}}).skip(offset).sort(LOGIN).limit(number)
    )
    return result
Exemple #10
0
import unittest
import pymongo
from db_model import addLogEntry, getDbObject, getClientObject
from config_reader import getDbName
from log import LOG_LVL_INFO
from log import LOG_LVL_CRITICAL

client = getClientObject()

# DB
TEST_DB = 'testservice'
TEST_DB_MASTER = getDbName()

# VALUES
TEST_USER_ID = 'test_user_id'
TEST_MSG = 'test_msg'
TEST_SERVICE = 'service'
TEST_LOG_LEVEL_INFO = LOG_LVL_INFO
TEST_LOG_LEVEL_CRITICAL = LOG_LVL_CRITICAL
# COLLECTIONS
LOG = 'log'

# FIELDS
TEST_USER_ID_FIELD = 'user_id'
TEST_MSG_FIELD = 'message'
TEST_SERVICE_FIELD = 'service'
TEST_LEVEL_FIELD = 'level'

db = getDbObject(TEST_DB)
db_master = getDbObject(TEST_DB_MASTER)
Exemple #11
0
# Collections
TAGS = 'tags'
COLLECTION = 'services'
NAME = 'name'
CONFIG = 'config'
LOG_SIZE = 'log_size'
OWNERID = 'owner_id'
ID = '_id'
LOG = 'log'
BC = 'bc'
METADATA = 'metadata'

# db initialisation
MONGO_CLIENT = None  # MongoClient(getHost(), getPort())

db = MongoClient(getHost(), getPort())[getDbName()]
# keys
USER_ID = 'user_id'
DATE = 'date'
MESSAGE = 'message'
LEVEL = 'level'
ERROR_CODE = 'error_code'
SERVICE = 'service'
COLLECTION = 'services'
CHANNELS_COLLECTION = 'channels'
POINTS_COLLECTION = 'points'
JSON = 'json'
ACL = 'acl'
OWNER_GROUP = 'owner_group'
POINTS_COLLECTION = 'points'
LOCATION = 'location'
import unittest
from datetime import datetime
from db_model import addLogEntry, getDbObject
from config_reader import getDbName
from log import LOG_LVL_INFO
# DB
TEST_DB = getDbName()

# VALUES
TEST_USER_ID = 'fix_test_user_id'
TEST_MSG = 'test_msg'
TEST_SERVICE = 'service'

# COLLECTIONS
LOG = 'log'

# Fields
DATE = 'date'

db = getDbObject()


class TestFixForAddLogEntry(unittest.TestCase):

    def testFixForAddLogEntry(self):
        addLogEntry(TEST_DB, TEST_USER_ID, TEST_MSG, LOG_LVL_INFO)
        objects = list(db[LOG].find())
        obj = objects[len(objects) - 1]
        self.assertEqual(type(obj[DATE]), datetime)
 def testDbName(self):
     self.assertEqual(DBNAME, config_reader.getDbName())
from flask import Flask
from unittest import TestCase
from config_reader import getDbName
from db_model import getDbObject
from user_routines import addUser

COLLECTION_NAME_USERS = "users"

TEST_ID = 'test_user_id'
TEST_FIRSTNAME = 'test_user_fn'
TEST_LASTNAME = 'test_user_ln'
TEST_EMAIL = '*****@*****.**'
TEST_LOGIN = '******'
TEST_ID_NONE = None

collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]

app = Flask(__name__)


class TestaddUserById(TestCase):
    def testaddUserById(self):
        collectionUsers.drop()
        result_id = addUser(TEST_ID, TEST_FIRSTNAME, TEST_LASTNAME, TEST_EMAIL,
                            TEST_LOGIN)
        self.assertEqual(TEST_ID, result_id)
        user = collectionUsers.find_one({'_id': result_id})
        self.assertEqual(TEST_ID, user.get('_id'))
        self.assertEqual(TEST_LOGIN, user.get('login'))
        self.assertEqual(TEST_EMAIL, user.get('email'))
        self.assertEqual(TEST_LASTNAME, user.get('last_name'))
Exemple #15
0
def findUserById(_id):
    collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]
    userById = collectionUsers.find_one({FIND_KEY_ID: _id})
    if userById is not None:
        return userById
    raise UserDoesNotExist
Exemple #16
0
# Collections
TAGS = 'tags'
COLLECTION = 'services'
NAME = 'name'
CONFIG = 'config'
LOG_SIZE = 'log_size'
OWNERID = 'owner_id'
ID = '_id'
LOG = 'log'
BC = 'bc'
METADATA = 'metadata'

# db initialisation
MONGO_CLIENT = None  # MongoClient(getHost(), getPort())

db = MongoClient(getHost(), getPort())[getDbName()]
# keys
USER_ID = 'user_id'
DATE = 'date'
MESSAGE = 'message'
LEVEL = 'level'
ERROR_CODE = 'error_code'
SERVICE = 'service'
COLLECTION = 'services'
CHANNELS_COLLECTION = 'channels'
POINTS_COLLECTION = 'points'
JSON = 'json'
ACL = 'acl'
OWNER_GROUP = 'owner_group'
POINTS_COLLECTION = 'points'
LOCATION = 'location'
Exemple #17
0
import unittest
from datetime import datetime
from db_model import addLogEntry, getDbObject
from config_reader import getDbName
from log import LOG_LVL_INFO
# DB
TEST_DB = getDbName()

# VALUES
TEST_USER_ID = 'fix_test_user_id'
TEST_MSG = 'test_msg'
TEST_SERVICE = 'service'

# COLLECTIONS
LOG = 'log'

# Fields
DATE = 'date'

db = getDbObject()


class TestFixForAddLogEntry(unittest.TestCase):
    def testFixForAddLogEntry(self):
        addLogEntry(TEST_DB, TEST_USER_ID, TEST_MSG, LOG_LVL_INFO)
        objects = list(db[LOG].find())
        obj = objects[len(objects) - 1]
        self.assertEqual(type(obj[DATE]), datetime)
Exemple #18
0
def getDbObject(dbName=getDbName()):
    return getClientObject()[dbName]
from flask import Flask
from unittest import TestCase
from config_reader import getDbName
from db_model import getDbObject
from user_routines import findUserById
from user_does_not_exist import UserDoesNotExist

COLLECTION_NAME_USERS = "users"

FIELD_USER_ID = "_id"

USER_ID = "user_id"
GOOD_USER_ID = "user_id_5"

collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]

app = Flask(__name__)


class TestFindUserById(TestCase):

    def setUp(self):
        for i in range(10):
            collectionUsers.insert(
                {
                    FIELD_USER_ID: USER_ID + "_" + unicode(i),
                    "first_name": "string",
                    "last_name": "string"
                }
            )
Exemple #20
0
def findUserById(_id):
    collectionUsers = getDbObject(getDbName())[COLLECTION_NAME_USERS]
    userById = collectionUsers.find_one({FIND_KEY_ID: _id})
    if userById is not None:
        return userById
    raise UserDoesNotExist
Exemple #21
0
import unittest
import pymongo
from db_model import addLogEntry, getDbObject, getClientObject
from config_reader import getDbName
from log import LOG_LVL_INFO
from log import LOG_LVL_CRITICAL

client = getClientObject()

# DB
TEST_DB = "testservice"
TEST_DB_MASTER = getDbName()

# VALUES
TEST_USER_ID = "test_user_id"
TEST_MSG = "test_msg"
TEST_SERVICE = "service"
TEST_LOG_LEVEL_INFO = LOG_LVL_INFO
TEST_LOG_LEVEL_CRITICAL = LOG_LVL_CRITICAL
# COLLECTIONS
LOG = "log"

# FIELDS
TEST_USER_ID_FIELD = "user_id"
TEST_MSG_FIELD = "message"
TEST_SERVICE_FIELD = "service"
TEST_LEVEL_FIELD = "level"

db = getDbObject(TEST_DB)
db_master = getDbObject(TEST_DB_MASTER)
Exemple #22
0
def writeInstanceLog(userId, message, level, service='instance'):
    addLogEntry(getDbName(), userId, message, level, service)