Exemplo n.º 1
0
 def test_new_application_season(self):
     createUser(db.session)
     mimetype = 'application/json'
     headers = {
         'Content-Type': mimetype,
         'Accept': mimetype,
         'Authorization': self.token,
         'AccessToken': self.accessToken
     }
     starttime = datetime.now() + timedelta(days=+5)
     endtime = starttime + timedelta(days=+150)
     acceptstart = starttime
     acceptend = starttime + timedelta(days=+7)
     response = self.app.test_client().post(
         '/season/',
         headers=headers,
         data=json.dumps(dict(newPeriodEnd=self.formatDate(acceptend),
                              newPeriodStart=self.formatDate(acceptstart),
                              newRoomEnd=self.formatDate(endtime),
                              newRoomStart=self.formatDate(starttime)),
                         default=str))
     assert "201 CREATED" == response.status
     assert jsonify(applicationPeriodEnd=str(acceptend),
                    applicationPeriodStart=str(acceptstart),
                    end=str(endtime),
                    start=str(starttime),
                    id="1").data == response.data
Exemplo n.º 2
0
 def test_create_rooms_and_get_all(self):
     createUser(db.session)
     room1 = createRoom()
     room2 = createRoom()
     roomList = [room1, room2]
     jsonList = list(map(lambda x: x.to_json(), roomList))
     response = self.app.test_client().get(f"http://localhost:5000/room/")
     assert response.status == "200 OK"
     assert response.data == jsonify(jsonList).data
     assert db.session.query(Room).all() == roomList
Exemplo n.º 3
0
 def test_delete_seat(self):
     createUser(db.session)
     headers = {
         'AccessToken': self.accessToken,
         'Authorization': self.token
     }
     room, seat = createSeatAndRoom()
     response = self.app.test_client().delete(
         f"http://localhost:5000/seat/{seat.id}", headers=headers)
     assert response.status == "200 OK"
     assert db.session.query(Seat).first() is None
Exemplo n.º 4
0
 def test_get_seat(self):
     createUser(db.session)
     room, seat = createSeatAndRoom()
     headers = {
         'AccessToken': self.accessToken,
         'Authorization': self.token
     }
     response = self.app.test_client().get(
         f"http://localhost:5000/seat/{seat.id}", headers=headers)
     assert response.data == jsonify(seat.to_json()).data
     assert db.session.query(Seat).first() == seat
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()
Exemplo n.º 6
0
 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
Exemplo n.º 7
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
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
    def test_rename_seat(self):
        room, seat = createSeatAndRoom()
        createUser(db.session)
        oldName = seat.seat_name
        newName = "New Name"
        seatId = seat.id

        mimetype = 'application/json'
        headers = {
            'Content-Type': mimetype,
            'Accept': mimetype,
            'AccessToken': self.accessToken,
        }
        response = self.app.test_client().put("http://localhost:5000/seat/" +
                                              str(seatId),
                                              headers=headers,
                                              data=json.dumps(newName))
        assert "200 OK" == response.status
        assert jsonify(seat.to_json()).data == response.data
        assert seat.seat_name == newName
        assert seat.seat_name != oldName
Exemplo n.º 10
0
 def test_updateRoom_success(self):
     createUser(db.session)
     room = createRoom()
     mimetype = 'application/json'
     headers = {
         'Content-Type': mimetype,
         'Accept': mimetype,
         'Authorization': self.token,
         'Accesstoken': self.accessToken
     }
     response = self.app.test_client().put('http://localhost:5000/room/1',
                                           headers=headers,
                                           data=json.dumps(
                                               dict(
                                                   name='X-wing',
                                                   info='nice ship dude',
                                               )))
     assert "200 OK" == response.status
     dbroom = db.session.query(Room).first()
     assert dbroom.name == 'X-wing'
     assert room.info == 'nice ship dude'
Exemplo n.º 11
0
    def test_create_seat(self):
        createUser(db.session)
        room, seat = createSeatAndRoom()
        mimetype = 'application/json'
        headers = {
            'Content-Type': mimetype,
            'Accept': mimetype,
            'AccessToken': self.accessToken,
        }
        data = dict(name='D2', roomId=room.id, info='nice ship dude')
        response = self.app.test_client().post("http://localhost:5000/seat/",
                                               headers=headers,
                                               data=json.dumps(data))

        assert "201 CREATED" == response.status
        assert make_response(
            jsonify(id=2,
                    name="D2",
                    roomId=room.id,
                    info='nice ship dude',
                    user=None)).data == response.data
        assert db.session.query(
            Seat).all()[1].to_json()["info"] == data["info"]
Exemplo n.º 12
0
 def test_create_room(self):
     createUser(db.session)
     mimetype = 'application/json'
     headers = {
         'Content-Type': mimetype,
         'Accept': mimetype,
         'Authorization': self.token,
         'Accesstoken': self.accessToken
     }
     data = dict(
         name='X-wing',
         info='nice ship dude',
         seats=dict(
             count=0,
             seats=[],
         ),
     )
     response = self.app.test_client().post("http://localhost:5000/room/",
                                            headers=headers,
                                            data=json.dumps(data))
     assert "201 CREATED" == response.status
     data["id"] = 1
     assert db.session.query(Room).first().to_json() == data
Exemplo n.º 13
0
 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)
Exemplo n.º 14
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)