Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add User tests for UserManager.py #868

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

carpecodeum
Copy link

@carpecodeum carpecodeum commented Jan 22, 2020

Description

added tests for adding, removing and updatinng both normal and regular user for UserManager.py

#851

Motivation and Context

this will enhance testing for existing helper functions
Screenshot 2020-01-22 at 1 07 16 PM
after integrating with testing.mysqld
Screenshot 2020-01-30 at 5 28 51 PM
the existing tests
Screenshot 2020-01-31 at 7 06 35 PM
Screenshot 2020-02-05 at 12 28 35 AM

in UserManager.py

How Has This Been Tested?

Screenshots (In case of UI changes):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@carpecodeum
Copy link
Author

@JaDogg please review this and tell me any necessary changes that need to be made in further tests. Also for writing future tests I was thinking of making a mock db. Please give your suggestions.

class Test(unittest.TestCase):

def test_check_existing_username(self):
self.assertEqual(True,check_user_name('rand'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use something like PyCharm's auto formatter to format these files.

Copy link
Author

Choose a reason for hiding this comment

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

okay i will do that!

@JaDogg
Copy link
Collaborator

JaDogg commented Jan 22, 2020

@JaDogg please review this and tell me any necessary changes that need to be made in further tests. Also for writing future tests I was thinking of making a mock db. Please give your suggestions.

We can do this in few ways:

  1. Use an ORM like PonyORM or SQLAlchemy (SQLAlchemy has migrations so I'd pick that) & use an SQLite (memory) DB for testing.
  2. Just spin a docker image for testing. (We can also probably use dunner for this) - so the DB is created and discarded.

@JaDogg JaDogg requested a review from kmehant January 22, 2020 10:33
@@ -42,7 +42,11 @@
}
],
"dependencies": {
"jasmine-core": "^2.5.2"
"fsevents": "^2.1.2",
"gyp": "^0.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did the package.json changed for python tests?

Copy link
Author

Choose a reason for hiding this comment

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

these have come during the setup of the frontend. these packages were somewhat required to complete the setup otherwise a few errors were flashing. any suggestions are most welcome.

@carpecodeum
Copy link
Author

@JaDogg please review this and tell me any necessary changes that need to be made in further tests. Also for writing future tests I was thinking of making a mock db. Please give your suggestions.

We can do this in few ways:

  1. Use an ORM like PonyORM or SQLAlchemy (SQLAlchemy has migrations so I'd pick that) & use an SQLite (memory) DB for testing.
  2. Just spin a docker image for testing. (We can also probably use dunner for this) - so the DB is created and discarded.

we can also checkout testing.mysqld module it automatically setups a mysqld instance in a temporary directory, and destroys it after testing. what are your thoughts?

@JaDogg
Copy link
Collaborator

JaDogg commented Jan 22, 2020

@JaDogg please review this and tell me any necessary changes that need to be made in further tests. Also for writing future tests I was thinking of making a mock db. Please give your suggestions.

We can do this in few ways:

  1. Use an ORM like PonyORM or SQLAlchemy (SQLAlchemy has migrations so I'd pick that) & use an SQLite (memory) DB for testing.
  2. Just spin a docker image for testing. (We can also probably use dunner for this) - so the DB is created and discarded.

we can also checkout testing.mysqld module it automatically setups a mysqld instance in a temporary directory, and destroys it after testing. what are your thoughts?

Will that work in Travis-CI 🤔 if so go ahead.

@carpecodeum
Copy link
Author

@JaDogg I have integrated testing.mysqld module and it passes the travis-CI test given your permission I will implement this on the upcoming and the existing tests

Copy link
Collaborator

@JaDogg JaDogg left a comment

Choose a reason for hiding this comment

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

Can you change the file to user_tests.py

import testing.mysqld

# Generate Mysqld class which shares the generated database
Mysqld = testing.mysqld.MysqldFactory(cache_initialized_db=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change this to MYSQLD

Copy link
Author

Choose a reason for hiding this comment

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

Okay I will!

@carpecodeum
Copy link
Author

Can you change the file to user_tests.py

Sure!

@carpecodeum
Copy link
Author

@JaDogg can you please help me with something I am not able to pass the token generated from the login test function inside a test class to subsequent test functions. Please suggest me away to to that.

JaDogg
JaDogg previously approved these changes Feb 2, 2020
@carpecodeum
Copy link
Author

@JaDogg I have added a few changes that make the running of tests look better and more manageable and elaborate.

@carpecodeum
Copy link
Author

@JaDogg Can you please tell me if there are any issues with this pr or is it good enough to be approved?

import Models


import unittest

Choose a reason for hiding this comment

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

Duplicate import statement. Same as in line no:4.

suite = unittest.TestLoader().loadTestsFromTestCase(Test)
unittest.TextTestRunner(verbosity=2).run(suite)


Choose a reason for hiding this comment

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

Unwanted new line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants