Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Tests for Event app #707

Merged
merged 1 commit into from
Jun 13, 2018
Merged

Conversation

Monal5031
Copy link
Contributor

@Monal5031 Monal5031 commented Jun 3, 2018

Description

Tested event app

  • Uncommented and corrected the commented tests
  • Move tests from automated testing repo
  • Write my own tests

Fixes #702

Type of Change:

Delete irrelevant options.

  • Code
  • Quality Assurance

Code/Quality Assurance Only

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

To verify that tests are non-breaking change in job app use:

python manage.py test job -v 2

and to overall project use:

python manage.py test

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • [x]I have commented my code or provided relevant documentation, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged

Code/Quality Assurance Only

  • My changes generate no new warnings
  • My PR currently breaks something (fix or feature that would cause existing functionality to not work as expected)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been published in downstream modules

@Monal5031 Monal5031 added Type: Testing UI Tests, Integration Tests, Travis CI, etc. Program: GSOC Related to work completed during the Google Summer of Code Program. category: testing labels Jun 3, 2018
@anitab-org anitab-org deleted a comment Jun 3, 2018
@anitab-org anitab-org deleted a comment Jun 3, 2018
@anitab-org anitab-org deleted a comment Jun 3, 2018
Copy link
Contributor Author

@Monal5031 Monal5031 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some changes, multiple instances are possible for following.

@@ -113,6 +112,9 @@ def go_to_create_organization_page(self):
def get_deletion_box(self):
return self.element_by_class_name(self.elements.DELETION_BOX)

def get_delete_element(self, relative):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to get_delete_event_element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


def check_error_messages(self):
event_details_page = self.event_details_page
error_message = 'This field is required.'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a variable inside EventsPage itself (multiple uses might be possible.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

event_details_page.go_to_events_page()

self.assertEqual(event_details_page.get_message_context(),
'There are currently no events. Please create events first.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, class var in EventsPage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

event_details_page.fill_event_form(event_start_after_end)

# Check error.
self.assertEqual(event_details_page.get_event_start_date_error(), 'Start date must be before the end date')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

self.assertEqual(str(event_in_db.start_date), event[1])
self.assertEqual(str(event_in_db.end_date), event[2])

# Checks are missing from model class
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raise issue after confirmation in tomorrow's meeting.

Copy link
Contributor Author

@Monal5031 Monal5031 Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround Solution found:
model validation checks aren't performed until a full_clean is called explicitly from code/command-line, Forms perform full_clean on submit thats why the error messages are shown. Thus model.save() will save the instance unless there not-null constraint is broken.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to use the workaround for now and file an issue to fix the bug later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well its not a workaround per se, as I explained in the later part that model.save() doesnt actually executes the validation checks we need clean or full clean for it which is done by default in forms so there we can see an error while saving i.e.form.save but not in model.save. Ideally we should have a custom clean function in model to raise error while model save.

self.assertEqual(event_in_db.name, 'new-event-name')
self.assertEqual(len(Event.objects.all()), 1)

# Clear function needs to be implemented for this.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

@Monal5031 Monal5031 Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround Solution found:
model validation checks aren't performed until a full_clean is called explicitly from code/command-line, Forms perform full_clean on submit thats why the error messages are shown. Thus model.save() will save the instance unless there not-null constraint is broken.

@@ -172,77 +157,77 @@ def test_shift_sign_up_with_outdated_shifts(self):

# on jobs page
sign_up_page.click_to_view_shifts()
self.assertEqual(sign_up_page.get_info_box().text,'There are currently no shifts for the job job.')
self.assertEqual(sign_up_page.get_info_box().text, 'There are currently no shifts for the job job.')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class var in EventsPage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

shift_1 = ["2016-05-11","9:00","15:00",6,Job.objects.get(name = 'job')]
s1 = create_shift_with_details(shift_1)
shift_1 = ["2016-05-11", "9:00", "15:00", 6, Job.objects.get(name='job')]
create_shift_with_details(shift_1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If something is returned, it is good practice to store the return value even if you're not using it. Someone else might want it later, but this way they'll think the function returns nothing.

v2 = create_volunteer_with_details(volunteer_2)

# Assign shift to the volunteer
vol_shift = register_volunteer_for_shift_utility(s2, v2)
register_volunteer_for_shift_utility(s2, v2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture return value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codacy was marking it as unused variable and failing. 😞

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll delete codacy comments, not to worry!

Copy link
Contributor

@naman1901 naman1901 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update us on the workaround/bugfix issue.
It is good practice to capture return values even if you don't use them.

@prachi1210
Copy link
Contributor

prachi1210 commented Jun 7, 2018

Review awaited from Anjali, Update and finalise PR and ping me on Slack @Monal5031

@Monal5031 Monal5031 force-pushed the testing-event branch 4 times, most recently from b3fbf6b to 82ccfda Compare June 10, 2018 02:28
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
@anitab-org anitab-org deleted a comment Jun 10, 2018
Copy link
Contributor

@anjali-dhanuka anjali-dhanuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@prachi1210 prachi1210 merged commit 67b84ee into anitab-org:gsoc18-infra Jun 13, 2018
@Monal5031 Monal5031 deleted the testing-event branch June 13, 2018 17:23
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 2, 2018
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 2, 2018
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 3, 2018
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 3, 2018
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 4, 2018
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 6, 2018
anjali-dhanuka referenced this pull request in anjali-dhanuka/vms Jul 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Program: GSOC Related to work completed during the Google Summer of Code Program. Type: Testing UI Tests, Integration Tests, Travis CI, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants