コード例 #1
0
    def test_list(self):
        """The index page should display the complete and correct user
        information."""

        # Get time now for superuser's last login time
        login_time = datetime.now(tz=timezone.utc)

        LoginPage(self).login(self.superuser['username'],
                              self.superuser['password'])

        users_page = UsersPage(self)
        users_page.go_to()

        users = self.test_data['users']
        assert users_page.get_num_users() == len(users)

        # Construct list of orgs each user is in
        # (Basically, invert the '_members' test data)
        for user in users:
            user['orgs'] = []
        for org in self.test_data['orgs']:
            for idx in org['_members']:
                users[idx]['orgs'].append(org)

        for user in users:

            username = user['username']

            # Check full name is displayed correctly
            full_name = user.get('full_name', '')
            expected_name = '{}\n{}'.format(username, full_name).strip()
            actual_name = users_page.get_user_name(username)
            assert actual_name == expected_name

            # Check email is displayed correctly
            expected_email = user['email'] or '—'
            actual_email = users_page.get_user_email(username)
            assert actual_email == expected_email

            # Check organizations are displayed correctly
            actual_orgs = users_page.get_user_orgs(username)
            if len(user['orgs']) == 0:
                assert actual_orgs == '—'
            else:
                for org in user['orgs']:
                    assert org['name'] in actual_orgs
                    actual_orgs = actual_orgs.replace(org['name'], '')
                assert re.match('^[, ]*$', actual_orgs)

            # Check last login is displayed correctly
            if user == self.superuser:
                # Fuzzy checking for superuser
                try:
                    self.check_last_login(username, login_time)
                except AssertionError:
                    login_time = login_time + timedelta(minutes=1)
                    self.check_last_login(username, login_time)
            else:
                self.check_last_login(username, user['last_login'])

            # Check active status is displayed correctly
            assert (
                users_page.is_user_active(username) ==
                bool(user['is_active'])
            )