Esempio n. 1
0
def start(trains_data):
    from train_data_service import TrainDataService
    TrainDataService.data_for_train.exposed = True
    TrainDataService.reserve.exposed = True
    TrainDataService.reset.exposed = True
    cherrypy.config.update({"server.socket_port": 8081})
    cherrypy.quickstart(TrainDataService(trains_data))
def start(trains_data):
    global TRAIN_DATA
    TRAIN_DATA = TrainDataService(trains_data)

    app.config["SERVER_NAME"] = "127.0.0.1:8081"
    app.config["DEBUG"] = True
    app.run()
Esempio n. 3
0
def test_fetch_train_data():
    service = TrainDataService("""{ "foo_train": {"seats": {"1A": {"coach": "A", "seat_number": "1", "booking_reference": ""} }}}""")
    train_data = service.data_for_train("foo_train")
    assert "1A" in train_data
Esempio n. 4
0
def test_reset():
    service = TrainDataService("""{ "foo_train": {"seats": {"1A": {"coach": "A", "seat_number": "1", "booking_reference": "existing"} }}}""")
    train_data = service.reset("foo_train")
    assert 'existing' not in train_data
Esempio n. 5
0
def test_reserve_with_typo_in_seatid():
    service = TrainDataService("""{ "foo_train": {"seats": {"1A": {"coach": "A", "seat_number": "1", "booking_reference": "existing"} }}}""")
    response = service.reserve("foo_train", json.dumps(["typo"]), "01234567")
    assert "seat not found typo" in response
Esempio n. 6
0
def test_reserve_seat_when_already_reserved():
    service = TrainDataService("""{ "foo_train": {"seats": {"1A": {"coach": "A", "seat_number": "1", "booking_reference": "existing"} }}}""")
    response = service.reserve("foo_train", json.dumps(["1A"]), "01234567")
    assert "already booked with reference: existing" in response
    train_data = service.data_for_train("foo_train")
    assert '"booking_reference": "existing"' in train_data
Esempio n. 7
0
def test_reserve_seat():
     service = TrainDataService("""{ "foo_train": {"seats": {"1A": {"coach": "A", "seat_number": "1", "booking_reference": ""} }}}""")
     service.reserve("foo_train", json.dumps(["1A"]), "01234567")
     train_data = service.data_for_train("foo_train")
     assert '"booking_reference": "01234567"' in train_data