Пример #1
0
def test_start_docs_status_upgrade(sample_worker, sample_start_doc):
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")

        doc_id = sample_start_doc.id
        data = {doc_id: {
            "delivered": True,
            "sent": True,
            "sent-date": "2019-07-25",
            "notes": "sample note"
        }}

        assert sample_start_doc.delivered is False
        assert sample_start_doc.sent_to_hr is False
        assert sample_start_doc.sent_date is None
        assert sample_start_doc.sent_date is None

        resp = client.post("/start-docs-status-upgrade",
                           data=json.dumps(data),
                           content_type="application/json")
        assert resp.status_code == 200

        assert sample_start_doc.delivered is data[doc_id]["delivered"]
        assert sample_start_doc.sent_to_hr is data[doc_id]["sent"]
        assert sample_start_doc.sent_date == datetime.strptime(data[doc_id]["sent-date"], "%Y-%m-%d").date()
        assert sample_start_doc.notes == data[doc_id]["notes"]
Пример #2
0
def test_index():
    client = app.test_client()
    with client:

        # redirect to login if user not logged in
        resp = client.get("/index")
        assert resp.status_code == 302
        resp = client.get("/index", follow_redirects=True)
        assert resp.status_code == 200
        assert "HR - logowanie" in resp.get_data(as_text=True)

        # logs user in and checks if main page is loaded
        resp = login(client=client, username="******", password="******")
        data = resp.get_data(as_text=True)
        assert resp.status_code == 200
        assert "HR - strona główna" in data

        # checks main page content
        for card in main_page_cards:
            assert card in data
            for section in main_page_cards[card]:
                assert section in data

        # checks navbar content
        assert "GŁÓWNA" in data
        assert "WYLOGUJ Test" in data
Пример #3
0
def test_logout(sample_user):
    client = app.test_client()
    with client:

        # checks if logging out mechanism works
        login(client=client, username="******", password="******")
        resp = logout(client)
        data = resp.get_data(as_text=True)
        assert "HR - logowanie" in data
Пример #4
0
def test_login_wrong_username_and_password(sample_user):
    client = app.test_client()
    with client:

        # checks login with wrong password and username
        resp = login(client=client, username="******", password="******")
        data = resp.get_data(as_text=True)
        assert "HR - logowanie" in data
        assert "Nieprawidłowa nazwa użytkownika lub hasło" in data
Пример #5
0
def test_login_mechanism(sample_user):
    client = app.test_client()
    with client:

        # checks login with proper data
        resp = login(client=client, username="******", password="******")
        data = resp.get_data(as_text=True)
        assert resp.status_code == 200
        assert "HR - strona główna" in data
Пример #6
0
def test_login_page():
    client = app.test_client()
    with client:

        # checks if login page works
        resp = client.get("/login")
        assert resp.status_code == 200
        data = resp.get_data(as_text=True)
        assert "GŁÓWNA" in data
        assert "ZALOGUJ" in data
Пример #7
0
def test_links():
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")
        resp = client.get("/index")
        data = resp.get_data(as_text=True)
        assert url_for("main.index") in data
        assert url_for("auth.logout") in data
        assert url_for("workers.add_worker") in data
        assert url_for("workers.workers_query") in data
        assert url_for("start_docs.new_start_doc_type") in data
        assert url_for("start_docs.list_start_doc_type") in data
Пример #8
0
def test_worker_start_docs_post(sample_worker, sample_start_doc, sample_start_doc_type):
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")

        assert not sample_start_doc_type.docs
        resp = client.post(url_for("workers.worker_start_docs"),
                           query_string=dict(worker_name=sample_worker.name),
                           data=dict(doc_type=[sample_start_doc_type.name]),
                           follow_redirects=True)
        data = resp.get_data(as_text=True)
        assert sample_start_doc_type.docs
        assert len(sample_start_doc_type.docs) == 1
        doc = sample_start_doc_type.docs[0]
        assert "{}-delivered".format(doc.id) in data
Пример #9
0
def test_worker_start_docs_connection_and_get(sample_worker, sample_start_doc, sample_start_doc_type):
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")

        sample_worker.assign_start_doc(sample_start_doc)
        sample_start_doc_type.assign_document(sample_start_doc)

        resp = client.get(url_for("workers.worker_start_docs"), query_string=dict(worker_name=sample_worker.name))
        data = resp.get_data(as_text=True)

        # checking page connection
        assert resp.status_code == 200
        assert "HR - dokumenty główne: {}".format(sample_worker.name) in data
        assert str(sample_start_doc.id) in data
        assert sample_start_doc_type.name in data
Пример #10
0
def test_create_start_docs(sample_user, sample_worker, sample_start_doc_type):
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")

        resp = client.post("/{}/create-start-docs".format(sample_worker.name),
                           data=json.dumps([sample_start_doc_type.name]),
                           content_type="application/json")

        # checking page connection
        assert resp.status_code == 200

        # checking route functionality
        start_doc = StartDoc.query.filter_by(start_doc_type=sample_start_doc_type.id).first()
        assert start_doc in StartDoc.query.all()
        assert start_doc in sample_worker.start_docs
Пример #11
0
def test_start_docs_required(sample_user, sample_worker, sample_start_doc_type):
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")

        # checking page connection
        resp = client.get("/{}/start-docs-required".format(sample_worker.id))
        assert resp.status_code == 200
        assert "HR - wybór dokumentów do zatrudnienia" in resp.get_data(as_text=True)
        assert "Wybierz dokumenty, które musi dostarczyć" in resp.get_data(as_text=True)

        # checks if list of start document types is displayed
        types = [doc_type.name for doc_type in StartDocType.query.all()]
        assert types
        for doctype in types:
            assert doctype in resp.get_data(as_text=True)
Пример #12
0
def test_add_worker(sample_function, sample_workplace):
    client = app.test_client()
    with client:
        login(client=client, username="******", password="******")

        # checking page connection
        resp = client.get("/add-worker", follow_redirects=True)
        assert resp.status_code == 200
        assert "HR - nowy pracownik" in resp.get_data(as_text=True)
        assert "Nowy pracownik" in resp.get_data(as_text=True)

        # checking adding new worker
        assert not Worker.query.filter_by(name="test_new_worker").first()
        resp = client.post("/add-worker", data=dict(name="test_new_worker",
                                                    password="******",
                                                    contract_begin="01.01.2019",
                                                    contract_end="22.01.2018",
                                                    workplace=sample_workplace.name,
                                                    function=sample_function.name),
                           follow_redirects=True)
        worker = Worker.query.filter_by(name="test_new_worker").first()
        assert worker in Worker.query.all()
        assert "Wybierz dokumenty, które musi dostarczyć" in resp.get_data(as_text=True)