Skip to content

Commit

Permalink
Tests for Event app (#707)
Browse files Browse the repository at this point in the history
  • Loading branch information
Monal5031 authored and anjali-dhanuka committed Jul 2, 2018
1 parent 3d918ba commit 7c0a0c2
Show file tree
Hide file tree
Showing 11 changed files with 366 additions and 116 deletions.
2 changes: 1 addition & 1 deletion vms/event/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ class Event(models.Model):
)

def __str__(self):
return self.name
return str(self.name)
154 changes: 154 additions & 0 deletions vms/event/tests/test_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# third party
from selenium import webdriver

# Django
from django.contrib.staticfiles.testing import LiveServerTestCase

# local Django
from pom.pages.authenticationPage import AuthenticationPage
from pom.pages.eventsPage import EventsPage
from shift.utils import (create_admin, create_event_with_details)


class EventDetails(LiveServerTestCase):
"""
Contains Tests for Job app in aspect of
an admin's view of website.
"""

@classmethod
def setUpClass(cls):
cls.driver = webdriver.Firefox()
cls.driver.implicitly_wait(5)
cls.driver.maximize_window()
cls.event_details_page = EventsPage(cls.driver)
cls.authentication_page = AuthenticationPage(cls.driver)
super(EventDetails, cls).setUpClass()

@classmethod
def tearDownClass(cls):
cls.driver.quit()
super(EventDetails, cls).tearDownClass()

def setUp(self):
create_admin()
self.login_admin()

def tearDown(self):
self.authentication_page.logout()

@staticmethod
def register_valid_event():
created_event = create_event_with_details(['event', '2050-06-11', '2050-06-19'])
return created_event

def check_error_messages(self):
event_details_page = self.event_details_page
self.assertEqual(len(event_details_page.get_help_blocks()), 3)
self.assertEqual(event_details_page.get_event_name_error(), event_details_page.FIELD_REQUIRED)
self.assertEqual(event_details_page.get_event_start_date_error(), event_details_page.FIELD_REQUIRED)
self.assertEqual(event_details_page.get_event_end_date_error(), event_details_page.FIELD_REQUIRED)

def login_admin(self):
authentication_page = self.authentication_page
authentication_page.server_url = self.live_server_url
authentication_page.login(
{
'username': 'admin',
'password': 'admin'
}
)

def test_event_details_view(self):
# Navgate to event view
event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()

self.assertEqual(event_details_page.get_message_context(),
event_details_page.NO_EVENT_PRESENT)

# Create a valid event
created_event = EventDetails.register_valid_event()

# Verify Details
event_details_page.navigate_to_event_list_view()
self.assertEqual(event_details_page.get_event_name(), created_event.name)
self.assertEqual(event_details_page.get_event_start_date(), 'June 11, 2050')
self.assertEqual(event_details_page.get_event_end_date(), 'June 19, 2050')

def test_valid_event_create(self):
created_event = EventDetails.register_valid_event()

event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()

# Check event creation
self.assertEqual(event_details_page.get_event_name(), created_event.name)
self.assertEqual(event_details_page.get_event_start_date(), 'June 11, 2050')
self.assertEqual(event_details_page.get_event_end_date(), 'June 19, 2050')

def test_invalid_event_create(self):
event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()

# Create empty job
event = ['', '', '']
event_details_page.go_to_create_event_page()
event_details_page.fill_event_form(event)

# Check error messages
self.check_error_messages()

def test_invalid_event_edit(self):
registered_event = EventDetails.register_valid_event()
event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()

event_details_page.go_to_edit_event_page()

null_valued_event = ['', '', '']
event_details_page.fill_event_form(null_valued_event)
self.check_error_messages()

def test_valid_event_edit(self):
registered_event = EventDetails.register_valid_event()
event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()

edit_job = ['newevent', '2050-06-12', '2050-06-20']
event_details_page.go_to_edit_event_page()
event_details_page.fill_event_form(edit_job)
event_details_page.navigate_to_event_list_view()

self.assertEqual(event_details_page.get_event_name(), edit_job[0])
self.assertEqual(event_details_page.get_event_start_date(), 'June 12, 2050')
self.assertEqual(event_details_page.get_event_end_date(), 'June 20, 2050')

def test_event_delete(self):
registered_event = EventDetails.register_valid_event()
event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()

