def testLastQuestionShouldGetLatestRetrievedQuestion(self):
   first_question = Question(id=12345, asker="firstuser", data="blah")
   second_question = Question(id=12345, asker="seconduser", data="blah2")
   third_question = Question(id=12345, asker="thirduser", data="blah3")
   
   first_question.put()
   second_question.put()
   third_question.put()
   
   last_question = Question.last_question()
   self.assertEqual("thirduser", last_question.asker)
Ejemplo n.º 2
0
 def testShouldOnlyAskForQuestionsAfterLastQuestion(self):
     last_question = Question(id=12345, asker="Cheese", data="pants")
     last_question.put()
     
     test_questions = []
     queue = Mock({ "add": None }, taskqueue)
     twitterbot = Mock({ "questions_since": test_questions }, TwitterBot)
     listener = Listener(twitterbot, queue)
     
     listener.listen()
     last_question.delete()
     
     twitterbot.mockCheckCall(0, "questions_since", last_question)
     self.failIf(queue.mockGetNamedCalls("add"))
     
Ejemplo n.º 3
0
 def testAnswerAQuestion(self):
   question = Question.from_mention({ "id" : 12345, "user" : { "screen_name": "testusername"}, "text": "@username restaurants collingwood" })
   client = Mock()
   oracle = Mock({"answer": "cheesy cheese"})
   twitterbot = TwitterBot(client, oracle, None)
   twitterbot.answer(question)
   client.mockCheckCall(0, "reply", 12345, "testusername", "cheesy cheese")
   oracle.mockCheckCall(0, "answer", "restaurants collingwood")
Ejemplo n.º 4
0
 def testQuestionShouldHandleIntegerIds(self):
   logging.info("Before question.from mention")
   question = Question.from_mention({ "id": 1234, "user": { "screen_name" : "testusername" }, "text" : "@csausbot cheese"})
   logging.info("After question from mention, before asserts")
   self.assertEqual(1234, question.id)
   self.assertEqual("testusername", question.asker)
   self.assertEqual("cheese", question.data)
   logging.info("Do we get to here ever?")
Ejemplo n.º 5
0
class AnswererTest(unittest.TestCase):
    
    test_question = None
    
    def setUp(self):
        self.test_question = Question(id=12345, asker="Cheese", data="blah blah")
        self.test_question.put()
        
    def test_should_answer_question(self):
        logging.info("test_question is %r", self.test_question)
        twitterbot = Mock({"answer": None}, TwitterBot)
        answerer = Answerer(twitterbot)
        
        answerer.answer(12345)
        twitterbot.mockCheckCall(0, "answer", self.test_question)
        
    def tearDown(self):
        self.test_question.delete()
Ejemplo n.º 6
0
 def test_should_shorten_answers(self):
   question = Question.from_mention({ "id" : 12345, "user" : { "screen_name": "testusername"}, "text": "@username restaurants collingwood" })
   client = Mock()
   oracle = Mock({"answer": "http://longurl.com/blah/cheesy/cheese"})
   urlshortener = Mock({"shorten": "http://shorturl.com/edam", "__nonzero__": 1})
   
   twitterbot = TwitterBot(client, oracle, urlshortener)
   twitterbot.answer(question)
   
   oracle.mockCheckCall(0, "answer", "restaurants collingwood")
   urlshortener.mockCheckCall(0, "__nonzero__")
   urlshortener.mockCheckCall(1, "shorten", "http://longurl.com/blah/cheesy/cheese")
   client.mockCheckCall(0, "reply", 12345, "testusername", "http://shorturl.com/edam")
Ejemplo n.º 7
0
  def testShouldFetchOnlyNewQuestions(self):
    test_mentions = [ 
      { "id" : 12345, "user": { "screen_name": "nomiddlename" }, "text": "@csausbot testing, testing, one, two, three."},
      { "id" : 12345, "user": { "screen_name": "cheekymonkey" }, "text": "@csausbot      "},
      { "id" : 12345, "user": { "screen_name": "eh" }, "text": "This @csausbot is really cool."}
      ]
    client = Mock({ "mentions": test_mentions })
    twitterbot = TwitterBot(client, None, None)
    
    lastQuestion = Question.from_mention({ "id" : 67891, "user" : { "screen_name": "testusername"}, "text": "@username blah" })
    questions = twitterbot.questions_since(lastQuestion)
    client.mockCheckCall(0, "mentions", 67891)
    
    self.assertEqual(len(questions), 1)
    question = questions[0]
    self.assertEqual(question.asker, "nomiddlename")
    self.assertEqual(question.data, "testing, testing, one, two, three.")

    query = Question.all()
    query.filter('id = ', 12345)
    self.assertEqual(1, query.count())
    db_question = query.get()
    self.assertEqual(question.asker, db_question.asker)
    self.assertEqual(question.data, db_question.data)
Ejemplo n.º 8
0
 def tearDown(self):
   query = Question.all()
   query.filter('id = ', 12345)
   for question in query:
     question.delete()
Ejemplo n.º 9
0
 def setUp(self):
     self.test_question = Question(id=12345, asker="Cheese", data="blah blah")
     self.test_question.put()
Ejemplo n.º 10
0
 def testQuestionBeginsWithUsernameShouldBeValid(self):
   question = Question.from_mention({ "id": 1234, "user" : { "screen_name": "testusername" }, "text": "@cheese blah" })
   self.assert_(question.is_valid())
Ejemplo n.º 11
0
 def testQuestionSetupFromMention(self):
   question = Question.from_mention({ "id": 1234, "user": { "screen_name" : "testusername" }, "text" : "@csausbot cheese"})
   self.assertEqual(1234, question.id)
   self.assertEqual("testusername", question.asker)
   self.assertEqual("cheese", question.data)
Ejemplo n.º 12
0
 def testMissingAskerShouldNotBeValid(self):
   question = Question.from_mention({ "id": 1234, "text" : "@csausbot cheese"})
   self.assertEqual(None, question)
   question = Question.from_mention({ "id": 1234, "user" : { "cheese" : "biscuits" }, "text": "@csausbot mince"})
   self.assertEqual(None, question)
Ejemplo n.º 13
0
 def testMissingIdShouldNotBeValid(self):
   question = Question.from_mention({ "user": { "screen_name" : "testusername" }, "text": "@csausbot blah"})
   self.assertEqual(None, question)
Ejemplo n.º 14
0
 def testEmptyQuestionShouldNotBeValid(self):
   question = Question.from_mention({ "id": 1234, "user" : { "screen_name": "testusername" }, "text": "@cheese     "})
   self.assertEqual(None, question)
   
   question = Question.from_mention({ "id": 1234, "user" : { "screen_name": "testusername" }, "text": "@cheese"})
   self.assertEqual(None, question)
Ejemplo n.º 15
0
 def setUp(self):
   query = Question.all()
   query.filter('id = ', 12345)
   for question in query:
     question.delete()
Ejemplo n.º 16
0
 def testQuestionWithUsernameInMiddleShouldNotBeValid(self):
   question = Question.from_mention({ "id": 1234, "user" : { "screen_name": "testusername" }, "text": "blah @cheese blah"})
   self.assertEqual(None, question)
 def testPutShouldWriteQuestionToDatabase(self):
   question = Question.from_mention({ "id": 12345, "user": { "screen_name" : "testusername" }, "text" : "@csausbot cheese"})
   key = question.put()
 
   stored_question = Question.get(key)
   self.assertEqual("testusername", stored_question.asker)