def test_update_user(self): """ python manage.py test --settings=shinobi_core.settings.test shinobi_api.tests.UserServiceTestCase.test_update_user """ PETER, MARIA = create_users() new_name = 'PEPE' new_gender = Gender.MALE count1 = UserProfile.objects.count() NEWPETER = UserService.save({ 'id': PETER.id, 'first_name': new_name, 'profile': { 'gender': Gender.MALE } }) count2 = UserProfile.objects.count() count_user_email1 = UserEmail.objects.count() new_email = '*****@*****.**' NEWMARIA = UserService.save({ 'id': MARIA.id, 'email': new_email, 'profile': {} }) count_user_email2 = UserEmail.objects.count() self.assertEqual(count1, count2, 'Not create more profile') self.assertEqual(NEWPETER.first_name, new_name, 'Update user success') self.assertEqual(NEWPETER.profile.gender, new_gender, 'Update user profile success') self.assertEqual(NEWMARIA.email, new_email, 'Update email success')
def create_users(data1=None, data2=None): if data1 is None: data1 = copy.deepcopy(user_data1) if data2 is None: data2 = copy.deepcopy(user_data2) peter = UserService.save(data1) maria = UserService.save(data2) return peter, maria
def setUp(self): """ data file: "checkin", "visitor_code", "location_id", "badge_id", "date", "time", "destination", "badge_type_id", "name", "id_card", "avatar", "dob" 1,122199203165225,122,1,2017-03-28,08:30:53,Grade 1 - 101,1,THN,241225225,cmnd/1.jpg,1992-03-16 1,122199203175224,122,2,2017-03-29,08:30:53,Grade 2 - 102,1,TA,241225224,cmnd/2.jpg,1992-03-17 1,122199203185223,122,3,2017-04-29,08:30:53,Grade 3 - 103,2,NTHV,241225223,cmnd/3.jpg,1992-03-18 1,122199203195222,122,4,2017-03-29,08:30:53,Grade 4 - 104,2,TG,241225222,cmnd/4.jpg,1992-03-19 0,122199203165225,2017-03-29,09:30:53 0,122199203185223,2017-04-29,09:40:53 """ global ADMIN_INIT global BUILDING_INIT admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) building_test = building_init building_test['user_id'] = ADMIN_INIT.id BUILDING_INIT = Building.objects.create(**building_test) badge_type_1['building_id'] = BUILDING_INIT.id badge_type_2['building_id'] = BUILDING_INIT.id BadgeType.objects.create(**badge_type_1) BadgeType.objects.create(**badge_type_2) input = {} input['data'] = 'test/data.csv' input['upload_dir'] = 'test/upload' act_rs = BadgeService.sync(input, building=BUILDING_INIT.id)
def setUp(self): """ data file: "checkin", "visitor_code", "location_id", "badge_id", "date", "time", "destination", "badge_type_id", "name", "id_card", "avatar", "dob" 1,122199203165225,122,1,2017-03-28,08:30:53,Grade 1 - 101,1,THN,241225225,cmnd/1.jpg,1992-03-16 1,122199203175224,122,2,2017-03-29,08:30:53,Grade 2 - 102,1,TA,241225224,cmnd/2.jpg,1992-03-17 1,122199203185223,122,3,2017-04-29,08:30:53,Grade 3 - 103,2,NTHV,241225223,cmnd/3.jpg,1992-03-18 1,122199203195222,122,4,2017-03-29,08:30:53,Grade 4 - 104,2,TG,241225222,cmnd/4.jpg,1992-03-19 0,122199203165225,2017-03-29,09:30:53 0,122199203185223,2017-04-29,09:40:53 """ global ADMIN_INIT global BUILDING_INIT global TOKEN admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) building_test = building_init building_test['user_id'] = ADMIN_INIT.id BUILDING_INIT = Building.objects.create(**building_test) # login url = '/api/v1/auth' data = {'email': '*****@*****.**', 'password': '******'} response = self.client.post(url, data, **head) TOKEN = response.data['token'] badge_type_1['building_id'] = BUILDING_INIT.id badge_type_2['building_id'] = BUILDING_INIT.id BadgeType.objects.create(**badge_type_1) BadgeType.objects.create(**badge_type_2)
def setUp(self): global ADMIN_INIT global BUILDING_INIT admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) building_test = building_init building_test['user_id'] = ADMIN_INIT.id BUILDING_INIT = Building.objects.create(**building_test)
def setUp(self): global ADMIN_INIT global BUILDING_INIT admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) question_reset_1['user_id'] = ADMIN_INIT.id question_reset_2['user_id'] = ADMIN_INIT.id question_reset_3['user_id'] = ADMIN_INIT.id QuestionReset.objects.create(**question_reset_1) QuestionReset.objects.create(**question_reset_2) QuestionReset.objects.create(**question_reset_3)
def setUp(self): global ADMIN_INIT global BUILDING_INIT global TOKEN admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) # login url = '/api/v1/auth' data = {'email': '*****@*****.**', 'password': '******'} response = self.client.post(url, data, **head) TOKEN = response.data['token']
def setUp(self): global ADMIN_INIT global BUILDING_INIT global NTHV, THHN, HTKV admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) building_test = building_init building_test['user_id'] = ADMIN_INIT.id BUILDING_INIT = Building.objects.create(**building_test) # Add visitor vistor1['building_id'] = BUILDING_INIT.id NTHV = Visitor.objects.create(**vistor1) vistor2['building_id'] = BUILDING_INIT.id THHN = Visitor.objects.create(**vistor2) vistor3['building_id'] = BUILDING_INIT.id HTKV = Visitor.objects.create(**vistor3)
def setUp(self): global ADMIN_INIT global BUILDING_INIT global TOKEN global VISITOR_1, VISITOR_2 admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) building_test = building_init building_test['user_id'] = ADMIN_INIT.id BUILDING_INIT = Building.objects.create(**building_test) VISITOR_1 = Visitor.objects.create(**visitor_1) VISITOR_2 = Visitor.objects.create(**visitor_2) # login url = '/api/v1/auth' data = {'email': '*****@*****.**', 'password': '******'} response = self.client.post(url, data, **head) TOKEN = response.data['token']
def setUp(self): global ADMIN_INIT global BUILDING_INIT global TOKEN admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test) building_test = building_init building_test['user_id'] = ADMIN_INIT.id BUILDING_INIT = Building.objects.create(**building_test) badge_type_1['building_id'] = BUILDING_INIT.id badge_type_2['building_id'] = BUILDING_INIT.id BadgeType.objects.create(**badge_type_1) BadgeType.objects.create(**badge_type_2) # login url = '/api/v1/auth' data = {'email': '*****@*****.**', 'password': '******'} response = self.client.post(url, data, **head) TOKEN = response.data['token']
def setUp(self): global ADMIN_INIT global BUILDING_INIT admin_test = copy.deepcopy(user_init) ADMIN_INIT = UserService.save(admin_test)