self.assertEqual(event_details_page.get_delete_event_element('').text, 'Delete')
event_details_page.get_delete_event_element('//a').click()
self.assertEqual(event_details_page.get_deletion_context(), 'Delete Event')
event_details_page.submit_form()

def test_start_date_after_end_date(self):
event_details_page = self.event_details_page
event_details_page.live_server_url = self.live_server_url
event_details_page.go_to_events_page()
event_details_page.go_to_create_event_page()

event_start_after_end = ['event name', '2050-06-17', '2050-06-16']
event_details_page.fill_event_form(event_start_after_end)

# Check error.
self.assertEqual(event_details_page.get_event_start_date_error(),
event_details_page.START_BEFORE_END)
115 changes: 115 additions & 0 deletions vms/event/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# third party

# Django
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.test.testcases import TestCase

# local Django
from event.models import Event
from shift.utils import create_event_with_details
from pom.pages.eventsPage import EventsPage


class EventModelTests(TestCase):

def setUp(self):
pass

def tearDown(self):
pass

@staticmethod
def create_event():
event = ['event-name', '2050-05-24', '2050-05-28']
created_event = create_event_with_details(event)
return created_event

def test_valid_model_create(self):
event = ['event-name', '2050-05-24', '2050-05-28']
create_event_with_details(event)

# Check database for instance creation
self.assertNotEqual(len(Event.objects.all()), 0)

event_in_db = Event.objects.get(Q(name='event-name'))
# Verify correctness
self.assertEqual(event_in_db.name, event[0])
self.assertEqual(str(event_in_db.start_date), event[1])
self.assertEqual(str(event_in_db.end_date), event[2])

def test_invalid_model_create(self):
event = ['event~name', '2050-05-21', '2050-05-24']
event = create_event_with_details(event)

self.assertRaisesRegexp(ValidationError, EventsPage.ENTER_VALID_VALUE, event.full_clean)

# Check database for instance creation
self.assertNotEqual(len(Event.objects.all()), 0)

def test_model_edit_with_valid_values(self):
created_event = EventModelTests.create_event()

# Check db for instance creation
self.assertEqual(len(Event.objects.all()), 1)

event_in_db = Event.objects.get(Q(name='event-name'))
# Check if correct event retrieved
self.assertEqual(event_in_db.name, created_event.name)

# Edit job
event_in_db.name = 'new-event-name'
event_in_db.save()

event_in_db = Event.objects.get(Q(name='new-event-name'))
# Check if save is success
self.assertEqual(event_in_db.name, 'new-event-name')
self.assertEqual(len(Event.objects.all()), 1)

def test_model_edit_with_invalid_values(self):
created_event = EventModelTests.create_event()

# Check db for instance creation
self.assertEqual(len(Event.objects.all()), 1)

event_in_db = Event.objects.get(Q(name='event-name'))
# Check if correct event retrieved
self.assertEqual(event_in_db.name, created_event.name)

# Edit job
event_in_db.name = 'new~event~name'
event_in_db.save()

self.assertRaisesRegexp(ValidationError,
EventsPage.ENTER_VALID_VALUE,
event_in_db.full_clean)

# Check database for instance creation
self.assertNotEqual(len(Event.objects.all()), 0)

def test_model_delete(self):
created_event = EventModelTests.create_event()

# Check db for instance creation
self.assertEqual(len(Event.objects.all()), 1)

event_in_db = Event.objects.get(Q(name='event-name'))
# Check if correct job retrieved
self.assertEqual(event_in_db.name, created_event.name)

# Delete job
event_in_db.delete()

# Check if delete is successful
self.assertEqual(len(Event.objects.all()), 0)

def test_model_representation(self):
EventModelTests.create_event()

# Check db for instance creation
self.assertEqual(len(Event.objects.all()), 1)

event_in_db = Event.objects.get(Q(name='event-name'))

# Check __str__
self.assertEqual(str(event_in_db), event_in_db.name)
1 change: 0 additions & 1 deletion vms/event/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class EventWithVolunteerTest(unittest.TestCase):

@classmethod
def setup_test_data(cls):

cls.e1 = e1
cls.e2 = e2
cls.e3 = e3
Expand Down
Loading

0 comments on commit 7c0a0c2

Please sign in to comment.