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

Administrator Tests #695

Merged
merged 1 commit into from
Jun 5, 2018
Merged

Conversation

Monal5031
Copy link
Contributor

@Monal5031 Monal5031 commented May 25, 2018

Description

Added tests for administrator app

  • Uncommented tests
  • Migrated tests from automated-testing repo.

Fixes #685

Type of Change:

Delete irrelevant options.

  • Code
  • Quality Assurance

Code/Quality Assurance Only

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

To test my tests:

python manage.py test administrator -v 2

To confirm non-breaking change:

python manage.py test -v 2

Checklist:

Delete irrelevant options.

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • 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 this to the Week2 milestone May 25, 2018
@Monal5031 Monal5031 added Difficulty: MEDIUM Program: GSOC Related to work completed during the Google Summer of Code Program. labels May 25, 2018
@Monal5031
Copy link
Contributor Author

Monal5031 commented May 25, 2018

Debug Testing here: test

@coveralls
Copy link

coveralls commented May 25, 2018

Coverage Status

Coverage increased (+28.8%) to 71.261% when pulling 6539403ee571a5164f3424da4ab21d26db167f67 on Monal5031:testing-admin into cf79a03 on systers:gsoc18-infra.

@anitab-org anitab-org deleted a comment May 25, 2018
@anitab-org anitab-org deleted a comment May 25, 2018
@anitab-org anitab-org deleted a comment May 25, 2018
@anitab-org anitab-org deleted a comment May 25, 2018
@anitab-org anitab-org deleted a comment May 25, 2018
@@ -75,6 +75,27 @@ def create_volunteer_with_details(volunteer):
return v1


def create_volunteer_with_details_dynamic_password(volunteer):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

please no. What is the use case of passing unrelated data in a list ? Please use a proper dict :-(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking for the same, (I hate using lists).
but the above related functions were using list so I didn't want to change the similarities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also @tonythomas01 can you please help me solve those broken pipe issue in travis without increasing the build time (it already 7 mins and I've added only 1 app).

Copy link
Contributor

Choose a reason for hiding this comment

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

okey - in that case, can you create a different task for changing this abuse of lists to dicts ? Let me look at the build steps as well.

Copy link
Contributor Author

@Monal5031 Monal5031 May 25, 2018

Choose a reason for hiding this comment

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

Okay I looked on the dependency of this change. Its quite huge should we really change it? There are other instances too where we should've used dict like fill_form functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about other instances, but if a function receives data about an instance and populates the instance model to create a new one - that is a dictionary use case. It would be huge depending on how much things are here, but hopefully somebody else would take care of it I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure then I'll create an issue for it. 👍 .
Also should the form filling in e2e tests is a dict use case right? (I mean when we pass info to that fill function) We use send_keys() to send the info at the end.

Copy link
Contributor

@tonythomas01 tonythomas01 May 26, 2018

Choose a reason for hiding this comment

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

I think yes. See, when its structured data - yes dict. Collection of similar stuff - list. Even though, there is nothing wrong in having mixed data in a list though, like say awkward_list = [1, 2, 'myvar', {'a_json_key': 'a_json_value'}, 345.4]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. that makes things quite clear.

Copy link
Contributor

@tonythomas01 tonythomas01 left a comment

Choose a reason for hiding this comment

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

I looked briefly at the code - and I see sleep times - please no. Why do you want to do that ? Can you point me to a documentation which asks you to put this - and that too like 50 seconds ?

@@ -39,7 +34,7 @@ def setUpClass(cls):
def setUp(self):
create_admin()
self.login_admin()
self.settings.go_to_events_page()
self.driver.implicitly_wait(50)
Copy link
Contributor

Choose a reason for hiding this comment

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

50 seconds ? really ? why do you want this ? please no.

@@ -52,21 +47,29 @@ def tearDownClass(cls):
def check_event_form_values(self, event):
settings = self.settings
self.assertEqual(settings.get_event_name_value(), event[0])
self.driver.implicitly_wait(10)
Copy link
Contributor

Choose a reason for hiding this comment

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

no.

self.assertEqual(settings.get_shift_end_time_value(), shift[2])
self.driver.implicitly_wait(10)
self.assertEqual(settings.get_shift_max_volunteers(), shift[3])
Copy link
Contributor

