def test_location_remove(self): self.setup_locations() updated_user_spec = deepcopy(self.user_specs[0]) # first assign both locations updated_user_spec["location_code"] = [ a.site_code for a in [self.loc1, self.loc2] ] bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) # deassign all locations updated_user_spec["location_code"] = [] updated_user_spec["user_id"] = self.user._id bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) # user should have no locations self.assertEqual(self.user.location_id, None) self.assertEqual(self.user.user_data.get('commcare_location_id'), None) self.assertListEqual(self.user.assigned_location_ids, [])
def test_upload_with_user_id(self): bulk_upload_async(self.domain.name, list(self.user_specs), list([]), list([])) self.assertNotEqual(self.user_specs[0]['user_id'], self.user._id) self.assertEqual(self.user_specs[0]['phone-number'], self.user.phone_number) self.assertEqual(self.user_specs[0]['name'], self.user.name)
def test_set_role(self): updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["role"] = self.role.name bulk_upload_async(self.domain.name, list([updated_user_spec]), list([]), list([])) self.assertEqual( self.user.get_role(self.domain_name).name, updated_user_spec['role'])
def test_upload_with_user_id(self): bulk_upload_async(self.domain.name, list(self.user_specs), list([]), list([])) user = CommCareUser.get_by_username('{}@{}.commcarehq.org'.format( self.user_specs[0]['username'], self.domain.name)) self.assertNotEqual(self.user_specs[0]['user_id'], user._id) self.assertEqual(self.user_specs[0]['phone-number'], user.phone_number) self.assertEqual(self.user_specs[0]['name'], user.name)
def test_set_role(self): updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["role"] = self.role.name bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) self.assertEqual(self.user.get_role(self.domain_name).name, updated_user_spec['role'])
def test_upload_with_user_id(self): bulk_upload_async( self.domain.name, list(self.user_specs), list([]), ) self.assertNotEqual(self.user_specs[0]['user_id'], self.user._id) self.assertEqual(self.user_specs[0]['phone-number'], self.user.phone_number) self.assertEqual(self.user_specs[0]['name'], self.user.name)
def test_upper_case_email(self): """ Ensure that bulk upload throws a proper error when the email has caps in it """ updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["email"] = '*****@*****.**' bulk_upload_async(self.domain.name, list([updated_user_spec]), list([]), list([])) self.assertEqual(self.user.email, updated_user_spec['email'].lower())
def test_numeric_user_name(self): """ Test that bulk upload doesn't choke if the user's name is a number """ updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["name"] = 1234 bulk_upload_async(self.domain.name, list([updated_user_spec]), list([]), list([])) self.assertEqual(self.user.full_name, "1234")
def test_location_update(self): self.setup_location() from copy import deepcopy updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["location_code"] = self.state_code bulk_upload_async(self.domain.name, list([updated_user_spec]), list([]), list([])) self.assertEqual(self.user.location_id, self.location._id) self.assertEqual(self.user.location_id, self.user.user_data.get('commcare_location_id'))
def test_empty_user_name(self): """ This test confirms that a name of None doesn't set the users name to "None" or anything like that. """ updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["name"] = None bulk_upload_async(self.domain.name, list([updated_user_spec]), list([]), list([])) self.assertEqual(self.user.full_name, "")
def test_numeric_user_name(self): """ Test that bulk upload doesn't choke if the user's name is a number """ updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["name"] = 1234 bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) self.assertEqual(self.user.full_name, "1234")
def test_upper_case_email(self): """ Ensure that bulk upload throws a proper error when the email has caps in it """ updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["email"] = '*****@*****.**' bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) self.assertEqual(self.user.email, updated_user_spec['email'].lower())
def test_upload_with_user_id(self): bulk_upload_async( self.domain.name, list(self.user_specs), list([]), list([]) ) user = CommCareUser.get_by_username('{}@{}.commcarehq.org'.format( self.user_specs[0]['username'], self.domain.name)) self.assertNotEqual(self.user_specs[0]['user_id'], user._id) self.assertEqual(self.user_specs[0]['phone-number'], user.phone_number) self.assertEqual(self.user_specs[0]['name'], user.name)
def test_location_update(self): self.setup_location() from copy import deepcopy updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["location-sms-code"] = self.state_code bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), list([]) ) self.assertEqual(self.user.location_id, self.location._id) self.assertEqual(self.user.location_id, self.user.user_data.get('commcare_location_id'))
def test_empty_user_name(self): """ This test confirms that a name of None doesn't set the users name to "None" or anything like that. """ updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["name"] = None bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) self.assertEqual(self.user.full_name, "")
def test_location_not_list(self): self.setup_locations() updated_user_spec = deepcopy(self.user_specs[0]) # location_code can also just be string instead of array for single location assignmentss updated_user_spec["location_code"] = self.loc1.site_code bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) self.assertEqual(self.user.location_id, self.loc1._id) self.assertEqual(self.user.location_id, self.user.user_data.get('commcare_location_id')) # multiple locations self.assertListEqual([self.loc1._id], self.user.assigned_location_ids)
def test_weak_password(self): updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["password"] = '******' rows = bulk_upload_async(self.domain.name, list([updated_user_spec]), list([]), list([]))['messages']['rows'] self.assertEqual(rows[0]['flag'], 'Please provide a stronger password')
def test_location_add(self): self.setup_locations() updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["location_code"] = [a.site_code for a in [self.loc1, self.loc2]] bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) # first location should be primary location self.assertEqual(self.user.location_id, self.loc1._id) self.assertEqual(self.user.location_id, self.user.user_data.get('commcare_location_id')) # multiple locations self.assertListEqual([l._id for l in [self.loc1, self.loc2]], self.user.assigned_location_ids) # non-primary location self.assertTrue(self.loc2._id in self.user.user_data.get('commcare_location_ids'))
def test_weak_password(self): updated_user_spec = deepcopy(self.user_specs[0]) updated_user_spec["password"] = '******' rows = bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), )['messages']['rows'] self.assertEqual(rows[0]['flag'], 'Please provide a stronger password')
def test_location_remove(self): self.setup_locations() updated_user_spec = deepcopy(self.user_specs[0]) # first assign both locations updated_user_spec["location_code"] = [a.site_code for a in [self.loc1, self.loc2]] bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) # deassign all locations updated_user_spec["location_code"] = [] updated_user_spec["user_id"] = self.user._id bulk_upload_async( self.domain.name, list([updated_user_spec]), list([]), ) # user should have no locations self.assertEqual(self.user.location_id, None) self.assertEqual(self.user.user_data.get('commcare_location_id'), None) self.assertListEqual(self.user.assigned_location_ids, [])
def test_duplicate_password(self): user_spec = [{ u'username': u'thiddleston', u'user_id': u'1990', u'name': u'Tom Hiddleston', u'language': None, u'is_active': u'True', u'phone-number': u'8675309', u'password': '******', u'email': None }] rows = bulk_upload_async(self.domain.name, list(user_spec + self.user_specs), list([]), list([]))['messages']['rows'] self.assertEqual(rows[0]['flag'], 'Provide a unique password for each mobile worker')
def test_duplicate_password(self): user_spec = [{ 'username': '******', 'user_id': '1990', 'name': 'Tom Hiddleston', 'language': None, 'is_active': 'True', 'phone-number': '8675309', 'password': '******', 'email': None }] rows = bulk_upload_async( self.domain.name, list(user_spec + self.user_specs), list([]), )['messages']['rows'] self.assertEqual(rows[0]['flag'], 'Provide a unique password for each mobile worker')