@@ -15,64 +15,115 @@ def remove_themerr_db_cache_file():
1515 _backup_file_name = "{}.bak" .format (webapp .database_cache_file )
1616
1717 # rename the file, so it is not found
18- os .rename (webapp .database_cache_file , _backup_file_name )
18+ if os .path .exists (webapp .database_cache_file ):
19+ os .rename (webapp .database_cache_file , _backup_file_name )
1920 yield
2021
2122 # rename the file back
22- os .rename (_backup_file_name , webapp .database_cache_file )
23+ if os .path .exists (_backup_file_name ):
24+ os .rename (_backup_file_name , webapp .database_cache_file )
2325
2426
25- def test_home ( test_client ):
27+ def test_home_login_disabled ( test_client_login_disabled ):
2628 """
2729 WHEN the '/' page is requested (GET)
2830 THEN check that the response is valid
2931
3032 Repeat for '/home'
3133 """
3234 try :
33- response = test_client .get ('/' )
35+ response = test_client_login_disabled .get ('/' )
3436 except AttributeError :
3537 pytest .skip ("cannot access Plex token/server" )
3638 else :
3739 assert response .status_code == 200
3840
39- response = test_client .get ('/home' )
41+ response = test_client_login_disabled .get ('/home' )
4042 assert response .status_code == 200
4143
4244 assert 'id="section_' in response .data .decode ('utf-8' )
4345
4446
45- def test_home_without_cache ( remove_themerr_db_cache_file , test_client ):
47+ def test_home ( test_client ):
4648 """
4749 WHEN the '/' page is requested (GET)
48- THEN check that the response is valid
50+ THEN check that the response is a redirect
51+
52+ Repeat for '/home'
4953 """
5054 try :
5155 response = test_client .get ('/' )
5256 except AttributeError :
5357 pytest .skip ("cannot access Plex token/server" )
58+ else :
59+ assert response .status_code == 302
60+
61+ response = test_client .get ('/home' )
62+ assert response .status_code == 302
63+
64+
65+ def test_home_without_cache_login_disabled (remove_themerr_db_cache_file , test_client_login_disabled ):
66+ """
67+ WHEN the '/' page is requested (GET)
68+ THEN check that the response is valid
69+ """
70+ try :
71+ response = test_client_login_disabled .get ('/' )
72+ except AttributeError :
73+ pytest .skip ("cannot access Plex token/server" )
5474 else :
5575 assert response .status_code == 200
5676
5777 assert 'Database is being cached' in response .data .decode ('utf-8' )
5878
5979
60- def test_image (test_client ):
80+ def test_home_without_cache (remove_themerr_db_cache_file , test_client ):
81+ """
82+ WHEN the '/' page is requested (GET)
83+ THEN check that the response is a redirect
84+ """
85+ try :
86+ response = test_client .get ('/' )
87+ except AttributeError :
88+ pytest .skip ("cannot access Plex token/server" )
89+ else :
90+ assert response .status_code == 302
91+
92+
93+ def test_image_login_disabled (test_client_login_disabled ):
6194 """
6295 WHEN the '/favicon.ico' file is requested (GET)
6396 THEN check that the response is valid
6497 THEN check the content type is 'image/vnd.microsoft.icon'
6598 """
66- response = test_client .get ('favicon.ico' )
99+ response = test_client_login_disabled .get ('favicon.ico' )
67100 assert response .status_code == 200
68101 assert response .content_type == 'image/vnd.microsoft.icon'
69102
70103
71- def test_status (test_client ):
104+ def test_image (test_client ):
105+ """
106+ WHEN the '/favicon.ico' file is requested (GET)
107+ THEN check that the response is a redirect
108+ """
109+ response = test_client .get ('favicon.ico' )
110+ assert response .status_code == 302
111+
112+
113+ def test_status_no_login (test_client_login_disabled ):
72114 """
73115 WHEN the '/status' page is requested (GET)
74116 THEN check that the response is valid
75117 """
76- response = test_client .get ('/status' )
118+ response = test_client_login_disabled .get ('/status' )
77119 assert response .status_code == 200
78120 assert response .content_type == 'application/json'
121+
122+
123+ def test_status (test_client ):
124+ """
125+ WHEN the '/status' page is requested (GET)
126+ THEN check that the response is a redirect
127+ """
128+ response = test_client .get ('/status' )
129+ assert response .status_code == 302
0 commit comments