Exemple #1
0
    def test_password_is_kept(self):
        view = CSVImportView(self.profiles, self.request)

        # if no password is provided in the import file, one get's generated
        user_fields_file_loc = self._get_fixture_location('basic_users.csv')
        with open(user_fields_file_loc) as bf:
            filedata = self._parse_file(bf.read())
        view.create_update_users(filedata)

        barry = pi_api.userprofile.get('foo')
        doug = pi_api.userprofile.get('bar')
        barry_pwd = barry.password
        doug_pwd = doug.password
        # both got encrypted passwords
        self.assertTrue(barry_pwd.startswith('{BCRYPT}'))
        self.assertTrue(doug_pwd.startswith('{BCRYPT}'))
        # doug got the password provided in the import file
        self.assertTrue(
            IMembraneUserAuth(doug).verifyCredentials(
                dict(login='******', password='******')))

        # now re-import the same users but provide a new password for barry
        user_fields_file_loc = self._get_fixture_location(
            'basic_users_password.csv')
        with open(user_fields_file_loc) as bf:
            filedata = self._parse_file(bf.read())
        view.create_update_users(filedata, update=True)

        # barry should get a new password
        self.assertNotEqual(barry_pwd, barry.password)
        self.assertTrue(
            IMembraneUserAuth(barry).verifyCredentials(
                dict(login='******', password='******')))
        # doug's password should still be the same
        self.assertEqual(doug_pwd, doug.password)
        # both got new surnames:
        self.assertEqual(barry.last_name, u'Whiter')
        self.assertEqual(doug.last_name, u'Carsbest')
    def test_create_update_users(self):
        view = CSVImportView(self.profiles, self.request)
        user_fields_file_loc = self._get_fixture_location(
            'basic_users.csv')
        with open(user_fields_file_loc) as bf:
            filedata = self._parse_file(bf.read())

        self.assertEqual(len(self.profiles.objectValues()), 0)

        count = view.create_update_users(filedata)
        self.assertEqual(count, 2)
        self.assertEqual(
            len(self.profiles.objectValues()), 2, "Users not created")

        # validation failure on duplicate username
        with self.assertRaises(custom_exc.DuplicateUser):
            view.create_update_users(filedata)

        file_loc = self._get_fixture_location(
            'missing_first_name.csv')
        with open(file_loc) as bf:
            filedata = self._parse_file(bf.read())

        # validation failure on missing required field
        with self.assertRaises(schema.interfaces.RequiredMissing):
            view.create_update_users(filedata)
        # Even though an exception was raised we will have an extra user
        # here as the transaction is handled by the process method
        self.assertEqual(
            len(self.profiles.objectValues()), 3, "Users not created")

        # now update one of the users
        user_fields_file_loc = self._get_fixture_location(
            'basic_users.csv')
        with open(user_fields_file_loc) as bf:
            filedata = self._parse_file(bf.read())
        raw = filedata.csv
        email = '*****@*****.**'
        raw = raw.replace('*****@*****.**', email)
        filedata.csv = raw

        view.create_update_users(filedata, update=True)
        self.assertEqual(
            len(self.profiles.objectValues()), 3,
            "Users not created correctly",
        )
        user = self.membrane_tool.searchResults(
            getUserName='******')
        self.assertEqual(
            user[0].getObject().email,
            email,
            'User not updated',
        )
Exemple #3
0
    def test_create_update_users(self):
        view = CSVImportView(self.profiles, self.request)
        user_fields_file_loc = self._get_fixture_location('basic_users.csv')
        with open(user_fields_file_loc) as bf:
            filedata = self._parse_file(bf.read())

        self.assertEqual(len(self.profiles.objectValues()), 0)

        count = view.create_update_users(filedata)
        self.assertEqual(count, 2)
        self.assertEqual(len(self.profiles.objectValues()), 2,
                         "Users not created")

        # validation failure on duplicate username
        with self.assertRaises(custom_exc.DuplicateUser):
            view.create_update_users(filedata)

        file_loc = self._get_fixture_location('missing_first_name.csv')
        with open(file_loc) as bf:
            filedata = self._parse_file(bf.read())

        # validation failure on missing required field
        with self.assertRaises(schema.interfaces.RequiredMissing):
            view.create_update_users(filedata)
        # Even though an exception was raised we will have an extra user
        # here as the transaction is handled by the process method
        self.assertEqual(len(self.profiles.objectValues()), 3,
                         "Users not created")

        # now update one of the users
        user_fields_file_loc = self._get_fixture_location('basic_users.csv')
        with open(user_fields_file_loc) as bf:
            filedata = self._parse_file(bf.read())
        raw = filedata.csv
        email = '*****@*****.**'
        raw = raw.replace('*****@*****.**', email)
        filedata.csv = raw

        view.create_update_users(filedata, update=True)
        self.assertEqual(
            len(self.profiles.objectValues()),
            3,
            "Users not created correctly",
        )
        user = self.membrane_tool.searchResults(getUserId='foo')
        self.assertEqual(
            user[0].getObject().email,
            email,
            'User not updated',
        )