Exemplo n.º 1
0
    def _run_percentage_filled_test(self, remove):
        self.set_logged()
        user = self.userdb_new.get_user_by_mail('*****@*****.**')
        assert isinstance(user, User)  # for the IDE
        saved_user = User(data=user.to_dict(
        ))  # save the original user to be able to restore it after the test

        # Remove those parts of the user information that are listed in `remove'
        if 'surname' in remove:
            user.surname = None
        if 'display_name' in remove:
            user.display_name = None
        if 'given_name' in remove:
            user.given_name = None
        if 'language' in remove:
            user.language = None
        if 'mail_addresses' in remove:
            self._empty_user_list(user.mail_addresses)
        if 'phone_numbers' in remove:
            self._empty_user_list(user.phone_numbers)
        if 'nins' in remove:
            self._empty_user_list(user.nins)
        self._save_user_to_userdb(user)

        import pprint
        logger.debug('SAVED USER TO DB:\n{!s}'.format(
            pprint.pformat(user.to_dict())))

        response = self.testapp.get('/profile/userstatus/')
        self._save_user_to_userdb(saved_user)
        logger.debug('RESTORED USER IN DB:\n{!s}'.format(
            pprint.pformat(saved_user.to_dict())))
        return json.loads(response.body)['profile_filled']
Exemplo n.º 2
0
    def _run_percentage_filled_test(self, remove):
        self.set_logged()
        user = self.userdb_new.get_user_by_mail('*****@*****.**')
        assert isinstance(user, User)  # for the IDE
        saved_user = User(data=user.to_dict())  # save the original user to be able to restore it after the test

        # Remove those parts of the user information that are listed in `remove'
        if 'surname' in remove:
            user.surname = None
        if 'display_name' in remove:
            user.display_name = None
        if 'given_name' in remove:
            user.given_name = None
        if 'language' in remove:
            user.language = None
        if 'mail_addresses' in remove:
            self._empty_user_list(user.mail_addresses)
        if 'phone_numbers' in remove:
            self._empty_user_list(user.phone_numbers)
        if 'nins' in remove:
            self._empty_user_list(user.nins)
        self._save_user_to_userdb(user)

        import pprint
        logger.debug('SAVED USER TO DB:\n{!s}'.format(pprint.pformat(user.to_dict())))

        response = self.testapp.get('/profile/userstatus/')
        self._save_user_to_userdb(saved_user)
        logger.debug('RESTORED USER IN DB:\n{!s}'.format(pprint.pformat(saved_user.to_dict())))
        return json.loads(response.body)['profile_filled']
Exemplo n.º 3
0
 def to_dict(self, old_userdb_format=False):
     res = User.to_dict(self, old_userdb_format=old_userdb_format)
     res['terminated'] = self.terminated
     return res
Exemplo n.º 4
0
class TestRemoveninFromUser(TestCase):

    def setUp(self):
        ninuser = deepcopy(MOCKED_USER_STANDARD)
        del ninuser['norEduPersonNIN']
        ninuser.update({
            'nins':
                [{'number': '1111',
                  'verified': True,
                  'primary': True,
                  },
                 {'number': '2222',
                  'verified': True,
                  },
                 {'number': '0000',
                  'verified': False,
                  }],
        })
        self.ninuser = User(data = ninuser)

    def test_remove_primary_nin(self):
        """ Remove the primary address and expect the next verified one to be promoted to primary """
        this = _remove_nin_from_user('1111', self.ninuser)
        expected = [{'number': '2222',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '0000',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_remove_verified_nin(self):
        """ Remove a verified non-primary address """
        this = _remove_nin_from_user('2222', self.ninuser)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '0000',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_remove_nonverified_nin(self):
        """ Remove a non-verified address, although this user would not be found in reality """
        this = _remove_nin_from_user('0000', self.ninuser)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '2222',
                     'verified': True,
                     'primary': False,
                     }]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_add_new_number(self):
        """ Add a new number to the test user """
        this = self.ninuser
        _add_nin_to_user('3333', this)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '2222',
                     'verified': True,
                     'primary': False,
                     },
                    {'number': '0000',
                     'verified': False,
                     'primary': False,
                     },
                    {'number': '3333',
                     'verified': True,
                     'primary': False,
                     'created_by': 'dashboard',
                     }
                    ]
        got = this.nins.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            if addr.get('number') == '3333':
                del addr['created_ts']
        self.assertEqual(got, expected)

    def test_verify_existing_number(self):
        """ Verify an existing number on the test user """
        this = self.ninuser
        _add_nin_to_user('0000', this)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '2222',
                     'verified': True,
                     'primary': False,
                     },
                    {'number': '0000',
                     'verified': True,
                     'primary': False,
                     },
                    ]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_add_first_number(self):
        """ Add an number to a test user that has none """
        userdoc = self.ninuser.to_dict()
        del userdoc['nins']
        this = User(data = userdoc)
        _add_nin_to_user('9999', this)
        expected = [{'number': '9999',
                     'verified': True,
                     'primary': True,
                     'created_by': 'dashboard',
                     }]
        got = this.nins.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            del addr['created_ts']
        self.assertEqual(got, expected)