Choose a reason for hiding this comment

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

remove all sleep times please. if you want to have a sleep time - that too > 2 probably there is something wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonythomas01 Check these builds build1 and build2 Removing the implicit waits cause 33 of them to fail (locally 8 are failing).

I agree there are a lot of implicit waits and which is not a good practice to use but the redirects are fast that the forms are not being filled within the time frame and elements to be selected are refreshed.

All these tests work individually but as a whole they get a wait problem. 😕
Any suggestions how I can tackle 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.

Nevermind. Made some tweaks in my changes and it worked on my test branch.
Waiting for build on this PR.


# database check to ensure that job not created
# Check Database of job creation
self.assertEqual(len(Job.objects.all()), 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

to be honest, I see a bigger problem - if your tests are doing E2E stuff - then you should nto even care about what the database looks like here. but, I think this is not in scope of this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't we check for loopholes in backend if invalid instance are being created in db even after giving some error message in front?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's an antipattern for an E2E test. For a unit test, yes you should. In E2E - you look at direct user interactions. Cannot quote anything as from phone, but feel free to look it up.

@anitab-org anitab-org deleted a comment May 26, 2018
@anitab-org anitab-org deleted a comment May 26, 2018
@anitab-org anitab-org deleted a comment May 26, 2018
@anitab-org anitab-org deleted a comment May 26, 2018
@anitab-org anitab-org deleted a comment May 26, 2018
@anitab-org anitab-org deleted a comment May 26, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment from Monal5031 May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@anitab-org anitab-org deleted a comment May 27, 2018
@Monal5031
Copy link
Contributor Author

@tonythomas01 Any more changes needed? otherwise please mark approve.

Copy link
Contributor

@tonythomas01 tonythomas01 left a comment

Choose a reason for hiding this comment

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

getting shape. Good work so far, but has room for improvements.

[
{
"volunteer": [
"uname1",
Copy link
Contributor

@tonythomas01 tonythomas01 May 28, 2018

Choose a reason for hiding this comment

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

this representation is a start, but only half done. You need it like this.

"volunteer":  {
     "first_name":  "uname1",
      "last_name": "uname1", 
....
}

and then use it as: 

v1 = Volunteer(
+        email=volunteer['email'],
+        first_name=volunteer['first_name'],
+        last_name=volunteer['last_name'],
....
+    )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Umm... if I change this then I'd have to change the structure we earlier discussed (lists -> dict), I think this can be a part of the new issue we'll create to change use of lists to dict.

Copy link
Contributor

Choose a reason for hiding this comment

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

okey then. Once you link that new issue here, I will finish my review :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here you go @tonythomas01 #697

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good then. approving.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tonythomas01 . Will this issue be taken up by you, @Monal5031 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not atm, but if time persists before I move on to postorius I'll do it.

"""
u1 = User.objects.create_user(username=volunteer[0], password=volunteer[1])
v1 = Volunteer(
email=volunteer[2],
Copy link
Contributor

Choose a reason for hiding this comment

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

this and above will change after fixing my comment above.

Creates and returns volunteer with passed name and dates
"""
u1 = User.objects.create_user(username=volunteer[0], password=volunteer[1])
v1 = Volunteer(
Copy link
Contributor

Choose a reason for hiding this comment

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

inconsistency (minor though). Why not use Volunteer.objects.create() as you have used above (I know you have used a diff manager function, but the second one is a model instantiation via constructor which is different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The similar functions above have used this so I went with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

also, some general notes - please avoid using these kind of variables. u1, a1, b2, c3'. it should be user_1or even betteruser_a, user_b`, etc.

Copy link
Contributor

@tonythomas01 tonythomas01 left a comment

Choose a reason for hiding this comment

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

Given #697 gets tackled soon.

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 name variables as representative of what they are, even if you have to use long names. Makes the code more readable. For example - change v1 to volunteer1 or volunteer_1, as per guidelines followed.

@naman1901 naman1901 merged commit 0c1e7b6 into anitab-org:gsoc18-infra Jun 5, 2018
@Monal5031 Monal5031 deleted the testing-admin branch June 5, 2018 21:59
Monal5031 referenced this pull request in Monal5031/vms Jun 6, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants