Commits

Yuki KODAMA  committed 9741742

test: add utility method to get account data

  • Participants
  • Parent commits f69bb1c

Comments (0)

Files changed (1)

File tests/test_user_handler.py

         return [tweet for tweet
                 in model.Tweet.all().filter('twitter_id =', tid)]
 
+    def get_account(self, tid='mail2tw'):
+        return model.Account.all().filter('twitter_id =', tid).get()
+
     def test_account_status(self):
         # check current service status
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('running', account.status)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('stopped', resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('stopped', account.status)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('running', resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('running', account.status)
 
     def test_account_status_badparam(self):
         # check current service status
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('running', account.status)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('running', resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('running', account.status)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('running', resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('running', account.status)
 
     def test_account_deactivate(self):
         # check existence of account
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
 
         # deactivate account
         self.assertEqual('http://localhost/signout', resp.headers['Location'])
 
         # after deactivated account
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertEqual(account, None)
 
     def test_account_regen(self):
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
 
         # regenerate address id
         self.assertEqual('200 OK', resp.status)
         self.assertNotEqual(old_email, resp.json['email'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         new_email = util.make_address(account.address_id)
         self.assertEqual(new_email, resp.json['email'])
 
     def test_account_regen_badparam(self):
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
 
         # invalid address id
 
     def test_forward_status_edit(self):
         # check current forwarding status
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertFalse(account.reply_forward)
 
         self.assertEqual('200 OK', resp.status)
         self.assertTrue(resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertTrue(account.reply_forward)
 
         self.assertEqual('200 OK', resp.status)
         self.assertFalse(resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertFalse(account.reply_forward)
 
     def test_forward_status_edit_badparam(self):
         # check current forwarding status
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertFalse(account.reply_forward)
 
         self.assertEqual('200 OK', resp.status)
         self.assertFalse(resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertFalse(account.reply_forward)
 
         self.assertEqual('200 OK', resp.status)
         self.assertFalse(resp.json['status'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertFalse(account.reply_forward)
 
     def test_forward_email_edit(self):
         # check current forwarding email address
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual(account.user_email, None)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('mail2tw@example.com', resp.json['email'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('mail2tw@example.com', account.user_email)
 
     def test_forward_email_edit_badparam(self):
         # check current forwarding email address
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual(account.user_email, None)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('', resp.json['email'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('mail2tw@example.com', account.user_email)
 
         self.assertEqual('200 OK', resp.status)
         self.assertEqual('', resp.json['email'])
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(account, None)
         self.assertEqual('mail2tw@example.com', account.user_email)
 
 
     def test_tweet_post(self):
         # check current statistics
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(None, account)
         self.assertEqual(0, account.count)
         self.assertEqual(None, account.last_updated)
         tweets = self.get_all_scheduled_tweets()
         self.assertEqual(4, len(tweets))
 
-        account = model.Account.all().filter('twitter_id =', 'mail2tw').get()
+        account = self.get_account()
         self.assertNotEqual(None, account)
         self.assertEqual(1, account.count)
         self.assertNotEqual(None, account.last_updated)