Beispiel #1
0
    def setUp(self):
        self.ctx = self.app.test_request_context()
        self.ctx.push()
        db.create_all()
        # Initial Setup
        random_user_id = buid()
        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=u"SpaceCon", userid=self.user.userid)
        db.session.add(self.profile)
        db.session.commit()

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

        self.ticket_client = TicketClient(name=u"test client", client_eventid=u'123', clientid=u'123', client_secret=u'123', client_access_token=u'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
    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
Beispiel #3
0
def find_projects(starting_times, within, gap):
    # Keep the timestamps at which projects were found, plus the project. Criteria:
    # starts at `timestamp` + up to `within` period, with `gap` from prior sessions
    return {
        timestamp: found
        for timestamp, found in {
            timestamp: Project.starting_at(timestamp, within, gap).all()
            for timestamp in starting_times
        }.items() if found
    }
Beispiel #4
0
def create_project2(test_db_structure, create_organization, create_user_owner):
    user_owner = test_db_structure.session.merge(create_user_owner)
    organization = test_db_structure.session.merge(create_organization)
    project = Project(
        profile=organization.profile,
        user=user_owner,
        title="Test Project",
        tagline="Test tagline",
        description="Test description",
        location="Test Location",
    )
    test_db_structure.session.add(project)
    test_db_structure.session.commit()
    return project
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())
Beispiel #6
0
class TestEventModels(unittest.TestCase):
    app = app

    def setUp(self):
        self.ctx = self.app.test_request_context()
        self.ctx.push()
        db.create_all()
        # Initial Setup
        random_user_id = buid()
        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=u"SpaceCon", userid=self.user.userid)
        db.session.add(self.profile)
        db.session.commit()

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

        self.ticket_client = TicketClient(name=u"test client", client_eventid=u'123', clientid=u'123', client_secret=u'123', client_access_token=u'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

    def tearDown(self):
        self.session.rollback()
        db.drop_all()
        self.ctx.pop()

    def test_import_from_list(self):
        # test bookings
        self.ticket_client.import_from_list(ticket_list)
        p1 = Participant.query.filter_by(email=u'*****@*****.**', project=self.project).one_or_none()
        p2 = Participant.query.filter_by(email=u'*****@*****.**', project=self.project).one_or_none()
        p3 = Participant.query.filter_by(email=u'*****@*****.**', project=self.project).one_or_none()
        self.assertEquals(SyncTicket.query.count(), 3)
        self.assertEquals(Participant.query.count(), 3)
        self.assertEquals(len(p1.events), 2)
        self.assertEquals(len(p2.events), 1)
        self.assertEquals(len(p3.events), 1)

        # test cancellations
        self.ticket_client.import_from_list(ticket_list2)
        self.assertEquals(len(p1.events), 2)
        self.assertEquals(len(p2.events), 0)
        self.assertEquals(len(p3.events), 1)

        # test_transfers
        self.ticket_client.import_from_list(ticket_list3)
        p4 = Participant.query.filter_by(email=u'*****@*****.**', project=self.project).one_or_none()
        self.assertEquals(len(p1.events), 2)
        self.assertEquals(len(p2.events), 0)
        self.assertEquals(len(p3.events), 0)
        self.assertEquals(len(p4.events), 1)
class TestEventModels(unittest.TestCase):
    app = app

    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

    def tearDown(self):
        self.session.rollback()
        db.drop_all()
        self.ctx.pop()

    def test_import_from_list(self):
        # test bookings
        self.ticket_client.import_from_list(ticket_list)
        p1 = TicketParticipant.query.filter_by(
            email_address=EmailAddress.get('*****@*****.**'),
            project=self.project,
        ).one_or_none()
        p2 = TicketParticipant.query.filter_by(
            email_address=EmailAddress.get('*****@*****.**'),
            project=self.project,
        ).one_or_none()
        p3 = TicketParticipant.query.filter_by(
            email_address=EmailAddress.get('*****@*****.**'),
            project=self.project,
        ).one_or_none()
        self.assertEqual(SyncTicket.query.count(), 3)
        self.assertEqual(TicketParticipant.query.count(), 3)
        self.assertEqual(len(p1.ticket_events), 2)
        self.assertEqual(len(p2.ticket_events), 1)
        self.assertEqual(len(p3.ticket_events), 1)

        # test cancellations
        self.ticket_client.import_from_list(ticket_list2)
        self.assertEqual(len(p1.ticket_events), 2)
        self.assertEqual(len(p2.ticket_events), 0)
        self.assertEqual(len(p3.ticket_events), 1)

        # test_transfers
        self.ticket_client.import_from_list(ticket_list3)
        p4 = TicketParticipant.query.filter_by(
            email_address=EmailAddress.get('*****@*****.**'),
            project=self.project,
        ).one_or_none()
        self.assertEqual(len(p1.ticket_events), 2)
        self.assertEqual(len(p2.ticket_events), 0)
        self.assertEqual(len(p3.ticket_events), 0)
        self.assertEqual(len(p4.ticket_events), 1)