Exemplo n.º 1
0
def fillup_db():
    DB['rooms'].append(Room(42, 1, 'closed', 1000))
    DB['rooms'].append(Room(7, 1, 'available', 50))
    DB['rooms'].append(Room(69, 7, 'available', 9000))
    DB['rooms'].append(Room(11, 3, 'closed', 10))

    DB['tenants'].append(Tenant('Neo', 'zz0101', 33, 'M',
                                {
                                    "city": "Zeon",
                                    "street": "Street 255"
                                }, 42))
    DB['tenants'].append(Tenant('Janis', 'bb2222', 40, 'W',
                                {
                                    "city": "Los Angeles",
                                    "street": "Beverly Hills, 90210"
                                }, 7))
    DB['tenants'].append(Tenant('Sherlock', 'cc3333', 51, 'M',
                                {
                                    "city": "London",
                                    "street": "Bakerstreet, 221B"
                                }, 11))

    DB['staff'].append(Staff('Taylor', 'aa1111', 'waiter', 100))
    DB['staff'].append(Staff('Hannibal', 'et0000', 'cook', 1000))
    DB['staff'].append(Staff('Hilton', 'ad1234', 'Administrator', 9000))
Exemplo n.º 2
0
def main():
    tenant_list = all_tenant()
    for tenant in tenant_list:
        if can_insert(tenant['id']):
            tn = Tenant(tenant['id'], tenant['name'], tenant['user_id'])
            db.add(tn)
            print "tenant :", tenant['name'], " added to db"
    db.flush()
    db.commit()
Exemplo n.º 3
0
 def save(self, commit=True):
     tenant = Tenant(rent_date=self.cleaned_data['rentDate'],\
     remind_date=self.cleaned_data['remindDate'],rent_money=self.cleaned_data['rentMoney'],\
     house_number=self.cleaned_data['houseNumber'],unit=self.cleaned_data['unit'],\
     community=self.cleaned_data['community'],mobile_number=self.cleaned_data['mobileNumber'],\
     sex=self.cleaned_data['sex'],name=self.cleaned_data['name'])
     tenant.status = '1'
     tenant.user_id = self.userId
     tenant.done_date = datetime.datetime.now()
     if commit:
         tenant.save()
Exemplo n.º 4
0
 def post(self):
     data = data_valid_for('POST')
     logging.debug(data)
     tenants_already_exist = list(
         filter(lambda t: data['passport_id'] == t.passport_id,
                DB['tenants']))
     if not tenants_already_exist:
         DB['tenants'].append(Tenant(**data))
         new_passport_id = str(DB['tenants'][-1].passport_id)
         location = {"Location": f'/api/v0.1/tenants/{new_passport_id}'}
         return {"message": "tenant was added successfully"}, 201, location
     msg = f"tenant with passport_id {data['passport_id']} already exists"
     return {"message": msg}, 400
Exemplo n.º 5
0
    def __init__(self, args):
        self.args = args
        self.tenant = Tenant(
            self.args.username,
            self.args.api_key,
            Tenant.SMALL,  # this doesn't mean anything for our purposes
            self.args.auth_endpoint,
        )

        self.tenant.get_token()

        print "%s has token %s" % (self.tenant.id, self.tenant.get_token())

        self.client = DesignateClient(
            client=HttpSession(self.args.endpoint),
            tenant=self.tenant,
            use_project_id=self.args.no_repose,
            tenant_id_in_url=not self.args.no_repose,
        )
Exemplo n.º 6
0
def userRegisteration(request: User, db: Session = Depends(get_db)):

    id_uid = id_uuids()
    organization = Organization(id=id_uid, name=request.organization_name)
    db.add(organization)
    db.commit()
    db.refresh(organization)

    id_uid = id_uuids()
    tenant = Tenant(id=id_uid,
                    name=request.tenant_name,
                    company_logo=request.company_logo,
                    organization_id=organization.id)
    db.add(tenant)
    db.commit()
    db.refresh(tenant)

    role = db.query(
        models.Role).filter(models.Role.name == "tenentAdmin").first()
    if role:
        print(role.id)

    else:

        role = Role(id=id_uid, name="tenentAdmin")
        db.add(role)
        db.commit()
        db.refresh(role)

        # atuo generate password
    a = randoms()
    password = str(a)
    Tenantuser = TenantUser(id=id_uid,
                            username=request.username,
                            role_id=role.id,
                            password=password,
                            tenant_id=tenant.id)
    db.add(Tenantuser)
    db.commit()
    db.refresh(Tenantuser)

    return {organization, tenant, Tenantuser}
