from tests.scoring_engine.web.web_test import WebTest


class TestAdmin(WebTest):
    def setup(self):
        super(TestAdmin, self).setup()
        self.create_default_user()
        self.create_default_settings()

    def test_auth_required_admin(self):
        self.verify_auth_required('/admin')
        stats_resp = self.auth_and_get_path('/admin')
        assert stats_resp.status_code == 200

    def test_auth_required_admin_status(self):
        self.verify_auth_required('/admin/status')
        stats_resp = self.auth_and_get_path('/admin/status')
        assert stats_resp.status_code == 200

    def test_auth_required_admin_manage(self):
        self.verify_auth_required('/admin/manage')
        stats_resp = self.auth_and_get_path('/admin/manage')
        assert stats_resp.status_code == 200

    def test_auth_required_admin_settings(self):
        self.verify_auth_required('/admin/settings')
        stats_resp = self.auth_and_get_path('/admin/settings')
        assert stats_resp.status_code == 200

@@ -47,16 +47,104 @@
 WebTest%0A
+from scoring_engine.models.team import Team%0Afrom scoring_engine.models.user import User%0A
 %0A%0Aclass 
@@ -298,16 +298,479 @@
 ings()%0A%0A
+    def unauthorized_admin_test(self, path):%0A        red_team = Team(name=%22Red Team%22, color=%22Red%22)%0A        self.session.add(red_team)%0A        user = User(username=%22testuser_red%22, password=%22testpass_red%22, team=red_team)%0A        self.session.add(user)%0A        self.session.commit()%0A        self.client.login('testuser_red', 'testpass_red')%0A        resp = self.client.get(path)%0A        assert resp.status_code == 302%0A        assert 'unauthorized' in str(resp.data)%0A%0A
     def 
@@ -1142,32 +1142,128 @@
 us_code == 200%0A%0A
+    def test_auth_bad_auth_status(self):%0A        self.unauthorized_admin_test('/admin/status')%0A%0A
     def test_aut
@@ -1443,32 +1443,128 @@
 us_code == 200%0A%0A
+    def test_auth_bad_auth_manage(self):%0A        self.unauthorized_admin_test('/admin/manage')%0A%0A
     def test_aut
@@ -1704,32 +1704,32 @@
 dmin/settings')%0A
-
         assert s
@@ -1737,28 +1737,967 @@
 ats_resp.status_code == 200%0A
+%0A    def test_auth_bad_auth_settings(self):%0A        self.unauthorized_admin_test('/admin/settings')%0A%0A    def test_auth_required_admin_progress(self):%0A        self.verify_auth_required('/admin/progress')%0A        stats_resp = self.auth_and_get_path('/admin/progress')%0A        assert stats_resp.status_code == 200%0A%0A    def test_auth_bad_auth_progress(self):%0A        self.unauthorized_admin_test('/admin/progress')%0A%0A    def test_auth_required_admin_team(self):%0A        self.verify_auth_required('/admin/team/1')%0A        stats_resp = self.auth_and_get_path('/admin/team/1')%0A        assert stats_resp.status_code == 200%0A%0A    def test_admin_bad_team(self):%0A        self.verify_auth_required('/admin/team/20')%0A        resp = self.auth_and_get_path('/admin/team/20')%0A        assert resp.status_code == 302%0A        assert 'unauthorized' in str(resp.data)%0A%0A    def test_auth_bad_auth_team(self):%0A        self.unauthorized_admin_test('/admin/team/3')%0A

Improve tests for admin view