From 73145fe7ea8ab4e8a391f1ea374ca09ade76116d Mon Sep 17 00:00:00 2001
From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de>
Date: Sat, 11 Mar 2017 20:15:38 +0100
Subject: [PATCH] Some first protocol unit tests

---
 server.py |  1 -
 tests.py  | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/server.py b/server.py
index 556db2d..c45203f 100755
--- a/server.py
+++ b/server.py
@@ -477,7 +477,6 @@ def show_protocol(protocol):
     document_upload_form = DocumentUploadForm()
     source_upload_form = KnownProtocolSourceUploadForm()
     time_diff = protocol.date - datetime.now().date()
-    print(time_diff)
     large_time_diff = not protocol.is_done() and time_diff.days > 0
     return render_template("protocol-show.html", protocol=protocol, errors_table=errors_table, documents_table=documents_table, document_upload_form=document_upload_form, source_upload_form=source_upload_form, time_diff=time_diff, large_time_diff=large_time_diff)
 
diff --git a/tests.py b/tests.py
index b8602a0..ed7f1b2 100644
--- a/tests.py
+++ b/tests.py
@@ -104,6 +104,20 @@ class FullDBAnonymousTestCase(GeneralTestCase):
                 new_meta_route = "/defaultmeta/new/{}".format(protocoltype.id)
                 assert self.app.get(new_meta_route).status_code == STATUS_REDIRECT
                 assert self.app.post(new_meta_route).status_code == STATUS_REDIRECT
+
+    def test_protocols(self):
+        with proto3.app.app_context():
+            new_route = "/protocol/new"
+            assert self.app.get(new_route).status_code == STATUS_REDIRECT
+            assert self.app.post(new_route).status_code == STATUS_REDIRECT
+            protocols = Protocol.query.all()
+            for protocol in protocols:
+                visible = protocol.protocoltype.has_public_view_right(None, check_networks=False)
+                state_ok_or_redirect = STATUS_OK if visible else STATUS_REDIRECT
+                show_route = "/protocol/show/{}".format(protocol.id)
+                assert self.app.get(show_route).status_code == state_ok_or_redirect
+                assert self.app.post(show_route).status_code == STATUS_METHOD
+                
                 
 
 if __name__ == "__main__":
-- 
GitLab