Ejemplo n.º 1
0
def test_facilities():
    Database.initialize()
    # add company

    status = Facilities.is_company_exist('google')
    assert status != Facilities.add_company('google', 'matam')
    status = Facilities.is_company_exist('yahoo')
    assert status != Facilities.add_company('yahoo', 'matam')
    status = Facilities.is_company_exist('microsoft')
    assert status != Facilities.add_company('microsoft', 'matam')
    status = Facilities.is_company_exist('vmware')
    assert status != Facilities.add_company('vmware', 'matam')
    status = Facilities.is_company_exist('intel')
    assert status != Facilities.add_company('intel', 'matam')
    # add facilities to each company

    status = Facilities.is_facility_exist('google', 'carmel')
    assert status != Facilities.add_facility('google', 'carmel')
    status = Facilities.is_facility_exist('yahoo', 'carmel')
    assert status != Facilities.add_facility('yahoo', 'carmel')
    status = Facilities.is_facility_exist('microsoft', 'carmel')
    assert status != Facilities.add_facility('microsoft', 'carmel')
    status = Facilities.is_facility_exist('vmware', 'carmel')
    assert status != Facilities.add_facility('vmware', 'carmel')
    status = Facilities.is_facility_exist('intel', 'carmel')
    assert status != Facilities.add_facility('intel', 'carmel')

    assert 'carmel' in Facilities.get_facilities('intel')
    assert 'matam' in Facilities.get_facilities('intel')
    assert 'carmel' in Facilities.get_facilities('vmware')
    assert 'matam' in Facilities.get_facilities('vmware')

    Facilities.remove_facility('vmware', 'carmel')
    assert 'carmel' not in Facilities.get_facilities('vmware')
Ejemplo n.º 2
0
 def manager_register(cls, email, password, username, _id, role, permission,
                      company, facility):
     data = Database.find_one('facilities', {'company': company})
     role = 'Manager'
     permission = 100
     if data is not None:
         return False, "company already exist"
     else:
         user = cls.get_by_email(email)
         if not cls.check_id(_id):
             return False, "bad number ID"
         if user is None:
             # User dose'nt exist, create new user
             Facilities.add_company(company, facility)
             new_user = cls(email, username, password, _id, role,
                            permission, company, facility)
             try:
                 new_user.save_to_mongodb()
                 session['email'] = email
                 return True, "SUCCESS"
             except Exception as e:
                 return False, str(e)
         else:
             # User already exist
             return False, "user email already exist"