Exemplo n.º 5
0
class TestRemoveMailFromUser(TestCase):

    def setUp(self):
        mailuser = deepcopy(MOCKED_USER_STANDARD)
        mailuser.update({
            'mail': '*****@*****.**',
            'mailAliases':
                [{'email': '*****@*****.**',
                  'verified': True,
                  },
                 {'email': '*****@*****.**',
                  'verified': True,
                  },
                 {'email': '*****@*****.**',
                  'verified': False,
                  }],
        })
        self.mailuser = User(data = mailuser)

    def test_remove_primary_mail(self):
        """ Remove the primary address and expect the next verified one to be promoted to primary """
        this = _remove_mail_from_user('*****@*****.**', self.mailuser)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_remove_verified_mail(self):
        """ Remove a verified non-primary address """
        this = _remove_mail_from_user('*****@*****.**', self.mailuser)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_remove_nonverified_mail(self):
        """ Remove a non-verified address, although this user would not be found in reality """
        this = _remove_mail_from_user('*****@*****.**', self.mailuser)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     }]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_add_new_email_address(self):
        """ Add a new email address to the test user """
        this = self.mailuser
        _add_mail_to_user('*****@*****.**', this)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     },
                    {'email': '*****@*****.**',
                     'verified': False,
                     'primary': False,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     'created_by': 'dashboard',
                     }
                    ]
        got = this.mail_addresses.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            if addr.get('email') == '*****@*****.**':
                del addr['created_ts']
        self.assertEqual(got, expected)

    def test_verify_existing_email_address(self):
        """ Verify an existing email address on the test user """
        this = self.mailuser
        _add_mail_to_user('*****@*****.**', this)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     },
                    ]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_add_first_email_address(self):
        """ Add an email address to a test user that has none """
        userdoc = self.mailuser.to_dict()
        del userdoc['mailAliases']
        this = User(data = userdoc)
        _add_mail_to_user('*****@*****.**', this)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     'created_by': 'dashboard',
                     }]
        got = this.mail_addresses.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            del addr['created_ts']
        self.assertEqual(got, expected)
