def test_new_application_without_existing_partner(self):
     createBasicSeason(db.session)
     testuser = User(username="******",
                     sub=decodedToken.get("sub"),
                     email="email",
                     fullname="Franky Frank")
     db.session.add(testuser)
     db.session.commit()
     mimetype = 'application/json'
     headers = {
         'Content-Type': mimetype,
         'Accept': mimetype,
         'Authorization': self.token,
         'AccessToken': self.accessToken
     }
     response = self.app.test_client().post(
         'http://localhost:5000/application/',
         headers=headers,
         data=json.dumps(
             dict(
                 username=testuser.username,
                 needs="Pepsi is better than coke",
                 comments="Not Pepsi, but Pepsi Max",
                 partnerUsername="******",
                 preferredRoom="d1",
                 seatRollover=True,
             )))
     expectedApplicationResponse = make_response(
         jsonify(
             needs="Pepsi is better than coke",
             comments="Not Pepsi, but Pepsi Max",
             id=1,
             status="SUBMITTED",
             user={
                 "id": 1,
                 "username": testuser.username,
                 "email": "email",
                 "fullname": "Franky Frank"
             },
             partnerApplication={},
             preferredRoom="d1",
             seatRollover=True,
             rank="WRITING_MASTER",
         ), 201)
     getApplication = self.app.test_client().get(
         'http://localhost:5000/application/byUser/1', headers=headers)
     assert expectedApplicationResponse.status == response.status
     assert json.loads(expectedApplicationResponse.data) == json.loads(
         response.data)
     assert getApplication.status == "200 OK"
     assert filterOnStatus(json.loads(getApplication.data)) == json.loads(
         expectedApplicationResponse.data)
def test_application_connect_to_seat(db_session):
    season = createBasicSeason(db_session)
    room = Room("D1", "kek")
    db_session.add(room)
    seat = Seat(name="D1", room=room, info="")
    db_session.add(seat)
    user = User(username="******",
                sub="sub",
                email="email",
                fullname="schnep scmep")
    db_session.add(user)
    application = Application(needs="",
                              comments="",
                              user=user,
                              partnerUsername="",
                              preferredRoom="d1",
                              seatRollover=True,
                              rank=Rank.WRITING_MASTER,
                              status=ApplicationStatus.SUBMITTED,
                              applicationSeason=season)
    db_session.add(application)
    db_session.commit()
    application.room_id = seat.room_id
    application.seat_id = seat.id
    assert application.seat is seat
    assert seat.application is application
def test_cascading(db_session):
    season = createBasicSeason(db_session)
    db_session.expire_all()
    db_session.delete(season)
    db_session.commit()
    dbapplication = db_session.query(Application).first()
    assert dbapplication is None
def test_multiple_applications_on_applicationSeason_should_fail(db_session):
    season = createBasicSeason(db_session)
    user = createUser(db_session)
    application1 = Application(needs="needs",
                               user=user,
                               partnerUsername="******",
                               comments="comments",
                               preferredRoom="pref",
                               seatRollover=True,
                               rank=Rank.WRITING_MASTER,
                               status=ApplicationStatus.SUBMITTED,
                               applicationSeason=season)
    db_session.add(application1)
    db_session.commit()
    with raises(IntegrityError):
        application2 = Application(needs="needs",
                                   user=user,
                                   partnerUsername="******",
                                   comments="comments",
                                   preferredRoom="pref",
                                   seatRollover=True,
                                   rank=Rank.WRITING_MASTER,
                                   status=ApplicationStatus.SUBMITTED,
                                   applicationSeason=season)
        db_session.add(application2)
        db_session.commit()
