Пример #1
0
def populate(db):
    """
    Create some data for tests to use.

    Args:
        db (sqlalchemy.orm.session.Session): The database session.
    """
    user = models.User(name='guest')
    db.add(user)
    anonymous = models.User(name='anonymous')
    db.add(anonymous)
    provenpackager = models.Group(name='provenpackager')
    db.add(provenpackager)
    packager = models.Group(name='packager')
    db.add(packager)
    user.groups.append(packager)
    release = models.Release(name='F17',
                             long_name='Fedora 17',
                             id_prefix='FEDORA',
                             version='17',
                             dist_tag='f17',
                             stable_tag='f17-updates',
                             testing_tag='f17-updates-testing',
                             candidate_tag='f17-updates-candidate',
                             pending_signing_tag='f17-updates-signing-pending',
                             pending_testing_tag='f17-updates-testing-pending',
                             pending_stable_tag='f17-updates-pending',
                             override_tag='f17-override',
                             branch='f17',
                             state=models.ReleaseState.current,
                             create_automatic_updates=True,
                             package_manager=models.PackageManager.unspecified,
                             testing_repository=None)
    db.add(release)
    db.flush()
    # This mock will help us generate a consistent update alias.
    with mock.patch(target='uuid.uuid4', return_value='wat'):
        update = create_update(db, ['bodhi-2.0-1.fc17'])
    update.type = models.UpdateType.bugfix
    update.severity = models.UpdateSeverity.medium
    bug = models.Bug(bug_id=12345)
    db.add(bug)
    update.bugs.append(bug)

    comment = models.Comment(karma=1, text="wow. amaze.")
    db.add(comment)
    comment.user = user
    update.comments.append(comment)

    comment = models.Comment(karma=0, text="srsly.  pretty good.")
    comment.user = anonymous
    db.add(comment)
    update.comments.append(comment)

    db.add(update)

    db.commit()
Пример #2
0
    def test_allowed_via_group(self, gpcfp):
        """Ensure that packagers can be allowed via group membership."""
        user = self.db.query(models.User).filter_by(id=1).one()
        group = models.Group(name='infra-sig')
        self.db.add(group)
        user.groups.append(group)
        request = self.get_mock_request()

        validators.validate_acls(request)

        assert not len(request.errors)
        gpcfp.assert_called_once_with()
Пример #3
0
    def test_authorize_update_email_groups(self):
        """Make sure the email and the groups are updated upon login."""
        user = models.User(name='testuser', email='*****@*****.**')
        self.db.add(user)
        self.db.flush()
        user.groups = [
            models.Group(name="testgroup1"),
            models.Group(name="testgroup2")
        ]
        self.db.commit()

        request = testing.DummyRequest(path="/oidc/authorize",
                                       params={"state": "STATE"})
        set_session_data(request.session,
                         "STATE",
                         "state",
                         "STATE",
                         app_name="fedora")
        request.registry = self.registry
        request.db = self.db

        _fake_send = fake_send({
            "UserInfo": {
                "sub": "SUB",
                "nickname": "testuser",
                "email": "*****@*****.**",
                "groups": ["testgroup1", "testgroup3"],
            }
        })

        with mock.patch('requests.sessions.Session.send',
                        side_effect=_fake_send):
            response = authorize_oidc(request)

        assert response.status_code == 302
        user = models.User.get('testuser')
        assert user.email == "*****@*****.**"
        assert [g.name for g in user.groups] == ["testgroup1", "testgroup3"]