From 7c7283f49a5246289295f40fe177b81d86650500 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Sun, 6 Jan 2019 21:45:57 +0100
Subject: [PATCH] Added AutoLogout test

---
 frontend/src/components/AutoLogout.vue   |  4 +-
 frontend/src/components/mixins/mixins.ts |  1 -
 functional_tests/test_auto_logout.py     | 67 ++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 3 deletions(-)
 create mode 100644 functional_tests/test_auto_logout.py

diff --git a/frontend/src/components/AutoLogout.vue b/frontend/src/components/AutoLogout.vue
index 7572dd86..ae037ddf 100644
--- a/frontend/src/components/AutoLogout.vue
+++ b/frontend/src/components/AutoLogout.vue
@@ -4,7 +4,7 @@
     max-width="30%"
     v-model="logoutDialog"
   >
-    <v-card>
+    <v-card id="logout-dialog">
       <v-card-title class="headline">
         You'll be logged out!
       </v-card-title>
@@ -82,7 +82,7 @@ export default {
           this.logoutDialog = true
         }
       }
-    }, 5 * 1e3)
+    }, 1 * 1e3)
   },
   beforeDestroy () {
     clearInterval(this.timer)
diff --git a/frontend/src/components/mixins/mixins.ts b/frontend/src/components/mixins/mixins.ts
index 4b93f298..974e18df 100644
--- a/frontend/src/components/mixins/mixins.ts
+++ b/frontend/src/components/mixins/mixins.ts
@@ -11,7 +11,6 @@ export enum ExportType {
 @Component
 export class parseCSVMapMixin extends Vue {
   parseCSVMap (csvMap: string) {
-    console.log('parsing')
     let lines = csvMap.split('\n')
     lines.shift() // drop the first line since it contains only headings
     // TODO remove any type
diff --git a/functional_tests/test_auto_logout.py b/functional_tests/test_auto_logout.py
new file mode 100644
index 00000000..ecdfa41f
--- /dev/null
+++ b/functional_tests/test_auto_logout.py
@@ -0,0 +1,67 @@
+import datetime
+import time
+import logging
+from django.test import LiveServerTestCase
+from selenium import webdriver
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.support import expected_conditions as ec
+
+from core.models import UserAccount
+from functional_tests.util import (login, create_browser)
+from util import factory_boys as fact
+
+log = logging.getLogger(__name__)
+
+
+class TestAutoLogout(LiveServerTestCase):
+    browser: webdriver.Firefox = None
+    username = None
+    password = None
+    role = None
+
+    @classmethod
+    def setUpClass(cls):
+        super().setUpClass()
+        cls.browser = create_browser()
+
+    @classmethod
+    def tearDownClass(cls):
+        super().tearDownClass()
+        cls.browser.quit()
+
+    def setUp(self):
+        self.username = 'reviewer'
+        self.password = 'p'
+        self.role = UserAccount.TUTOR
+        fact.UserAccountFactory(
+            username=self.username,
+            password=self.password,
+            role=self.role
+        )
+
+    def _login(self):
+        login(self.browser, self.live_server_url, self.username, self.password)
+
+    def test_auto_logout_can_continue(self):
+        with self.settings(JWT_AUTH={
+            'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=5),
+            'JWT_ALLOW_REFRESH': True,
+        }
+        ):
+            self._login()
+            initial_token = self.browser.execute_script(
+                'return sessionStorage["token"]'
+            )
+            logout_dialog = self.browser.find_element_by_id('logout-dialog')
+            WebDriverWait(self.browser, 5).until(
+                ec.visibility_of_element_located((By.ID, 'logout-dialog')))
+            logout_dialog.find_element_by_id('continue-btn').click()
+            # explicit sleep is unfortunately necessary here, since we need to wait
+            # for the initial token to expire and the site to be the same
+            time.sleep(2)
+            self.assertNotIn('login', self.browser.current_url)
+            new_token = self.browser.execute_script(
+                'return sessionStorage["token"]'
+            )
+            self.assertNotEqual(initial_token, new_token)
-- 
GitLab