def test_cascading_seat(db_session):
    season = createBasicSeason(db_session)
    user = User(username="******",
                sub="sub",
                email="email",
                fullname="Man Man McMan")
    application = Application(needs="needs",
                              user=user,
                              partnerUsername="******",
                              comments="comments",
                              preferredRoom="pref",
                              seatRollover=True,
                              rank=Rank.WRITING_MASTER,
                              status=ApplicationStatus.SUBMITTED,
                              applicationSeason=season)
    room = Room(name="room", info="info")
    seat = Seat(name="d1", room=room, info="info")
    db_session.add(user)
    db_session.add(application)
    db_session.add(room)
    db_session.add(seat)
    db_session.commit()
    application.room_id = seat.room_id
    application.seat_id = seat.id
    assert application.seat is seat

    db_session.delete(application)
    db_session.commit()
    db_session.expire_all()

    dbseat = db_session.query(Seat).first()
    print(user.application)
    assert dbseat == seat
    assert dbseat.application is None
    assert user.application is None
 def test_update_application(self):
     season = createBasicSeason(db.session)
     testuser = createUser(db.session)
     testApplication = Application(ApplicationStatus.SUBMITTED,
                                   "Fanta is better than solo",
                                   user=testuser,
                                   partnerUsername="******",
                                   preferredRoom="d1",
                                   seatRollover=True,
                                   applicationSeason=season,
                                   comments="Not Pepsi, but Pepsi Max")
     db.session.add(testApplication)
     db.session.commit()
     mimetype = 'application/json'
     headers = {
         'Content-Type': mimetype,
         'Accept': mimetype,
         'Authorization': self.token,
         'AccessToken': self.accessToken
     }
     response = self.app.test_client().put(
         'http://localhost:5000/application/1',
         headers=headers,
         data=json.dumps(
             dict(
                 username=testuser.username,
                 needs="Pepsi is better than coke",
                 comments="Not Pepsi, but Pepsi Max",
                 partnerUsername="",
                 preferredRoom="d1",
                 seatRollover=True,
                 aRandomfield=True,
             )))
     expectedResponse = make_response(
         jsonify(
             needs="Pepsi is better than coke",
             comments="Not Pepsi, but Pepsi Max",
             id=1,
             status="SUBMITTED",
             user={
                 "id": 1,
                 "username": testuser.username,
                 "email": testuser.email,
                 "fullname": testuser.fullname
             },
             partnerApplication={},
             rank="OTHER",
             seat=None,
             preferredRoom="d1",
             seatRollover=True,
         ), 200)
     assert expectedResponse.status == response.status
     assert json.loads(expectedResponse.data) == json.loads(response.data)
     assert testApplication.to_json() == json.loads(response.data)
 def test_new_application_without_partner(self):
     createBasicSeason(db.session)
     testuser = createUser(db.session)
     mimetype = 'application/json'
     headers = {
         'Content-Type': mimetype,
         'Accept': mimetype,
         'Authorization': self.token,
         'AccessToken': self.accessToken
     }
     response = self.app.test_client().post(
         'http://localhost:5000/application/',
         headers=headers,
         data=json.dumps(
             dict(
                 username=testuser.username,
                 needs="Pepsi is better than coke",
                 comments="Not Pepsi, but Pepsi Max",
                 partnerUsername="",
                 preferredRoom="d1",
                 seatRollover=True,
             )))
     expectedResponse = make_response(
         jsonify(
             needs="Pepsi is better than coke",
             comments="Not Pepsi, but Pepsi Max",
             id=1,
             status="SUBMITTED",
             user={
                 "id": 1,
                 "username": testuser.username,
                 "email": "email",
                 "fullname": testuser.fullname
             },
             partnerApplication={},
             rank="WRITING_MASTER",
             preferredRoom="d1",
             seatRollover=True,
         ), 201)
     assert expectedResponse.status == response.status
     assert json.loads(expectedResponse.data) == json.loads(response.data)
Example #8
0
def registerApplicationMock(comments, user, needs, partnerUsername, preferredRoom, seatRollover, rank):
    return Application(
        status=ApplicationStatus.SUBMITTED,
        comments=comments,
        needs=needs,
        user=User(username="******", sub="sub", email="email", fullname="Schnep Schmep"),
        partnerUsername=partnerUsername,
        preferredRoom="d1",
        seatRollover=True,
        rank=rank,
        applicationSeason=createBasicSeason()
    ).to_json(), 201
 def test_update_application_with_partner(self):
     season = createBasicSeason(db.session)
     headers = {
         'Authorization': self.token,
         'AccessToken': self.accessToken,
         'Content-type': 'application/json'
     }
     testuser1 = User(username="******",
                      sub="sub",
                      email="email",
                      fullname="Franky Frank")
     testuser2 = User(username="******",
                      sub="uuid",
                      email="email",
                      fullname="Schmemail")
     db.session.add(testuser1)
     db.session.add(testuser2)
     db.session.commit()
     createUser(db.session)
     testApplication1 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than solo",
                                    user=testuser1,
                                    partnerUsername=testuser2.username,
                                    preferredRoom="d1",
                                    seatRollover=True,
                                    applicationSeason=season,
                                    comments="Not Pepsi, but Pepsi Max")
     testApplication2 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than solo",
                                    user=testuser2,
                                    partnerUsername=testuser1.username,
                                    preferredRoom="d1",
                                    seatRollover=True,
                                    applicationSeason=season,
                                    comments="Not Pepsi, but Pepsi Max")
     testApplication1.partnerApplication = testApplication2
     testApplication2.partnerApplication = testApplication1
     db.session.add(testApplication1)
     db.session.add(testApplication2)
     db.session.commit()
     assert testApplication1.partnerApplication is testApplication2
     assert testApplication2.partnerApplication is testApplication1
     self.app.test_client().put('http://localhost:5000/application/1',
                                headers=headers,
                                data=json.dumps(dict(partnerUsername="", )))
     assert testApplication1.partnerApplication is None
     assert testApplication2.partnerApplication is None
