def insert_a_role(name): try: role = RoleFactory(name=name) role.save() return role except IntegrityError: db.session.rollback() return Role.query.filter(Role.name == name).first()
def test_can_edit_is_public(self): staff = UserFactory.build(roles=[RoleFactory.build(name='staff')]) creator = UserFactory.build(roles=[RoleFactory.build(name='staff')]) admin = UserFactory.build(roles=[RoleFactory.build(name='admin')]) opportunity = OpportunityFactory.build( is_public=True, planned_publish=self.yesterday, planned_submission_start=self.today, planned_submission_end=self.tomorrow, created_by=creator, created_by_id=creator.id, contact_id=creator.id ) self.assertFalse(opportunity.can_edit(staff)) self.assertFalse(opportunity.can_edit(creator)) self.assertTrue(opportunity.can_edit(admin))
def test_can_edit_is_public(self): staff = UserFactory.build(role=RoleFactory.build(name='staff')) creator = UserFactory.build(role=RoleFactory.build(name='staff')) admin = UserFactory.build(role=RoleFactory.build(name='admin')) opportunity = OpportunityFactory.build( is_public=True, planned_publish=self.yesterday, planned_submission_start=self.today, planned_submission_end=self.tomorrow, created_by=creator, created_by_id=creator.id, contact_id=creator.id) self.assertFalse(opportunity.can_edit(staff)) self.assertFalse(opportunity.can_edit(creator)) self.assertTrue(opportunity.can_edit(admin))
def setUp(self): super(TestBeaconJobs, self).setUp() self.yesterday = datetime.datetime.today() - datetime.timedelta(days=1) today = datetime.datetime.today() tomorrow = datetime.datetime.today() + datetime.timedelta(days=1) self.category = CategoryFactory.create() admin_role = RoleFactory.create(name='admin') self.admin = UserFactory.create(roles=[admin_role]) self.opportunity = OpportunityFactory.create( is_public=True, planned_publish=today, planned_submission_start=today, planned_submission_end=tomorrow, categories=set([self.category]), created_by=self.admin, published_at=today ) self.opportunity2 = OpportunityFactory.create( is_public=True, planned_publish=self.yesterday, planned_submission_start=today, planned_submission_end=tomorrow, publish_notification_sent=True, categories=set([self.category]), created_by=self.admin, published_at=self.yesterday ) self.opportunity3 = OpportunityFactory.create( is_public=False, planned_publish=today, planned_submission_start=today, planned_submission_end=tomorrow, publish_notification_sent=False, categories=set([self.category]), created_by=self.admin, published_at=today ) self.opportunity4 = OpportunityFactory.create( is_public=True, planned_publish=self.yesterday, planned_submission_start=self.yesterday, planned_submission_end=today, publish_notification_sent=True, categories=set([self.category]), created_by=self.admin, published_at=self.yesterday ) VendorFactory.create(opportunities=set([self.opportunity])) VendorFactory.create(categories=set([self.category]))
def insert_a_user(email=None, department=None, role=None): role = role if role else RoleFactory.create() try: if email: user = UserFactory.create(email=email, role=role, department=department) else: user = UserFactory.create(role=role, department=department) return user except IntegrityError: db.session.rollback() return User.query.filter(User.email == email).first()
def insert_a_user(email=None, department=None, role=None, pw="password"): role = role if role else RoleFactory.create() try: if email: user = UserFactory.create( email=email, roles=[role], department=department, confirmed_at=datetime.datetime.now(), password=pw ) else: user = UserFactory.create( roles=[role], department=department, password=pw, confirmed_at=datetime.datetime.now() ) return user except IntegrityError: db.session.rollback() return User.query.filter(User.email == email).first()
def insert_a_user(email=None, department=None, role=None, pw='password'): role = role if role else RoleFactory.create() try: if email: user = UserFactory.create( email=email, roles=[role], department=department, confirmed_at=datetime.datetime.now(), password=pw ) else: user = UserFactory.create( roles=[role], department=department, password=pw, confirmed_at=datetime.datetime.now() ) return user except IntegrityError: db.session.rollback() return User.query.filter(User.email == email).first()
def setUp(self): super(TestUsers, self).setUp() RoleFactory.create(name='staff') AcceptedEmailDomainsFactory.create(domain='foo.com')