예제 #1
0
def test_user_notification_preferences(notification_types, db_transaction):
    """Test that users have a notification_preferences dict."""
    db = db_transaction
    user = User(fullname="User")
    db.session.add(user)
    db.session.commit()
    assert user.notification_preferences == {}
    np = NotificationPreferences(
        user=user,
        notification_type=notification_types.TestNewUpdateNotification.cls_type,
    )
    db.session.add(np)
    db.session.commit()
    assert set(user.notification_preferences.keys()) == {'update_new_test'}
    assert user.notification_preferences['update_new_test'] == np
    assert user.notification_preferences['update_new_test'].user == user
    assert (
        user.notification_preferences['update_new_test'].type_cls
        == notification_types.TestNewUpdateNotification
    )

    # There cannot be two sets of preferences for the same notification type
    with pytest.raises(IntegrityError):
        db.session.add(
            NotificationPreferences(
                user=user,
                notification_type=notification_types.TestNewUpdateNotification.cls_type,
            )
        )
        db.session.commit()
    db.session.rollback()

    # Preferences cannot be set for invalid types
    with pytest.raises(ValueError):
        NotificationPreferences(user=user, notification_type='invalid')

    # Preferences can be set for other notification types though
    np2 = NotificationPreferences(
        user=user,
        notification_type=notification_types.TestProposalReceivedNotification.cls_type,
    )
    db.session.add(np2)
    db.session.commit()
    assert set(user.notification_preferences.keys()) == {
        'update_new_test',
        'proposal_received_test',
    }
예제 #2
0
    def setUp(self):
        self.ctx = self.app.test_request_context()
        self.ctx.push()
        db.create_all()
        # Initial Setup
        random_user_id = uuid_b58()
        self.user = User(
            username='******'.format(userid=random_user_id.lower()),
            fullname="Luke Skywalker",
            email='luke{userid}@dagobah.org'.format(userid=random_user_id),
        )

        db.session.add(self.user)
        db.session.commit()

        self.organization = Organization(name='spacecon',
                                         title="SpaceCon",
                                         owner=self.user)
        db.session.add(self.organization)
        db.session.commit()
        self.profile = self.organization.profile

        self.project = Project(
            title="20000 AD",
            tagline="In a galaxy far far away...",
            profile=self.profile,
            user=self.user,
        )
        db.session.add(self.project)
        self.project.make_name()
        db.session.commit()

        self.ticket_client = TicketClient(
            name="test client",
            client_eventid='123',
            clientid='123',
            client_secret='123',
            client_access_token='123',
            project=self.project,
        )
        db.session.add(self.ticket_client)
        db.session.commit()

        bulk_upsert(self.project, event_ticket_types)
        db.session.commit()

        self.session = db.session
예제 #3
0
    def setUp(self):
        self.ctx = self.app.test_request_context()
        self.ctx.push()
        init_for('test')
        db.create_all()
        # Initial Setup
        random_user_id = random.randint(1, 1000)
        self.user = User(
            userid=unicode(random_user_id),
            username=u'lukes{userid}'.format(userid=random_user_id),
            fullname=u"Luke Skywalker",
            email=u'luke{userid}@dagobah.org'.format(userid=random_user_id))

        db.session.add(self.user)
        db.session.commit()

        self.profile = Profile(title='SpaceCon', userid=self.user.userid)
        db.session.add(self.profile)
        db.session.commit()

        self.space = ProposalSpace(title='20000 AD',
                                   tagline='In a galaxy far far away...',
                                   profile=self.profile,
                                   user=self.user)
        db.session.add(self.space)
        db.session.commit()

        self.ticket_client = TicketClient(name="test client",
                                          client_eventid='123',
                                          clientid='123',
                                          client_secret='123',
                                          client_access_token='123',
                                          proposal_space=self.space)
        db.session.add(self.ticket_client)
        db.session.commit()

        bulk_upsert(self.space, event_ticket_types)
        db.session.commit()

        self.session = db.session
예제 #4
0
def create_user(test_db_structure):
    user = User(**TEST_DATA['users']['testuser'])
    test_db_structure.session.add(user)
    test_db_structure.session.commit()
    return user
