Exemplo n.º 1
0
    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, [])
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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'])
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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'])
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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())
Exemplo n.º 8
0
    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")
Exemplo n.º 9
0
    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'))
Exemplo n.º 10
0
    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, "")
Exemplo n.º 11
0
    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")
Exemplo n.º 12
0
    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())
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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'))
Exemplo n.º 15
0
    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, "")
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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')
Exemplo n.º 19
0
    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'))
Exemplo n.º 20
0
    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'))
Exemplo n.º 21
0
    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')
Exemplo n.º 22
0
    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, [])
Exemplo n.º 23
0
    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')
Exemplo n.º 24
0
    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')