Example #10
0
 def test_get_all_applications(self):
     season = createBasicSeason(db.session)
     headers = {
         'Authorization': self.token,
         'AccessToken': self.accessToken
     }
     testuser1 = User(username="******",
                      sub="sub",
                      email="email",
                      fullname="Franky Frank")
     testuser2 = User(username="******",
                      sub="uuid",
                      email="email",
                      fullname="Schmemail")
     db.session.add(testuser1)
     db.session.add(testuser2)
     db.session.commit()
     createUser(db.session)
     testApplication1 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than solo",
                                    user=testuser1,
                                    partnerUsername="******",
                                    preferredRoom="d1",
                                    seatRollover=True,
                                    applicationSeason=season,
                                    comments="Not Pepsi, but Pepsi Max")
     testApplication2 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than solo",
                                    user=testuser2,
                                    partnerUsername="******",
                                    preferredRoom="d1",
                                    seatRollover=True,
                                    applicationSeason=season,
                                    comments="Not Pepsi, but Pepsi Max")
     db.session.add(testApplication1)
     db.session.add(testApplication2)
     db.session.commit()
     allApplications = self.app.test_client().get(
         'http://localhost:5000/application/all', headers=headers)
     assert allApplications.status == "200 OK"
     assert allApplications.data == jsonify(
         [testApplication1.to_json(),
          testApplication2.to_json()]).data
def test_proper_user_serialization(db_session):
    season = createBasicSeason(db_session)
    testuser1 = User(username="******",
                     sub="sub",
                     email="email",
                     fullname="Asbjørn ELEVG baby")
    db_session.add(testuser1)
    application = Application(needs="",
                              comments="",
                              user=testuser1,
                              partnerUsername=None,
                              preferredRoom="d1",
                              seatRollover=True,
                              rank=Rank.WRITING_MASTER,
                              status=ApplicationStatus.SUBMITTED,
                              applicationSeason=season)
    db_session.add(application)
    db_session.commit()
    dbapplication = db_session.query(Application).first()
    assert testuser1.to_json() == dbapplication.to_json()['user']
def test_cascading_partnerApplication(db_session):
    season = createBasicSeason(db_session)
    user1 = User(username="******",
                 sub="sub",
                 email="email",
                 fullname="Solvæng")
    application1 = Application(needs="needs",
                               user=user1,
                               partnerUsername="******",
                               comments="comments",
                               preferredRoom="pref",
                               seatRollover=True,
                               rank=Rank.WRITING_MASTER,
                               status=ApplicationStatus.SUBMITTED,
                               applicationSeason=season)
    user2 = User(username="******",
                 sub="sub2",
                 email="email2",
                 fullname="Sålvong")
    application2 = Application(needs="needs",
                               user=user2,
                               partnerUsername="******",
                               comments="comments",
                               preferredRoom="pref",
                               seatRollover=True,
                               rank=Rank.WRITING_MASTER,
                               status=ApplicationStatus.SUBMITTED,
                               applicationSeason=season)
    db_session.add(user1)
    db_session.add(user2)
    db_session.add(application1)
    db_session.add(application2)
    application1.partnerApplication = application2
    application2.partnerApplication = application1
    db_session.commit()
    db_session.expire_all()
    db_session.delete(application1)
    db_session.commit()
    dbapplication = db_session.query(Application).first()
    assert dbapplication == application2
    assert dbapplication.partnerApplication is None
def test_application_connect_to_season(db_session):
    season = createBasicSeason(db_session)
    user = User(username="******",
                sub="sub",
                email="email",
                fullname="schnep scmep")
    db_session.add(user)
    application = Application(needs="",
                              comments="",
                              user=user,
                              partnerUsername="",
                              preferredRoom="d1",
                              seatRollover=True,
                              rank=Rank.WRITING_MASTER,
                              status=ApplicationStatus.SUBMITTED,
                              applicationSeason=season)
    db_session.add(season)
    db_session.add(application)
    db_session.commit()
    dbseason = db_session.query(ApplicationSeason).first()
    assert application.applicationSeason == season
    assert dbseason.applications == [application]
def test_users_connect_each_other(db_session):
    season = createBasicSeason(db_session)
    testuser1 = User(username="******",
                     sub="sub",
                     email="email",
                     fullname="Asbjørn ELEVG baby")
    testuser2 = User(username="******",
                     sub="subs",
                     email="emails",
                     fullname="Asbjørns ELEVGs babys")
    db_session.add(testuser1)
    db_session.add(testuser2)
    application2 = Application(needs="",
                               comments="",
                               user=testuser2,
                               partnerUsername=testuser1.username,
                               preferredRoom="d1",
                               seatRollover=True,
                               rank=Rank.WRITING_MASTER,
                               status=ApplicationStatus.SUBMITTED,
                               applicationSeason=season)
    application1 = Application(needs="",
                               comments="",
                               user=testuser1,
                               partnerUsername=testuser2.username,
                               preferredRoom="d1",
                               seatRollover=True,
                               rank=Rank.WRITING_MASTER,
                               status=ApplicationStatus.SUBMITTED,
                               applicationSeason=season)
    application1.partnerApplication = application2
    application2.partnerApplication = application1
    db_session.add(application1)
    db_session.add(application2)
    db_session.commit()
    dbapp1 = db_session.query(Application).filter_by(user=testuser1).one()
    dbapp2 = db_session.query(Application).filter_by(user=testuser2).one()
    assert dbapp1.partnerApplication == application2
    assert dbapp2.partnerApplication == application1
def test_cascading_user(db_session):
    season = createBasicSeason(db_session)
    user = User(username="******", sub="sub", email="email", fullname="Dudeman")
    application = Application(needs="needs",
                              user=user,
                              partnerUsername="******",
                              comments="comments",
                              preferredRoom="pref",
                              seatRollover=True,
                              rank=Rank.WRITING_MASTER,
                              status=ApplicationStatus.SUBMITTED,
                              applicationSeason=season)

    db_session.add(user)
    db_session.add(application)
    db_session.commit()
    db_session.expire_all()
    db_session.delete(application)
    db_session.commit()
    dbuser = db_session.query(User).first()
    assert dbuser == user
    assert user.application is None
Example #16
0
 def test_waiting_list(self):
     season = createBasicSeason(db.session)
     headers = {
         'Authorization': self.token,
         'AccessToken': self.accessToken,
         'Content-type': 'application/json'
     }
     testuser1 = User(username="******",
                      sub="sub",
                      email="email",
                      fullname="Franky Frank")
     testuser2 = User(username="******",
                      sub="uuid",
                      email="email",
                      fullname="Schmemail")
     testuser3 = User(username="******",
                      sub="ubuid",
                      email="email",
                      fullname="bruh")
     db.session.add(testuser1)
     db.session.add(testuser2)
     db.session.add(testuser3)
     db.session.commit()
     createUser(db.session)
     testApplication1 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than solo",
                                    user=testuser1,
                                    partnerUsername="******",
                                    preferredRoom="d1",
                                    seatRollover=True,
                                    applicationSeason=season,
                                    comments="Not Pepsi, but Pepsi Max")
     testApplication2 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than solo",
                                    user=testuser2,
                                    partnerUsername="******",
                                    preferredRoom="d1",
                                    seatRollover=True,
                                    applicationSeason=season,
                                    comments="Not Pepsi, but Pepsi Max")
     testApplication3 = Application(ApplicationStatus.SUBMITTED,
                                    "Fanta is better than Cola",
                                    user=testuser3,
                                    partnerUsername="",
                                    preferredRoom="d2",
                                    seatRollover=False,
                                    applicationSeason=season,
                                    comments="Not Cola, but Fanta Free")
     db.session.add(testApplication1)
     db.session.add(testApplication2)
     db.session.add(testApplication3)
     db.session.commit()
     # Dump to create new objects which are not changed by the post
     app1 = json.dumps(testApplication1.to_json())
     app2 = json.dumps(testApplication2.to_json())
     jsondata = json.dumps(dict(ids=[1, 2]))
     approvedApplications = self.app.test_client().post(
         'http://localhost:5000/application/waitingList',
         headers=headers,
         data=jsondata,
     )
     app1 = json.loads(app1)
     app2 = json.loads(app2)
     app1["status"] = "WAITING_LIST"
     app2["status"] = "WAITING_LIST"
     assert approvedApplications.status == "200 OK"
     assert json.loads(approvedApplications.data) == json.loads(
         jsonify([app1, app2]).data)
Example #17
0
    def test_new_application_with_existing_partner(self):
        season = createBasicSeason(db.session)
        testuser1 = User(username="******",
                         sub=decodedToken.get("sub"),
                         email="email",
                         fullname="Franky Frank")
        testuser2 = User(username="******",
                         sub="sub",
                         email="emails",
                         fullname="Schmemails")
        testApplication = Application(ApplicationStatus.SUBMITTED,
                                      "Pepsi is better than coke",
                                      user=testuser2,
                                      partnerUsername="******",
                                      preferredRoom="d1",
                                      seatRollover=True,
                                      applicationSeason=season,
                                      comments="Not Pepsi, but Pepsi Max")
        db.session.add(testuser1)
        db.session.commit()
        db.session.add(testuser2)
        db.session.add(testApplication)
        db.session.commit()
        mimetype = 'application/json'
        headers = {
            'Content-Type': mimetype,
            'Accept': mimetype,
            'Authorization': self.token,
            'AccessToken': self.accessToken
        }
        user1Response = self.app.test_client().post(
            'http://localhost:5000/application/',
            headers=headers,
            data=json.dumps(
                dict(
                    username=testuser1.username,
                    needs="Fanta is better than solo",
                    comments="Bruh wtf",
                    partnerUsername=testuser2.username,
                    preferredRoom="d1",
                    seatRollover=True,
                )))
        user1expectedResponse = make_response(
            jsonify(
                needs="Fanta is better than solo",
                comments="Bruh wtf",
                id=2,
                status="SUBMITTED",
                user={
                    "id": testuser1.id,
                    "username": testuser1.username,
                    "email": testuser1.email,
                    "fullname": testuser1.fullname
                },
                preferredRoom="d1",
                rank="WRITING_MASTER",
                seatRollover=True,
                partnerApplication={
                    "needs": "Pepsi is better than coke",
                    "comments": "Not Pepsi, but Pepsi Max",
                    "id": 1,
                    "status": "SUBMITTED",
                    "rank": "OTHER",
                    "user": {
                        "id": testuser2.id,
                        "username": testuser2.username,
                        "email": testuser2.email,
                        "fullname": testuser2.fullname
                    },
                    "preferredRoom": "d1",
                    "seatRollover": True,
                },
            ), 201)

        expectedConnectedApplication = jsonify(
            needs="Pepsi is better than coke",
            comments="Not Pepsi, but Pepsi Max",
            id=1,
            status="SUBMITTED",
            user={
                "id": testuser2.id,
                "username": testuser2.username,
                "email": testuser2.email,
                "fullname": testuser2.fullname
            },
            preferredRoom="d1",
            seatRollover=True,
            seat=None,
            rank="OTHER",
            partnerApplication={
                "needs": "Fanta is better than solo",
                "comments": "Bruh wtf",
                "id": 2,
                "status": "SUBMITTED",
                "preferredRoom": "d1",
                "seatRollover": True,
                "rank": "WRITING_MASTER",
                "seat": None,
                "user": {
                    "id": testuser1.id,
                    "username": testuser1.username,
                    "email": testuser1.email,
                    "fullname": testuser1.fullname
                },
            },
        )
        getApplication = self.app.test_client().get(
            'http://localhost:5000/application/byUser/1', headers=headers)
        assert user1expectedResponse.status == user1Response.status
        assert json.loads(user1expectedResponse.data) == json.loads(
            user1Response.data)
        assert getApplication.status == "200 OK"
        assert json.loads(expectedConnectedApplication.data) == json.loads(
            getApplication.data)