def test_cohorts_index_with_cohorts(pyramid_request): cohort1 = models.FeatureCohort(name='cohort1') cohort2 = models.FeatureCohort(name='cohort2') pyramid_request.db.add(cohort1) pyramid_request.db.add(cohort2) pyramid_request.db.flush() result = cohorts_index({}, pyramid_request) assert len(result["results"]) == 2
def test_cohorts_index_with_cohorts(): req = DummyRequest(db=db.Session) cohort1 = models.FeatureCohort(name='cohort1') cohort2 = models.FeatureCohort(name='cohort2') db.Session.add(cohort1) db.Session.add(cohort2) db.Session.flush() result = views.cohorts_index({}, req) assert len(result["results"]) == 2
def cohorts_add(request): """Create a new feature cohort.""" cohort_name = request.params["add"] cohort = models.FeatureCohort(name=cohort_name) request.db.add(cohort) url = request.route_url("admin.cohorts") return httpexceptions.HTTPSeeOther(url)
def test_cohorts_edit_with_no_users(pyramid_request): cohort = models.FeatureCohort(name="FractalCohort") pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict["id"] = cohort.id result = cohorts_edit({}, pyramid_request) assert result["cohort"].id == cohort.id assert not result["cohort"].members
def test_cohorts_edit_with_no_users(pyramid_request): cohort = models.FeatureCohort(name='FractalCohort') pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict['id'] = cohort.id result = cohorts_edit({}, pyramid_request) assert result['cohort'].id == cohort.id assert len(result['cohort'].members) == 0
def test_cohorts_edit_with_no_users(): req = DummyRequest(db=db.Session) cohort = models.FeatureCohort(name='FractalCohort') db.Session.add(cohort) db.Session.flush() req.matchdict['id'] = cohort.id result = views.cohorts_edit({}, req) assert result['cohort'].id == cohort.id assert len(result['cohort'].members) == 0
def test_cohorts_edit_add_user(factories, pyramid_request): user = factories.User(username='******') cohort = models.FeatureCohort(name='FractalCohort') pyramid_request.db.add(user) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict['id'] = cohort.id pyramid_request.params['add'] = user.username views.cohorts_edit_add(pyramid_request) assert len(cohort.members) == 1 assert cohort.members[0].username == user.username
def test_cohorts_edit_add_user_strips_spaces(factories, pyramid_request): user = factories.User(username="******", authority="foo.org") cohort = models.FeatureCohort(name="FractalCohort") pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict["id"] = cohort.id pyramid_request.params["add"] = " benoit " pyramid_request.params["authority"] = " %s " % user.authority cohorts_edit_add(pyramid_request) assert len(cohort.members) == 1 assert cohort.members[0].username == user.username
def test_cohorts_edit_add_user_strips_spaces(factories, pyramid_request): user = factories.User(username='******', authority='foo.org') cohort = models.FeatureCohort(name='FractalCohort') pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict['id'] = cohort.id pyramid_request.params['add'] = ' benoit ' pyramid_request.params['authority'] = ' %s ' % user.authority cohorts_edit_add(pyramid_request) assert len(cohort.members) == 1 assert cohort.members[0].username == user.username
def test_cohorts_edit_with_users(factories, pyramid_request): cohort = models.FeatureCohort(name='FractalCohort') user1 = factories.User(username='******') user2 = factories.User(username='******', authority='foo.org') cohort.members.append(user1) cohort.members.append(user2) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict['id'] = cohort.id result = cohorts_edit({}, pyramid_request) assert result['cohort'].id == cohort.id assert len(result['cohort'].members) == 2
def test_cohorts_edit_remove_user(factories, pyramid_request): user = factories.User(username='******', authority='foo.org') cohort = models.FeatureCohort(name='FractalCohort') cohort.members.append(user) pyramid_request.db.add(cohort) pyramid_request.db.flush() assert len(cohort.members) == 1 pyramid_request.matchdict['id'] = cohort.id pyramid_request.params['remove'] = user.userid cohorts_edit_remove(pyramid_request) assert len(cohort.members) == 0
def test_cohorts_edit_with_users(factories, pyramid_request): cohort = models.FeatureCohort(name="FractalCohort") user1 = factories.User(username="******") user2 = factories.User(username="******", authority="foo.org") cohort.members.append(user1) cohort.members.append(user2) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict["id"] = cohort.id result = cohorts_edit({}, pyramid_request) assert result["cohort"].id == cohort.id assert len(result["cohort"].members) == 2
def test_cohorts_edit_remove_user(factories, pyramid_request): user = factories.User(username="******", authority="foo.org") cohort = models.FeatureCohort(name="FractalCohort") cohort.members.append(user) pyramid_request.db.add(cohort) pyramid_request.db.flush() assert len(cohort.members) == 1 pyramid_request.matchdict["id"] = cohort.id pyramid_request.params["remove"] = user.userid cohorts_edit_remove(pyramid_request) assert len(cohort.members) == 0
def test_features_save_sets_cohorts_when_checkboxes_on(pyramid_request): feat = models.Feature(name='feat') cohort = models.FeatureCohort(name='cohort') pyramid_request.db.add(feat) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.POST = {'feat[cohorts][cohort]': 'on'} features_save(pyramid_request) feat = pyramid_request.db.query(models.Feature).filter_by(name='feat').first() cohort = pyramid_request.db.query(models.FeatureCohort).filter_by(name='cohort').first() assert len(feat.cohorts) == 1 assert cohort in feat.cohorts
def test_features_save_unsets_cohorts_when_checkboxes_off(pyramid_request): feat = models.Feature(name='feat') cohort = models.FeatureCohort(name='cohort') feat.cohorts.append(cohort) pyramid_request.db.add(feat) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.POST = {'feat[cohorts][cohort]': 'off'} views.features_save(pyramid_request) feat = pyramid_request.db.query(models.Feature).filter_by(name='feat').first() cohort = pyramid_request.db.query(models.FeatureCohort).filter_by(name='cohort').first() assert len(feat.cohorts) == 0 assert cohort not in feat.cohorts
def test_cohorts_edit_add_user(): req = DummyRequest(db=db.Session) user = models.User(username='******', password='******', email='*****@*****.**') cohort = models.FeatureCohort(name='FractalCohort') db.Session.add(user) db.Session.add(cohort) db.Session.flush() req.matchdict['id'] = cohort.id req.params['add'] = user.username views.cohorts_edit_add(req) assert len(cohort.members) == 1 assert cohort.members[0].username == user.username
def test_cohorts_delete(factories, pyramid_request): cohort = models.FeatureCohort(name="Test Cohort") # Add some members to the cohort. This is not essential, but it ensures # that this facility can be used to delete a cohort which still has members. user1 = factories.User(username="******") user2 = factories.User(username="******", authority="foo.org") cohort.members.append(user1) cohort.members.append(user2) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.matchdict["id"] = cohort.id result = cohorts_delete({}, pyramid_request) assert cohort in pyramid_request.db.deleted assert isinstance(result, HTTPFound)
def test_features_save_unsets_cohorts_when_checkboxes_off(pyramid_request): feat = models.Feature(name="feat") cohort = models.FeatureCohort(name="cohort") feat.cohorts.append(cohort) pyramid_request.db.add(feat) pyramid_request.db.add(cohort) pyramid_request.db.flush() pyramid_request.POST = {"feat[cohorts][cohort]": "off"} features_save(pyramid_request) feat = pyramid_request.db.query(models.Feature).filter_by(name="feat").first() cohort = ( pyramid_request.db.query(models.FeatureCohort).filter_by(name="cohort").first() ) assert len(feat.cohorts) == 0 assert cohort not in feat.cohorts
def test_cohorts_edit_with_users(): req = DummyRequest(db=db.Session) cohort = models.FeatureCohort(name='FractalCohort') user1 = models.User(username='******', password='******', email='*****@*****.**') user2 = models.User(username='******', password='******', email='*****@*****.**') cohort.members.append(user1) cohort.members.append(user2) db.Session.add(user1) db.Session.add(user2) db.Session.add(cohort) db.Session.flush() req.matchdict['id'] = cohort.id result = views.cohorts_edit({}, req) assert result['cohort'].id == cohort.id assert len(result['cohort'].members) == 2
def cohort(self): return models.FeatureCohort(name="cohort")