Exemplo n.º 7
0
def userRegisteration(request: User, db: Session = Depends(get_db)):

    id_uid = id_uuids()
    organization = Organization(id=id_uid, name=request.organization_name)
    db.add(organization)
    db.commit()
    db.refresh(organization)

    id_uid = id_uuids()
    tenant = Tenant(id=id_uid,
                    name=request.tenant_name,
                    organization_id=organization.id)
    db.add(tenant)
    db.commit()
    db.refresh(tenant)

    role = db.query(models.Role).filter(models.Role.name == "admin").first()
    if role:
        role_id = role.id

    else:

        role_id = Role(id=id_uid, name="tenentAdmin")
        db.add(role_id)
        db.commit()
        db.refresh(role_id)
        print(role_id)

    tenantuser = TenantUser(id=id_uid,
                            username=request.username,
                            first_name=request.firstname,
                            last_name=request.lastname,
                            email=request.email,
                            role_id=role_id,
                            tenant_id=tenant.id)
    db.add(tenantuser)
    db.commit()
    db.refresh(tenantuser)

    return {organization, tenant, tenantuser}
Exemplo n.º 8
0
def validate_checkdomain(request):
    TenantObj = Tenant().getUserBySubdomain(request.GET.get('company_domain'))
    if TenantObj == None:
        return HttpResponse(json.dumps(True))
    return HttpResponse(json.dumps(False))
Exemplo n.º 9
0
#Push sample data with GraphQL
#Drop existing tables if any before running

#initialize db with first tenants and sensors
import random
from models import engine, db_session, Base, Tenant, Data, Sensor
Base.metadata.create_all(bind=engine)

#add first user
kate = Tenant(name='kate')
db_session.add(kate)

#add second user
kate_multitenancy = Tenant(name='kate_multitenancy')
db_session.add(kate_multitenancy)

#add sensors
t = Sensor(name='temperature')
db_session.add(t)
e = Sensor(name='electricity')
db_session.add(e)
p = Sensor(name='pressure')
db_session.add(p)

users = [kate, kate_multitenancy]
sensors = [e,p,t]
#add 100 entries
n = 100


for i in range(n):
Exemplo n.º 10
0
# save a report when the test finishes
persistence.setup_persistence()

locust.config.RESET_STATS_AFTER_HATCHING = CONFIG.reset_stats

# use digaas to externally poll the nameserver(s) to record zone propagation
# times through Designate's stack
if CONFIG.use_digaas and not insight.is_slave():
    _digaas_client = digaas_integration.DigaasClient(CONFIG.digaas_endpoint)
    digaas_integration.setup(_digaas_client)

if not insight.is_master():
    # TODO: the tenant id is actually the username. it should be named so.
    SMALL_TENANTS = [
        Tenant(id=id, api_key=api_key, type=Tenant.SMALL)
        for id, api_key in CONFIG.small_tenants
    ]
    LARGE_TENANTS = [
        Tenant(id=id, api_key=api_key, type=Tenant.LARGE)
        for id, api_key in CONFIG.large_tenants
    ]
    ALL_TENANTS = SMALL_TENANTS + LARGE_TENANTS

    # the greenlet_manager keeps track of greenlets spawned for polling
    # todo: it's hard to ensure cleanup_greenlets gets run before the stats
    # are persisted to a file...

    # ensure cleanup when the test is stopped
    locust.events.locust_stop_hatching += \
        lambda: GreenletManager.get().cleanup_greenlets()