From 53c42db214a1fc4202683d32ccabfb916e3a5c58 Mon Sep 17 00:00:00 2001
From: Marco Ciotola <848222@stud.unive.it>
Date: Tue, 5 Mar 2019 13:44:07 +0100
Subject: [PATCH] [tests] Add admin user fixture and test accessibility of
 stats

---
 helios/fixtures/users.json | 41 +++++++++++++++++++++++++++++++++++++-
 helios/tests.py            | 20 +++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/helios/fixtures/users.json b/helios/fixtures/users.json
index c588ce4..c6e18b5 100644
--- a/helios/fixtures/users.json
+++ b/helios/fixtures/users.json
@@ -1 +1,40 @@
-[{"pk": 1, "model": "helios_auth.user", "fields": {"info": "{}", "user_id": "ben@adida.net", "name": "Ben Adida", "user_type": "google", "token": null, "admin_p": false}},{"pk": 2, "model": "helios_auth.user", "fields": {"info": "{}", "user_id": "12345", "name": "Ben Adida", "user_type": "facebook", "token": {"access_token":"1234"}, "admin_p": false}}]
\ No newline at end of file
+[
+  {
+    "pk": 1,
+    "model": "helios_auth.user",
+    "fields": {
+      "info": "{}",
+      "user_id": "ben@adida.net",
+      "name": "Ben Adida",
+      "user_type": "google",
+      "token": null,
+      "admin_p": false
+    }
+  },
+  {
+    "pk": 2,
+    "model": "helios_auth.user",
+    "fields": {
+      "info": "{}",
+      "user_id": "12345",
+      "name": "Ben Adida",
+      "user_type": "facebook",
+      "token": {
+        "access_token": "1234"
+      },
+      "admin_p": false
+    }
+  },
+  {
+    "pk": 3,
+    "model": "helios_auth.user",
+    "fields": {
+      "info": "{}",
+      "user_id": "mccio@github.com",
+      "name": "Marco Ciotola",
+      "user_type": "google",
+      "token": null,
+      "admin_p": true
+    }
+  }
+]
\ No newline at end of file
diff --git a/helios/tests.py b/helios/tests.py
index a002413..157ce28 100644
--- a/helios/tests.py
+++ b/helios/tests.py
@@ -491,6 +491,26 @@ class ElectionBlackboxTests(WebTest):
         new_election = models.Election.objects.get(uuid = self.election.uuid)
         self.assertEquals(new_election.short_name, self.election.short_name + "-2")
 
+    def test_get_election_stats(self):
+        self.setup_login(from_scratch=True, user_id='mccio@github.com', user_type='google')
+        response = self.client.get("/helios/stats/", follow=False)
+        self.assertStatusCode(response, 200)
+        response = self.client.get("/helios/stats/force-queue", follow=False)
+        self.assertRedirects(response, "/helios/stats/")
+        response = self.client.get("/helios/stats/elections", follow=False)
+        self.assertStatusCode(response, 200)
+        response = self.client.get("/helios/stats/problem-elections", follow=False)
+        self.assertStatusCode(response, 200)
+        response = self.client.get("/helios/stats/recent-votes", follow=False)
+        self.assertStatusCode(response, 200)
+        self.clear_login()
+        response = self.client.get("/helios/stats/", follow=False)
+        self.assertStatusCode(response, 403)
+        self.setup_login()
+        response = self.client.get("/helios/stats/", follow=False)
+        self.assertStatusCode(response, 403)
+        self.clear_login()
+
     def _setup_complete_election(self, election_params=None):
         "do the setup part of a whole election"
 
-- 
GitLab