예제 #5
0
def project_fixtures(test_db_structure, test_client):
    """Provide users, one org and one project, for tests on them."""
    db = test_db_structure

    user_owner = User(username='******', fullname="User Owner")
    user_owner.add_email('*****@*****.**')

    user_editor = User(username='******', fullname="User Editor")
    user_editor.add_email('*****@*****.**')
    user_editor_phone = UserPhone(user=user_editor, phone='+1234567890')

    user_participant = User(username='******', title="User Participant")

    user_cancelled_participant = User(
        username='******', title="User Cancelled Participant"
    )
    user_bystander = User(username='******', title="User Bystander")
    user_suspended = User(username='******', title="User Suspended")
    user_suspended.add_email('*****@*****.**')

    org = Organization(name='notifications-org', title="Organization", owner=user_owner)

    db.session.add_all(
        [
            user_owner,
            user_editor,
            user_editor_phone,
            user_participant,
            user_bystander,
            org,
        ]
    )
    db.session.commit()
    profile = org.profile
    project = Project(
        profile=profile,
        user=user_owner,
        title="Notifications project",
        tagline="Test notification delivery",
    )
    db.session.add(project)
    db.session.add(
        ProjectCrewMembership(project=project, user=user_editor, is_editor=True)
    )
    rsvp_y = Rsvp(project=project, user=user_participant)
    rsvp_y.rsvp_yes()
    rsvp_n = Rsvp(project=project, user=user_cancelled_participant)
    rsvp_n.rsvp_yes()
    rsvp_n.rsvp_no()
    rsvp_suspended = Rsvp(project=project, user=user_suspended)
    rsvp_suspended.rsvp_yes()
    user_suspended.status = USER_STATUS.SUSPENDED
    db.session.add_all([rsvp_y, rsvp_n, rsvp_suspended])
    db.session.commit()

    refresh_attrs = [attr for attr in locals().values() if isinstance(attr, db.Model)]

    def refresh():
        for attr in refresh_attrs:
            db.session.add(attr)

    return SimpleNamespace(**locals())
예제 #6
0
    def make_fixtures(self):
        """
        Create users, attach them to organizations. Create test client app, add test
        resource, action and message.
        """
        crusoe = User(username="******", fullname="Crusoe Celebrity Dachshund")
        oakley = User(username="******")
        piglet = User(username="******")
        nameless = User(fullname="Nameless")

        db.session.add_all([crusoe, oakley, piglet, nameless])
        self.crusoe = crusoe
        self.oakley = oakley
        self.piglet = piglet
        self.nameless = nameless

        crusoe_email = UserEmail(email="*****@*****.**",
                                 user=crusoe,
                                 primary=True)
        crusoe_phone = UserPhone(phone="+8080808080",
                                 user=crusoe,
                                 primary=True)
        oakley_email = UserEmail(email="*****@*****.**", user=oakley)
        db.session.add_all([crusoe_email, crusoe_phone, oakley_email])
        self.crusoe_email = crusoe_email
        self.crusoe_phone = crusoe_phone

        batdog = Organization(name='batdog', title='Batdog', owner=crusoe)
        db.session.add(batdog)
        self.batdog = batdog

        specialdachs = Organization(name="specialdachs",
                                    title="Special Dachshunds",
                                    owner=oakley)
        db.session.add(specialdachs)
        self.specialdachs = specialdachs

        auth_client = AuthClient(
            title="Batdog Adventures",
            organization=batdog,
            confidential=True,
            namespace='fun.batdogadventures.com',
            website="http://batdogadventures.com",
        )
        db.session.add(auth_client)
        self.auth_client = auth_client

        dachshunds = Team(title="Dachshunds", organization=batdog)
        db.session.add(dachshunds)
        self.dachshunds = dachshunds

        auth_client_team_permissions = AuthClientTeamPermissions(
            team=dachshunds,
            auth_client=auth_client,
            access_permissions="admin")
        self.auth_client_team_permissions = auth_client_team_permissions
        db.session.add(auth_client_team_permissions)

        auth_client_user_permissions = AuthClientUserPermissions(
            user=crusoe, auth_client=auth_client)
        db.session.add(auth_client_user_permissions)
        self.auth_client_user_permissions = auth_client_user_permissions

        message = SMSMessage(
            phone_number=crusoe_phone.phone,
            transactionid="Ruff" * 5,
            message="Wuff Wuff",
        )
        db.session.add(message)
        db.session.commit()
        self.message = message
def init_models():
    with app.test_request_context():
        db.drop_all()
        db.create_all()

        user_admin = User(username='******', fullname='admin-user')
        user_admin._set_password('admin-user129_Ftz')
        user_admin_email = UserEmail(email='*****@*****.**',
                                     user=user_admin)

        user = User(username='******', fullname='member-user')
        user._set_password('member-user341_Wer')
        user_email = UserEmail(email='*****@*****.**', user=user)

        profile_owner = User(username='******',
                             fullname='profile-cypress')
        profile_owner._set_password('profile-cypress123_St')
        profile_owner_email = UserEmail(email='*****@*****.**',
                                        user=profile_owner)

        concierge = User(username='******', fullname='concierge-user')
        concierge._set_password('concierge-user34_qQE')
        concierge_email = UserEmail(email='*****@*****.**',
                                    user=concierge)

        usher = User(username='******', fullname='usher-cypress')
        usher._set_password('usher-cypress566_YUt')
        usher_email = UserEmail(email='*****@*****.**', user=usher)

        editor = User(username='******', fullname='editor-cypress')
        editor._set_password('editor-cypress9_GH')
        editor_email = UserEmail(email='*****@*****.**', user=editor)

        user2 = User(username='******', fullname='hg-user')
        user2._set_password('hg-user5_HE')

        db.session.add_all([
            user_admin,
            user_admin_email,
            user,
            user_email,
            profile_owner,
            profile_owner_email,
            concierge,
            concierge_email,
            usher,
            usher_email,
            editor,
            editor_email,
            user2,
        ])
        db.session.commit()