Esempio n. 1
0
 def test_multiple_user_save(self):
   '''
   this test case will be used to test if multiple users can be saved if need be 
   '''
   self.new_user.user_save()
   test_user = UserInfo('Test', 'Tester')
   test_user.user_save()
   self.assertEqual(len(UserInfo.Users),2)
Esempio n. 2
0
 def test_find_user(self):
   '''
   this test case to make sure a user can be found to confirm they are who they say they are 
   '''
   self.new_user.user_save()
   test_user = UserInfo('Jeremy', 'Test')
   test_user.user_save()
   found_user = UserInfo.find_user('Jeremy')
   self.assertEqual(found_user.username, test_user.username)
Esempio n. 3
0
 def test_delete_user(self):
   '''
   this test case to make sure a user can be deleted
   '''
   self.new_user.user_save()
   test_user = UserInfo('Test', 'Tester')
   test_user.user_save()
   self.new_user.user_delete()
   self.assertEqual(len(UserInfo.Users),1)
Esempio n. 4
0
 async def get_todays_forecast(self, ctx, days, *location):
     if UserInfo().check_if_users_ready():
         user = str(ctx.author)
         if user in UserInfo.USERS.keys(
         ) and UserInfo.USERS[user]["tz"] != "":
             tz = UserInfo.USERS[user]["tz"]
         else:
             await ctx.send(
                 'You can get better tailored information by setting your timezone with me by typing '
                 '!settz')
             tz = None
     else:
         tz = None
     location = " ".join(location)
     if len(location) > 0:
         loop = asyncio.get_event_loop()
         keyword_blocking_function = functools.partial(
             self.get_weather_for_area, location, days=days, tz=tz)
         embed_list = await loop.run_in_executor(ThreadPoolExecutor(),
                                                 keyword_blocking_function)
         for embed in embed_list:
             embed.set_footer(
                 text=f'Requested by: {ctx.message.author.name}')
             await ctx.send(embed=embed)
     else:
         await ctx.send(
             'Error: Please type: !getforecast <# of days> <location>')
Esempio n. 5
0
 async def get_todays_weather(self, ctx, *location):
     # check if user has a timezone
     if UserInfo().check_if_users_ready():
         user = str(ctx.author)
         if user in UserInfo.USERS.keys(
         ) and UserInfo.USERS[user]["tz"] != "":
             tz = UserInfo.USERS[user]["tz"]
         else:
             await ctx.send(
                 'You can get better tailored information by setting your timezone with me by typing '
                 '!settz')
             tz = None
     else:
         tz = None
     location = " ".join(location)
     if len(location) > 0:
         loop = asyncio.get_event_loop()
         keyword_blocking_function = functools.partial(
             self.get_weather_for_area, location, days=1, tz=tz)
         embed = await loop.run_in_executor(ThreadPoolExecutor(),
                                            keyword_blocking_function)
         embed.set_footer(text=f'Requested by: {ctx.message.author.name}')
         await ctx.send(embed=embed)
     else:
         await ctx.send('Please provide a city/state or zip code.')
Esempio n. 6
0
class TestUser(unittest.TestCase):
  '''
  Test class that defines test cases for the contact class behaviours.

  Args:
  unittest.TestCase: TestCase class that helps in creating test cases
  '''

  def setUp(self):
    '''
    This is a set up method to run before each test case.
    '''
    self.new_user = UserInfo('Jeremy', '12345')
  
  def tearDown(self):
    '''
    That erases the data after each test case has run.
    '''
    UserInfo.Users=[]

  def test_init(self):
    '''
    test case to see if the object is correctly initialised.
    '''
    self.assertEqual(self.new_user.username,'Jeremy')
    self.assertEqual(self.new_user.password,'12345')

  def test_user_save(self):
    '''
    this test case will be testing if saving a users username and password is possible and done into the user object
    '''
    self.new_user.user_save()
    self.assertEqual(len(UserInfo.Users),1)

  def test_multiple_user_save(self):
    '''
    this test case will be used to test if multiple users can be saved if need be 
    '''
    self.new_user.user_save()
    test_user = UserInfo('Test', 'Tester')
    test_user.user_save()
    self.assertEqual(len(UserInfo.Users),2)

  def test_delete_user(self):
    '''
    this test case to make sure a user can be deleted
    '''
    self.new_user.user_save()
    test_user = UserInfo('Test', 'Tester')
    test_user.user_save()
    self.new_user.user_delete()
    self.assertEqual(len(UserInfo.Users),1)

  def test_find_user(self):
    '''
    this test case to make sure a user can be found to confirm they are who they say they are 
    '''
    self.new_user.user_save()
    test_user = UserInfo('Jeremy', 'Test')
    test_user.user_save()
    found_user = UserInfo.find_user('Jeremy')
    self.assertEqual(found_user.username, test_user.username)
Esempio n. 7
0
 def setUp(self):
   '''
   This is a set up method to run before each test case.
   '''
   self.new_user = UserInfo('Jeremy', '12345')
Esempio n. 8
0
def search_user(username):
    '''
  Function to search if a user exists
  '''
    return UserInfo.find_user(username)
Esempio n. 9
0
def create_user(username, password):
    '''
  Function to create a new user
  '''
    new_user = UserInfo(username, password)
    return new_user