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
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_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