Exemplo n.º 6
0
class TestRemoveninFromUser(TestCase):

    def setUp(self):
        ninuser = deepcopy(MOCKED_USER_STANDARD)
        del ninuser['norEduPersonNIN']
        ninuser.update({
            'nins':
                [{'number': '1111',
                  'verified': True,
                  'primary': True,
                  },
                 {'number': '2222',
                  'verified': True,
                  },
                 {'number': '0000',
                  'verified': False,
                  }],
        })
        self.ninuser = User(data = ninuser)

    def test_remove_primary_nin(self):
        """ Remove the primary address and expect the next verified one to be promoted to primary """
        this = _remove_nin_from_user('1111', self.ninuser)
        expected = [{'number': '2222',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '0000',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_remove_verified_nin(self):
        """ Remove a verified non-primary address """
        this = _remove_nin_from_user('2222', self.ninuser)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '0000',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_remove_nonverified_nin(self):
        """ Remove a non-verified address, although this user would not be found in reality """
        this = _remove_nin_from_user('0000', self.ninuser)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '2222',
                     'verified': True,
                     'primary': False,
                     }]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_add_new_number(self):
        """ Add a new number to the test user """
        this = self.ninuser
        _add_nin_to_user('3333', this)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '2222',
                     'verified': True,
                     'primary': False,
                     },
                    {'number': '0000',
                     'verified': False,
                     'primary': False,
                     },
                    {'number': '3333',
                     'verified': True,
                     'primary': False,
                     'created_by': 'dashboard',
                     }
                    ]
        got = this.nins.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            if addr.get('number') == '3333':
                del addr['created_ts']
        self.assertEqual(got, expected)

    def test_verify_existing_number(self):
        """ Verify an existing number on the test user """
        this = self.ninuser
        now = datetime.datetime.utcnow()
        _add_nin_to_user('0000', this, created_ts = now)
        expected = [{'number': '1111',
                     'verified': True,
                     'primary': True,
                     },
                    {'number': '2222',
                     'verified': True,
                     'primary': False,
                     },
                    {'number': '0000',
                     'verified': True,
                     'primary': False,
                     'created_by': 'dashboard',
                     'created_ts': now,
                     },
                    ]
        self.assertEqual(this.nins.to_list_of_dicts(), expected)

    def test_add_first_number(self):
        """ Add an number to a test user that has none """
        userdoc = self.ninuser.to_dict()
        del userdoc['nins']
        this = User(data = userdoc)
        _add_nin_to_user('9999', this)
        expected = [{'number': '9999',
                     'verified': True,
                     'primary': True,
                     'created_by': 'dashboard',
                     }]
        got = this.nins.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            del addr['created_ts']
        self.assertEqual(got, expected)
Exemplo n.º 7
0
class TestRemoveMailFromUser(TestCase):

    def setUp(self):
        mailuser = deepcopy(MOCKED_USER_STANDARD)
        mailuser.update({
            'mail': '*****@*****.**',
            'mailAliases':
                [{'email': '*****@*****.**',
                  'verified': True,
                  },
                 {'email': '*****@*****.**',
                  'verified': True,
                  },
                 {'email': '*****@*****.**',
                  'verified': False,
                  }],
        })
        self.mailuser = User(data = mailuser)

    def test_remove_primary_mail(self):
        """ Remove the primary address and expect the next verified one to be promoted to primary """
        this = _remove_mail_from_user('*****@*****.**', self.mailuser)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_remove_verified_mail(self):
        """ Remove a verified non-primary address """
        this = _remove_mail_from_user('*****@*****.**', self.mailuser)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': False,
                     'primary': False,
                     }]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_remove_nonverified_mail(self):
        """ Remove a non-verified address, although this user would not be found in reality """
        this = _remove_mail_from_user('*****@*****.**', self.mailuser)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     }]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_add_new_email_address(self):
        """ Add a new email address to the test user """
        this = self.mailuser
        _add_mail_to_user('*****@*****.**', this)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     },
                    {'email': '*****@*****.**',
                     'verified': False,
                     'primary': False,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     'created_by': 'dashboard',
                     }
                    ]
        got = this.mail_addresses.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            if addr.get('email') == '*****@*****.**':
                del addr['created_ts']
        self.assertEqual(got, expected)

    def test_verify_existing_email_address(self):
        """ Verify an existing email address on the test user """
        this = self.mailuser
        _add_mail_to_user('*****@*****.**', this)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     },
                    {'email': '*****@*****.**',
                     'verified': True,
                     'primary': False,
                     },
                    ]
        self.assertEqual(this.mail_addresses.to_list_of_dicts(), expected)

    def test_add_first_email_address(self):
        """ Add an email address to a test user that has none """
        userdoc = self.mailuser.to_dict()
        del userdoc['mailAliases']
        this = User(data = userdoc)
        _add_mail_to_user('*****@*****.**', this)
        expected = [{'email': '*****@*****.**',
                     'verified': True,
                     'primary': True,
                     'created_by': 'dashboard',
                     }]
        got = this.mail_addresses.to_list_of_dicts()
        # remove the 'created_ts' from the new entry
        for addr in got:
            del addr['created_ts']
        self.assertEqual(got, expected)
Exemplo n.º 8
0
 def to_dict(self, old_userdb_format=False):
     res = User.to_dict(self, old_userdb_format=old_userdb_format)
     if self._pending_mail_address is not None:
         res['pending_mail_address'] = self._pending_mail_address.to_dict()
     return res