def test_canAccessCallGroup(self): call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', call_group=call_group) practice.save() practice.call_groups.add(call_group) user = create_user('user-CallGroup2', 'us', 'er', 'demo') staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) #a staff call this method result = canAccessCallGroup(staff, long(call_group.pk)) self.assertEqual(result, False) #a manager call this method # manager = Office_Manager(user=staff, practice=practice, manager_role=1) # manager.save() # # result = canAccessCallGroup(manager, long(call_group.pk)) # self.assertEqual(result, True) #admin call this method admin = create_user('user-CallGroup', 'us', 'er', 'demo', '', '', '', '', Administrator) result = canAccessCallGroup(admin.user, call_group) self.assertEqual(result, True) Administrator.objects.all().delete()
def setUpClass(cls): # done once for all AnalyticsUnitTest # needed at login # create admin and test user cls.admin = create_user("sduper", "super", "duper", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator) cls.guest = create_user("cbear", "care", "bear", "demo", "Winchester Blvd.", "San Jose", "CA", uklass=Salesperson) cls.practice = PracticeLocation.objects.create(practice_name='Beach bums', practice_address1='Del Monte Ave.', practice_city='Monterey', practice_state='CA', practice_lat=0.0, practice_longit=0.0) cls.site = Site.objects.create(name='Site 9', address1='Ala Moana Ct.', city='Saratoga', state='CA', lat=0.0, longit=0.0) cls.provider = create_user("dholiday", "doc", "holiday", "demo", "123 Main St.", "Phoenix", "AZ", uklass=Provider) cls.docholiday = Physician.objects.create(user=cls.provider)
def create_mhluser(): chars = 'abcdefghijklmnopqrstuvwxyz0123456789' username = ''.join([random.choice(chars) for _ in range(8)]) firstname = ''.join([random.choice(chars) for _ in range(6)]) lastname = ''.join([random.choice(chars) for _ in range(6)]) return create_user(username, firstname, lastname, 'demo')
def test_checkeUserInCallGroup(self): call_group = CallGroup(description='test', team='team') call_group.save() request = HttpRequest() user = create_user('practicemgr1', 'lin', 'xing', 'demo') provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() mem = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) mem.save() request.method = 'POST' request.POST['userId'] = user.pk response = checkeUserInCallGroup(request, call_group.id) self.assertEqual(response.content, '"ok"') call_group2 = CallGroup(description='test', team='team') call_group2.save() response = checkeUserInCallGroup(request, call_group2.id) self.assertEqual(response.content, '"err"')
def setUp(self): PracticeLocation.objects.all().delete() self.practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) self.practice.save() self.user_datas = [ {"username":"******", "first_name":"bill", "last_name":"blazejowsky", "password":"******", "addr":"Ocean Avenue","addr2":"Ocean Avenue", "city":"Carmel", "state":"CA", "zipcode":"93921", "uklass":OfficeStaff}, {"username":"******", "first_name":"bill1", "last_name":"blazejowsky1", "password":"******", "addr":"Ocean Avenue","addr2":"Ocean Avenue", "city":"Carmel", "state":"CA", "zipcode":"93921", "uklass":Provider}, {"username":"******", "first_name":"bill2", "last_name":"blazejowsky2", "password":"******", "addr":"Ocean Avenue","addr2":"Ocean Avenue", "city":"Carmel", "state":"CA", "zipcode":"93921", "uklass":Broker}, ] for user in self.user_datas: persistent_user = create_user(user['username'], user['first_name'], user['last_name'], user['password'], user['addr'], user['city'], user['state'], user['zipcode'], uklass=user['uklass']) persistent_user.current_practice = self.practice persistent_user.save() user['id'] = persistent_user.user.id user['lat'] = persistent_user.user.lat user['longit'] = persistent_user.user.longit
def test_isCallGroupStaff(self): call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.call_group = call_group practice.save() user = create_user('user5', 'us', 'er', 'demo') #a mhluser call this method result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, False) staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) #a staff call this method result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, True) #a manager call this method manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, True)
def test_isCallGroupStaff(self): call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.call_group = call_group practice.save() user = create_user('user5', 'us', 'er', 'demo') #a mhluser call this method result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, False) staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) #a staff call this method result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, True) #a manager call this method manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, True)
def setUpClass(cls): clean_db_datas() cls.user = create_user( 'practicemgr1', 'lin', 'xing', 'demo', '', '', '', '', ) call_group = CallGroup(description='test', team='team') call_group.save() cls.call_group = call_group practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() practice.call_groups.add(call_group) cls.practice = practice
def test_getLevelByStaff(self): practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #not a manager login result = get_level_by_staff(user, practice) self.assertEqual(result, 0) staff = OfficeStaff(user=user) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() #a manager login result = get_level_by_staff(staff.id, practice) self.assertEqual(result, 2)
def test_getCurrentPractice(self): practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #a mhluser login and call this method result = getCurrentPractice(user) self.assertEqual(result, '') #a provider login and call this method provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.current_practice = practice provider.save() result = getCurrentPractice(user) self.assertEqual(result, 'test') #a staff login and call this method staff = OfficeStaff(user=user) staff.current_practice = practice staff.save() result = getCurrentPractice(user) self.assertEqual(result, 'test')
def test_checkoutUserManager(self): practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() user = create_user('staff', 'lin', 'xing', 'demo', '', '', '', '',) staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) provider = Provider.objects.create(username='******', first_name='heal', last_name='meister', address1="555 Bryant St.", city="Palo Alto", state="CA", lat=0.0, longit=0.0, office_lat=0.0, office_longit=0.0, is_active=True, tos_accepted=True, mobile_confirmed=True, mdcom_phone='123', mobile_phone='456') provider.user = provider # for our unique prov-user reln provider.save() # try provider result = user_is_mgr_of_practice(provider, practice) self.assertEqual(False, result) # try just staff result = user_is_mgr_of_practice(staff.user, practice) self.assertEqual(False, result) # now office manager (make staff an OM) om = Office_Manager.objects.create(user=staff, practice=practice, manager_role=1) result = user_is_mgr_of_practice(om.user.user, practice) self.assertEqual(True, result) result = user_is_mgr_of_practice(staff.user, practice) self.assertEqual(True, result)
def test_getLevelByStaff(self): practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit= -122.081864) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #not a manager login result = get_level_by_staff(user, practice) self.assertEqual(result, 0) staff = OfficeStaff(user=user) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() #a manager login result = get_level_by_staff(staff.id, practice) self.assertEqual(result, 2)
def test_getCurrentPractice(self): practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #a mhluser login and call this method result = getCurrentPractice(user) self.assertEqual(result, '') #a provider login and call this method provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.current_practice = practice provider.save() result = getCurrentPractice(user) self.assertEqual(result, 'test') #a staff login and call this method staff = OfficeStaff(user=user) staff.current_practice = practice staff.save() result = getCurrentPractice(user) self.assertEqual(result, 'test')
def create_org_pending(to_user, org_type=None, org_type_id=None): org = create_organization(org_type=org_type, org_type_id=org_type_id) from_user = create_user('tset', 'abc', 'def', 'demo') pending = Pending_Association(from_user=from_user, to_user=to_user, practice_location=org, created_time=datetime.datetime.now()) pending.save() return pending
def test_addProviderToPractice(self, start_thread): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() #invalid assoc id assocID = {'assoc_id': 'a'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.addProviderToPractice'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], _('A server error has occurred.')) #valid assoc id to_user = create_user( 'p2', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider = Provider(username='******', first_name='first', last_name="last", email='*****@*****.**', user=self.user, office_lat=0.0, office_longit=0.0) provider.save() pend = Pending_Association(from_user=self.user, to_user=to_user, practice_location=self.practice, created_time=datetime.datetime.now()) pend.save() assocID = {'assoc_id': pend.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.addProviderToPractice'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertEqual( Log_Association.objects.get(association_id=pend.id).action, 'ACC') self.assertEqual(Pending_Association.objects.count(), 0) self.assertEqual( self.practice in Provider.objects.get(pk=provider.pk).practices.all(), True) mems = CallGroupMember.objects.filter(call_group=self.call_group) self.assertEqual(len(mems), 1)
def test_get_all_providers_and_staffs(self): request = generateHttpRequest() #get method request.method = 'GET' result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #find 0 any type user result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 0) #has 1 nppa user = create_user('np1', 'abc', '', 'demo') provider = Provider(user=user, username='******', first_name='abc', last_name='', office_lat=0.0, office_longit=0.0) provider.save() nppa = NP_PA(user=provider) nppa.save() request.POST['name'] = unicode('abc') result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 1) self.assertEqual(msg['users'][0]['first_name'], 'abc') phy = Physician(user=provider) phy.save() result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc') #staff organization_type = create_org_type() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', mdcom_phone='8005550085', organization_type=organization_type) practice.save() staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() staff.practices.add(practice) request.POST['name'] = unicode(request.user.first_name) result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc')
def test_isMultiCallGroupManager(self): #init practice and call group call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() practice.call_groups.add(call_group) user = create_user('user1', 'us', 'er', 'demo') #only mhluser call method result = isMultiCallGroupManager(user, practice.id, call_group.id) self.assertEqual(result, False) #staff call method staff = OfficeStaff(user=user) staff.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, False) practice2 = PracticeLocation( practice_name='test2', practice_longit='0.1', practice_lat='0.0', ) practice2.save() practice2.call_groups.add(call_group) #manager call method staff.practices.add(practice) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True) #manager with specialty call method specialty_name = 'Specialty A' specialty1 = Specialty() specialty1.name = specialty_name specialty1.practice_location = practice specialty1.number_selection = 3 specialty1.save() specialty1.call_groups.add(call_group) manager2 = Office_Manager(user=staff, practice=practice2, manager_role=1) manager2.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True)
def setUpClass(cls): clean_db_datas() organization_type = create_org_type() practice = ct_practice('name', organization_type) cls.practice = practice user = create_user('practicemgr1', 'lin', 'xing', 'demo') cls.user = user
def test_rejectAssociation(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() #invalid assoc id assocID = {'assoc_id': 'a'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.rejectAssociation'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['err'], _('The data is error. Please refresh the page again.')) #valid assoc id to_user = create_user( 'p2', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider = Provider(username='******', first_name='first', last_name="last", email='*****@*****.**', user=self.user, office_lat=0.0, office_longit=0.0) provider.save() pend = Pending_Association(from_user=self.user, to_user=to_user, practice_location=self.practice, created_time=datetime.datetime.now()) pend.save() assocID = {'assoc_id': pend.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.rejectAssociation'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'OK') self.assertEqual( Log_Association.objects.get(association_id=pend.id).action, 'REJ') self.assertEqual(Pending_Association.objects.count(), 0)
def setUpClass(cls): # done once for all AnalyticsUnitTest # needed at login # create admin and test user cls.admin = create_user("sduper", "super", "duper", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator) cls.guest = create_user("cbear", "care", "bear", "demo", "Winchester Blvd.", "San Jose", "CA", uklass=Salesperson) cls.practice = PracticeLocation.objects.create( practice_name='Beach bums', practice_address1='Del Monte Ave.', practice_city='Monterey', practice_state='CA', practice_lat=0.0, practice_longit=0.0) cls.site = Site.objects.create(name='Site 9', address1='Ala Moana Ct.', city='Saratoga', state='CA', lat=0.0, longit=0.0) cls.provider = create_user("dholiday", "doc", "holiday", "demo", "123 Main St.", "Phoenix", "AZ", uklass=Provider) cls.docholiday = Physician.objects.create(user=cls.provider)
def setUpClass(cls): clean_db_datas() cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo') practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() cls.practice = practice
def test_canAccessMultiCallGroup(self): #init practice and call group call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() practice.call_groups.add(call_group) #admin call this method admin = create_user('user-access-group2', 'us', 'er', 'demo', '', '', '', '', Administrator) result = canAccessMultiCallGroup(admin.user, call_group, practice.id) self.assertEqual(result, True) #not admin call this method user = create_user('user-access-group', 'us', 'er', 'demo') result = canAccessMultiCallGroup(user, call_group, practice.id) self.assertEqual(result, False)
def setUpClass(cls): # create a user to login creating a session needed by ivr tests cls.admin = create_user("ivrguy", "ivr", "guy", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator)
def setUp(self): SalesLeads.objects.all().delete() MHLUser.objects.all().delete() Administrator.objects.all().delete() Provider.objects.all().delete() Products.objects.all().delete() self.salesperson = create_user("bblazejowsky", "bill", "blazejowsky", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Salesperson) self.admin = create_user("sduper", "super", "duper", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator) self.provider = create_user("hmeister", "heal", "meister", "demo", "555 Bryant St.", "Palo Alto", "CA", "", uklass=Provider) Products(description="Fancie smansie product", code="fsm", price="29.95").save() Products(description="Generic Shampoo", code="gsham", price="9.95").save() Products(description="Bicycle Tires", code="bt", price="14.95").save()
def setUpClass(cls): clean_db_datas() organization_type = create_org_type() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', mdcom_phone='8005550085', organization_type=organization_type) practice.save() cls.practice = practice user = create_user('practicemgr1', 'lin', 'xing', 'demo') cls.user = user
def test_isMultiCallGroupManager(self): #init practice and call group call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() practice.call_groups.add(call_group) user = create_user('user1', 'us', 'er', 'demo') #only mhluser call method result = isMultiCallGroupManager(user, practice.id, call_group.id) self.assertEqual(result, False) #staff call method staff = OfficeStaff(user=user) staff.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, False) practice2 = PracticeLocation(practice_name='test2', practice_longit='0.1', practice_lat='0.0',) practice2.save() practice2.call_groups.add(call_group) #manager call method staff.practices.add(practice) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True) #manager with specialty call method specialty_name = 'Specialty A' specialty1 = Specialty() specialty1.name = specialty_name specialty1.practice_location = practice specialty1.number_selection = 3 specialty1.save() specialty1.call_groups.add(call_group) manager2 = Office_Manager(user=staff, practice=practice2, manager_role=1) manager2.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True)
def test_getPenddings(self): request = HttpRequest() user = create_user('practicemgr1', 'lin', 'xing', 'demo') call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() from_user = create_user('from user', 'lin', 'xing', 'demo') to_user = create_user('to user', 'lin', 'xing', 'demo') to_user = Provider(username='******', first_name='tes3', last_name="meister3", email='*****@*****.**', user=to_user, office_lat=0.0, office_longit=0.0) to_user.save() #0 pending find request.user = to_user response = getPenddings(request) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 0) #1 pending find pend = CallGroupMemberPending(from_user=from_user, to_user=to_user, practice=practice, call_group=call_group, accept_status=0, created_time=datetime.datetime.now()) pend.save() request.user = to_user response = getPenddings(request) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1)
def test_canAccessMultiCallGroup(self): #init practice and call group call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() practice.call_groups.add(call_group) #admin call this method admin = create_user('user-access-group2', 'us', 'er', 'demo', '', '', '', '', Administrator) result = canAccessMultiCallGroup(admin.user, call_group, practice.id) self.assertEqual(result, True) #not admin call this method user = create_user('user-access-group', 'us', 'er', 'demo') result = canAccessMultiCallGroup(user, call_group, practice.id) self.assertEqual(result, False)
def setUpClass(cls): clean_db_datas() cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo', '', '', '', '',) group = CallGroup(description='test', team='team') group.save() cls.group = group practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() practice.call_groups.add(group) cls.practice = practice
def test_isCallGroupMember(self): call_group = CallGroup(description='test', team='team') call_group.save() user = create_user('user6', 'us', 'er', 'demo') result = isCallGroupMember(user, call_group.id) self.assertEqual(result, False) provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() call_groupm = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) call_groupm.save() result = isCallGroupMember(provider, call_group.id) self.assertEqual(result, True)
def test_addAssociation(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() #provider id user = create_user( 'p', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider = Provider(username='******', first_name='first', last_name="last", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() data = {'prov_id': provider.user.id, 'userType': 1} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.addAssociation'), data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg[0], 'ok') self.assertEqual(Pending_Association.objects.count(), 1) self.assertEqual( Pending_Association.objects.get(to_user=provider.user).from_user, self.user) self.assertEqual(Log_Association.objects.count(), 1)
def setUp(self): self.staff = create_user("bblazejowsky", "bill", "blazejowsky", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=OfficeStaff) PracticeLocation.objects.all().delete() self.practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) self.practice.save()
def test_changeCurrentPracticeForStaff(self, start_thread): practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') staff = OfficeStaff(user=user) staff.save() result = changeCurrentPracticeForStaff(practice.id, user.pk) self.assertEqual(result, practice) try: changeCurrentPracticeForStaff(0, user.pk) except: PracticeLocation.DoesNotExist try: result = changeCurrentPracticeForStaff(practice.id, 0) except: MHLUser.DoesNotExist
def test_changeCurrentPracticeForStaff(self, start_thread): practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit= -122.081864) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') staff = OfficeStaff(user=user) staff.save() result = changeCurrentPracticeForStaff(practice.id, user.pk) self.assertEqual(result, practice) try: changeCurrentPracticeForStaff(0, user.pk) except: PracticeLocation.DoesNotExist try: result = changeCurrentPracticeForStaff(practice.id, 0) except: MHLUser.DoesNotExist
def test_call(self): phone = '80012312321' request = generateHttpRequest() #user has no mobile phone result = call(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE005') #user has mobile phone user = MHLUser.objects.get(pk=request.user.pk) user.mobile_phone = phone user.save() #invlid form data request.POST['number'] = '' request.POST['caller_number'] = '' result = call(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE031') #valid form data assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) request.POST['number'] = '8005550056' request.POST['caller_number'] = '8005550056' result = call(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['warnings'], {}) #user id and is 0 user_id = 0 result = call(request, user_id=user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #user_id and is not 0 username = '******' user = create_user(username, 'abc', 'def', 'demo') user_id = user.pk result = call(request, user_id=user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE005') #user id and user hase mobile phone user = MHLUser.objects.get(username=username) user.mobile_phone = '8569854741' user.save() result = call(request, user_id=user_id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['warnings'], {}) #practice_id is 0 practice_id = 0 result = call(request, practice_id=practice_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #practice id is not 0 organization_type = create_org_type() practice = ct_practice('name', organization_type) result = call(request, practice_id=practice.pk) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE006') #number is in kwargs number = '8001247841' result = call(request, number=number) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['warnings'], {})
def setUp(self): # needed at login # create a user to login creating a session needed by ivr tests self.admin = create_user("ivrguy", "ivr", "guy", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator) # one office manager self.staff = create_user("bblazejowsky", "bill", "blazejowsky", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=OfficeStaff) self.staff.mobile_phone = '4085551234' PracticeLocation.objects.all().delete() # practice location data self.practice_data = [ { "practice_name": "Test practice 1", "practice_address1": "555 Pleasant Pioneer Grove", "practice_address2": "Trailer Q615", "practice_city": "Mountain View", "practice_state": "CA", "practice_zip": "94040-4104", "mdcom_phone": "4085551111", "practice_phone": "4086661111", "time_zone": "US/Pacific", 'practice_lat': '37.36876', "practice_longit": "-122.081864" }, { "practice_name": "San Jose Practice", "practice_address1": "123 McKee Road", "practice_address2": "", "practice_city": "San Jose", "practice_state": "CA", "practice_zip": "94455", "mdcom_phone": "4085552222", "practice_phone": "8006662222", "time_zone": "US/Pacific", 'practice_lat': '33.3', "practice_longit": "22.08" }, { "practice_name": "Third Specialty Practice", "practice_address1": "123 specialty Road", "practice_address2": "", "practice_city": "San Ramon", "practice_state": "CA", "practice_zip": "90041", "mdcom_phone": "4085553333", "practice_phone": "8006663333", "time_zone": "US/Pacific", 'practice_lat': '23.3', "practice_longit": "102.08" }, ] # provider data self.prov_data = [{ "username": "******", "first_name": "bill", "last_name": "doc", "email": "*****@*****.**", "password": "******", "addr1": "Ocean Avenue", "addr2": "main drive", "city": "Carmel", "state": "CA", "zipcode": "93921", "phone": "4085551111", "mobile_phone": "4085559999", "office_address1": "3931 Easy Pioneer Knoll", "office_city": "san jose", "office_zip": "94062-2751", "office_phone": "", "office_state": "CA", "forward_mobile": True, "forward_other": False, "forward_office": False, "forward_vmail": False, "forward_anssvc": "VM", "forward_voicemail": "MO", "status_verified": True, "practices": [], "mdcom_phone": "8004664411", "mdcom_phone_sid": "123" }, { "username": "******", "first_name": "sam", "last_name": "sung", "email": "*****@*****.**", "password": "******", "addr1": "Main Street", "addr2": "main drive", "city": "Carmelita", "state": "CA", "zipcode": "93921", "phone": "4085552222", "mobile_phone": "4085558888", "office_address1": "1234 Easy Street", "office_city": "santa clara", "office_zip": "94060-2751", "office_phone": "", "office_state": "CA", "forward_mobile": True, "forward_other": False, "forward_office": False, "forward_vmail": False, "forward_anssvc": "VM", "forward_voicemail": "VM", "status_verified": True, "practices": [], "mdcom_phone": "8004664422", "mdcom_phone_sid": "321" }, { "username": "******", "first_name": "tim", "last_name": "tam", "email": "*****@*****.**", "password": "******", "addr1": "willow Street", "addr2": "", "city": "Cupertino", "state": "CA", "zipcode": "91234", "phone": "4085553333", "mobile_phone": "4085557777", "office_address1": "1234 Easy Street", "office_city": "santa clara", "office_zip": "94060-2751", "office_phone": "", "office_state": "CA", "forward_mobile": True, "forward_other": False, "forward_office": False, "forward_vmail": False, "forward_anssvc": "MO", "forward_voicemail": "MO", "status_verified": True, "practices": [], "mdcom_phone": "8004664433", "mdcom_phone_sid": "321" }] self.providers = [] self._add_providers() self.practices = [] self._add_practices() self.practice = self.practices[0] self.practice1 = self.practices[1] self.practice2 = self.practices[2] self.office_manager = Office_Manager() self.office_manager.manager_role = 1 self.office_manager.user = self.staff self.office_manager.practice = self.practice self.staff.practices.add(self.practice) self.office_manager.save() self.client.post('/login/', { 'username': self.admin.user.username, 'password': '******' })
def test_removeProviderCallGroup(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() #invalid provider provider_invalid = {'prov_id': 'abc'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_invalid) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], _('The data is error. Please refresh page again.')) #init a provider in practices provider1 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider1.save() provider1.practices.add(self.practice) provider_data = {'prov_id': provider1.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertNotEqual(provider1.practices, self.practice) #init a new provider in current practice and assign event user2 = create_user( 'practicemgr2', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider2 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user2, office_lat=0.0, office_longit=0.0) provider2.save() provider2.practices.add(self.practice) startDate = datetime.datetime.now() + datetime.timedelta(-10) endDate = datetime.datetime.now() + datetime.timedelta(10) event = EventEntry(creator=user2, oncallPerson=user2, callGroup=self.group, startDate=startDate, endDate=endDate, title='test event', oncallLevel='0', eventStatus=1, checkString='abc') event.save() provider_data = {'prov_id': provider2.id} #init key because send mail generate_keys_for_users(output=DevNull()) response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertNotEqual(provider2.practices, self.practice) #init a provider in practices and current practice provider3 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider3.current_practice = self.practice provider3.save() provider3.practices.add(self.practice) provider_data = {'prov_id': provider3.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertNotEqual(provider1.practices, self.practice) self.assertIsNone(provider1.current_practice)
def setUp(self): PracticeLocation.objects.all().delete() self.practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) self.practice.save() self.user_datas = [ { "username": "******", "first_name": "bill", "last_name": "blazejowsky", "password": "******", "addr": "Ocean Avenue", "addr2": "Ocean Avenue", "city": "Carmel", "state": "CA", "zipcode": "93921", "uklass": OfficeStaff }, { "username": "******", "first_name": "bill1", "last_name": "blazejowsky1", "password": "******", "addr": "Ocean Avenue", "addr2": "Ocean Avenue", "city": "Carmel", "state": "CA", "zipcode": "93921", "uklass": Provider }, { "username": "******", "first_name": "bill2", "last_name": "blazejowsky2", "password": "******", "addr": "Ocean Avenue", "addr2": "Ocean Avenue", "city": "Carmel", "state": "CA", "zipcode": "93921", "uklass": Broker }, ] for user in self.user_datas: persistent_user = create_user(user['username'], user['first_name'], user['last_name'], user['password'], user['addr'], user['city'], user['state'], user['zipcode'], uklass=user['uklass']) persistent_user.current_practice = self.practice persistent_user.save() user['id'] = persistent_user.user.id user['lat'] = persistent_user.user.lat user['longit'] = persistent_user.user.longit
def test_call(self): phone = '80012312321' request = generateHttpRequest() #user has no mobile phone result = call(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE005') #user has mobile phone user = MHLUser.objects.get(pk=request.user.pk) user.mobile_phone = phone user.save() #invlid form data request.POST['number'] = '' request.POST['caller_number'] = '' result = call(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE031') #valid form data assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) request.POST['number'] = '8005550056' request.POST['caller_number'] = '8005550056' result = call(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['warnings'], {}) #user id and is 0 user_id = 0 result = call(request, user_id=user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #user_id and is not 0 username = '******' user = create_user(username, 'abc', 'def', 'demo') user_id = user.pk result = call(request, user_id=user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE005') #user id and user hase mobile phone user = MHLUser.objects.get(username=username) user.mobile_phone = '8569854741' user.save() result = call(request, user_id=user_id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['warnings'], {}) #practice_id is 0 practice_id = 0 result = call(request, practice_id=practice_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #practice id is not 0 organization_type = create_org_type() practice = ct_practice('name', organization_type) result = call(request, practice_id=practice.pk) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE006') #number is in kwargs number = '8001247841' result = call(request, number=number) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['warnings'], {})
def setUp(self): # needed at login # create a user to login creating a session needed by ivr tests self.admin = create_user("ivrguy", "ivr", "guy", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=Administrator) # one office manager self.staff = create_user("bblazejowsky", "bill", "blazejowsky", "demo", "Ocean Avenue", "Carmel", "CA", "93921", uklass=OfficeStaff) self.staff.mobile_phone = '4085551234' PracticeLocation.objects.all().delete() # practice location data self.practice_data = [{ "practice_name":"Test practice 1", "practice_address1":"555 Pleasant Pioneer Grove", "practice_address2": "Trailer Q615", "practice_city": "Mountain View", "practice_state": "CA", "practice_zip": "94040-4104", "mdcom_phone": "4085551111", "practice_phone": "4086661111", "time_zone": "US/Pacific", 'practice_lat': '37.36876', "practice_longit":"-122.081864" }, {"practice_name":"San Jose Practice", "practice_address1":"123 McKee Road", "practice_address2": "", "practice_city": "San Jose", "practice_state": "CA", "practice_zip": "94455", "mdcom_phone": "4085552222", "practice_phone": "8006662222", "time_zone": "US/Pacific", 'practice_lat': '33.3', "practice_longit":"22.08" }, {"practice_name":"Third Specialty Practice", "practice_address1":"123 specialty Road", "practice_address2": "", "practice_city": "San Ramon", "practice_state": "CA", "practice_zip": "90041", "mdcom_phone": "4085553333", "practice_phone": "8006663333", "time_zone": "US/Pacific", 'practice_lat': '23.3', "practice_longit":"102.08" }, ] # provider data self.prov_data = [ {"username":"******", "first_name":"bill", "last_name":"doc", "email":"*****@*****.**", "password":"******", "addr1":"Ocean Avenue", "addr2":"main drive", "city":"Carmel", "state":"CA", "zipcode":"93921", "phone":"4085551111", "mobile_phone":"4085559999", "office_address1": "3931 Easy Pioneer Knoll", "office_city": "san jose", "office_zip": "94062-2751", "office_phone": "", "office_state": "CA", "forward_mobile": True, "forward_other": False, "forward_office": False, "forward_vmail": False, "forward_anssvc": "VM", "forward_voicemail": "MO", "status_verified": True, "practices": [], "mdcom_phone": "8004664411", "mdcom_phone_sid": "123" }, {"username":"******", "first_name":"sam", "last_name":"sung", "email":"*****@*****.**", "password":"******", "addr1":"Main Street", "addr2":"main drive", "city":"Carmelita", "state":"CA", "zipcode":"93921", "phone":"4085552222", "mobile_phone":"4085558888", "office_address1": "1234 Easy Street", "office_city": "santa clara", "office_zip": "94060-2751", "office_phone": "", "office_state": "CA", "forward_mobile": True, "forward_other": False, "forward_office": False, "forward_vmail": False, "forward_anssvc": "VM", "forward_voicemail": "VM", "status_verified": True, "practices": [], "mdcom_phone": "8004664422", "mdcom_phone_sid": "321" }, {"username":"******", "first_name":"tim", "last_name":"tam", "email":"*****@*****.**", "password":"******", "addr1":"willow Street", "addr2":"", "city":"Cupertino", "state":"CA", "zipcode":"91234", "phone":"4085553333", "mobile_phone":"4085557777", "office_address1": "1234 Easy Street", "office_city": "santa clara", "office_zip": "94060-2751", "office_phone": "", "office_state": "CA", "forward_mobile": True, "forward_other": False, "forward_office": False, "forward_vmail": False, "forward_anssvc": "MO", "forward_voicemail": "MO", "status_verified": True, "practices": [], "mdcom_phone": "8004664433", "mdcom_phone_sid": "321" }] self.providers = [] self._add_providers() self.practices = [] self._add_practices() self.practice = self.practices[0] self.practice1 = self.practices[1] self.practice2 = self.practices[2] self.office_manager = Office_Manager() self.office_manager.manager_role = 1 self.office_manager.user = self.staff self.office_manager.practice = self.practice self.staff.practices.add(self.practice) self.office_manager.save() self.client.post('/login/', {'username': self.admin.user.username, 'password': '******'})
def test_getProviderByEmailOrNameInCallGroup(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) #get method response = self.client.get( reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' )) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], _('A server error has occurred.')) #post method searchOptions = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchOptions) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 0) #find 1 provider user = create_user( 'provider1', 'lin', 'xing', 'demo', '', '', '', '', ) provider1 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider1.save() #input option first name searchFirstName = { 'email': '', 'fullname': 'tes', 'firstName': 'tes', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchFirstName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) #input option last name searchLastName = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': 'meister', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchLastName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) #input option user name searchUsername = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': '', 'username': '******', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchUsername) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) #input option email searchEmail = { 'email': '*****@*****.**', 'fullname': '', 'firstName': 'tes', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchEmail) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) pend = CallGroupMemberPending(from_user=self.user, to_user=provider1, practice=self.practice, call_group=self.call_group, created_time=datetime.datetime.now()) pend.save() searchLastName = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': 'meister', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchLastName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) searchLastName = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchLastName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1)