Exemplo n.º 1
0
 def test_home_page_displays_only_todos_added(self):
     ToDo.objects.create(item='Code unit test', added_by=ADMIN_ID, date_todo=TODAY, archive='0')
     ToDo.objects.create(item='Fix code', added_by=OTHER_ID, date_todo=TODAY, archive='0')
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = home_page(request)
     self.assertIn('Code unit test', response.content.decode())
     self.assertNotIn('Fix code', response.content.decode())
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = OTHER_ID
     request.session['is_superuser'] = OTHER_IS_SUPERUSER
     request.session['first_name'] = OTHER_FIRST_NAME
     request.session['last_name'] = OTHER_LAST_NAME
     response = home_page(request)
     self.assertNotIn('Code unit test', response.content.decode())
     self.assertIn('Fix code', response.content.decode())
Exemplo n.º 2
0
 def test_home_page_transfer_pending_todos_to_current_day(self):
     one_day = datetime.timedelta(days=1)
     yesterday = TODAY - one_day
     tomorrow = TODAY + one_day
     
     #Done
     ToDo.objects.create(item='Code unit test 1', added_by='1', date_todo=yesterday, archive='1')
     #Cancelled
     ToDo.objects.create(item='Code unit test 2', added_by='1', date_todo=yesterday, archive='2')
     #Pending
     ToDo.objects.create(item='Fix code', added_by='1', date_todo=yesterday, archive='0')
     
     #Current
     ToDo.objects.create(item='Rerun the unit test', added_by='1', date_todo=TODAY, archive='0')
     
     #Future
     ToDo.objects.create(item='Refactor', added_by='1', date_todo=tomorrow, archive='0')
     
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = backoperations(request)
     response = home_page(request)
     self.assertNotIn('Code unit test 1', response.content.decode())
     self.assertNotIn('Code unit test 2', response.content.decode())
     self.assertIn('Fix code', response.content.decode())
     self.assertIn('Rerun the unit test', response.content.decode())
     self.assertNotIn('Refactor', response.content.decode())
     self.assertEqual(ToDo.objects.filter(date_todo=TODAY).count(), 2);
Exemplo n.º 3
0
 def test_logout_if_session_variables_are_unset(self):
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['username'] = ADMIN_USERNAME
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = logout(request)
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     response = home_page(request)
     
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = addtodo(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     random_id = 1000
     
     response = tick_done(request, random_id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = tick_cancel(request, random_id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = view_users(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = add_user(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = delete_user(request, random_id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = backoperations(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = view_weekly(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
     
     response = view_monthly(request)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response['location'], '/accounts/unauthorized')
Exemplo n.º 4
0
 def test_home_page_displays_prompt_on_empty_todolist(self):
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = home_page(request)
     self.assertIn('To do list is empty', response.content.decode())
Exemplo n.º 5
0
 def test_home_page_displays_view_monthly_todo_list_link(self):
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = OTHER_ID
     request.session['is_superuser'] = OTHER_IS_SUPERUSER
     request.session['first_name'] = OTHER_FIRST_NAME
     request.session['last_name'] = OTHER_LAST_NAME
     response = home_page(request)
     self.assertIn("View monthly", response.content.decode())
Exemplo n.º 6
0
 def test_view_user_link_visible_to_administrator(self):
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = home_page(request)
     self.assertIn("View Users", response.content.decode())
Exemplo n.º 7
0
 def test_home_page_display_current_date(self):
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = home_page(request)
     import time
     current_date = time.strftime('%Y-%m-%d')
     self.assertIn(current_date, response.content.decode())
Exemplo n.º 8
0
 def test_home_page_check_for_cancel_and_done_labels(self):
     ToDo.objects.create(item='Code unit test 1', added_by='1', date_todo=TODAY, archive='2')
     ToDo.objects.create(item='Code unit test 2', added_by='1', date_todo=TODAY, archive='1')
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     session_key = None
     request.session = engine.SessionStore(session_key)
     request.session['id'] = ADMIN_ID
     request.session['is_superuser'] = ADMIN_IS_SUPERUSER
     request.session['first_name'] = ADMIN_FIRST_NAME
     request.session['last_name'] = ADMIN_LAST_NAME
     response = home_page(request)
     self.assertIn('Cancelled', response.content.decode())
     self.assertIn('Done', response.content.decode())
Exemplo n.º 9
0
 def test_home_page_returns_correct_html(self):
     request = HttpRequest()
     response = home_page(request)
     self.assertTrue(response.content.startswith(b"<html>"))
     self.assertIn(b"<title>Welcome to Django. This is my cool Site!</title>", response.content)  # 4
     self.assertTrue(response.content.endswith(b"</html>"))
Exemplo n.º 10
0
 def test_home_page_returns_correct_html(self):
     request = HttpRequest()
     response = home_page(request)
     expected_html = render_to_string("home.html")
     self.assertEqual(response.content.decode(), expected_html)