예제 #1
0
    def test_view_tasks_twitter_post_status(self):
        if os.getenv('TWITTER_TESTS') == "FALSE":
            return # Modify in runtests.sh

        load_fixture('tests/states.json', kind={'State': State})
        load_fixture('tests/questions.json', 
                        kind={'Question': Question,'State': State})
        current_question = Question.get_current_question()

        # Add user with vote so we can test sway points
        vote_current = Vote(
            question = current_question.key,
            replyid = "123",
            state_abbreviation = "CA",
            party = 1,
            sway_points = 20
        )
        user = User(
            userid = "jrgrafton",
            votes = [vote_current],
            # Used 20 sway points upon creation
            sway_points = 30
        )
        user.put()
        original_sway_points = user.sway_points # Store initial sway points

        # Delete all previous tweets before proceeding
        twitter_api = TwitterAPI()
        twitter_api.delete_all_tweets()

        reponse = \
            self.app.get('/tasks/twitter_post_status' \
                '?question_cadence_minutes=1&post_to_twitter=True')
        current_question = Question.get_current_question()
        ndb.get_context().clear_cache()
        assert current_question.twitterid != None
        assert "Posted new status" in reponse.data
        assert status.is_success(reponse.status_code) == True

        # Ensure user had sway points returned
        assert user.sway_points == original_sway_points + \
                          sway_points_tasks["submit_answer"] + \
                          sway_points_tasks["submit_winning_answer"] + \
                          int(vote_current.sway_points * \
                              sway_points_tasks["refund"])

        # Ensure Twitter timeline has been updated
        twitter_status = twitter_api.get_last_tweet().text
        question_entity = Question.get_current_question()
        assert twitter_status == question_entity.question_text

        # Expect question not to be posted as time is not yet up
        reponse = \
            self.app.get('/tasks/twitter_post_status' \
                '?question_cadence_minutes=52560000')
        assert "New question not ready" in reponse.data
        assert status.is_success(reponse.status_code) == True
예제 #2
0
    def test_view_tasks_twitter_post_status(self):
        if os.getenv("TWITTER_TESTS") == "FALSE":
            return  # Modify in runtests.sh

        load_fixture("tests/states.json", kind={"State": State})
        load_fixture("tests/questions.json", kind={"Question": Question, "State": State})
        current_question = Question.get_current_question()

        # Add user with vote so we can test sway points
        vote_current = Vote(
            question=current_question.key, replyid="123", state_abbreviation="CA", party=1, sway_points=20
        )
        user = User(
            userid="jrgrafton",
            votes=[vote_current],
            # Used 20 sway points upon creation
            sway_points=30,
        )
        user.put()
        original_sway_points = user.sway_points  # Store initial sway points

        # Delete all previous tweets before proceeding
        twitter_api = TwitterAPI()
        twitter_api.delete_all_tweets()

        reponse = self.app.get("/tasks/twitter_post_status" "?question_cadence_minutes=1&post_to_twitter=True")
        current_question = Question.get_current_question()
        ndb.get_context().clear_cache()
        assert current_question.twitterid != None
        assert "Posted new status" in reponse.data
        assert status.is_success(reponse.status_code) == True

        # Ensure user had sway points returned
        assert user.sway_points == original_sway_points + sway_points_tasks["submit_answer"] + sway_points_tasks[
            "submit_winning_answer"
        ] + int(vote_current.sway_points * sway_points_tasks["refund"])

        # Ensure Twitter timeline has been updated
        twitter_status = twitter_api.get_last_tweet().text
        question_entity = Question.get_current_question()
        assert twitter_status == question_entity.question_text

        # Expect question not to be posted as time is not yet up
        reponse = self.app.get("/tasks/twitter_post_status" "?question_cadence_minutes=52560000")
        assert "New question not ready" in reponse.data
        assert status.is_success(reponse.status_code) == True
예제 #3
0
    def test_view_tasks_twitter_post_status_complete(self):
        load_fixture("tests/states.json", kind={"State": State})
        load_fixture("tests/questions_complete.json", kind={"Question": Question})

        # No more questions so should never post anything
        # Doesn't post to Twitter - we don't want to overload the API
        reponse = self.app.get("/tasks/twitter_post_status" "?question_cadence_minutes=1")
        assert "New question not ready" in reponse.data
        assert status.is_success(reponse.status_code) == True
예제 #4
0
    def test_view_tasks_twitter_post_status_unstarted(self):
        load_fixture("tests/states.json", kind={"State": State})
        load_fixture("tests/questions_unstarted.json", kind={"Question": Question})

        # No last question so should always post something
        # Doesn't post to Twitter - we don't want to overload the API
        reponse = self.app.get("/tasks/twitter_post_status" "?question_cadence_minutes=52560000")
        assert "Posted new status" in reponse.data
        assert status.is_success(reponse.status_code) == True
예제 #5
0
    def test_view_tasks_twitter_post_status_complete(self):
        load_fixture('tests/states.json', kind={'State': State})
        load_fixture('tests/questions_complete.json', 
                        kind={'Question': Question})

        # No more questions so should never post anything
        # Doesn't post to Twitter - we don't want to overload the API
        reponse = \
            self.app.get('/tasks/twitter_post_status' \
                '?question_cadence_minutes=1')
        assert "New question not ready" in reponse.data
        assert status.is_success(reponse.status_code) == True
예제 #6
0
    def test_view_tasks_twitter_post_status_unstarted(self):
        load_fixture('tests/states.json', kind={'State': State})
        load_fixture('tests/questions_unstarted.json', 
                        kind={'Question': Question})

        # No last question so should always post something
        # Doesn't post to Twitter - we don't want to overload the API
        reponse = \
            self.app.get('/tasks/twitter_post_status' \
                '?question_cadence_minutes=52560000')
        assert "Posted new status" in reponse.data
        assert status.is_success(reponse.status_code) == True
예제 #7
0
    def test_delete_fact(self, delete_fact):
        """Verify success scenario.
        """
        # Set up mocks and test data
        delete_fact.return_value = fact_id = uuid.uuid4()

        # Make call
        response = self.delete_fact(fact_id)

        # Verify response status and data
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(json.dumps({'id': str(fact_id)}),
                         response.data)

        # Verify mocks
        delete_fact.assert_called_once_with(fact_id)
예제 #8
0
    def test_get_fact(self, get_fact):
        """Verify success scenario.
        """
        # Set up mocks and test data
        get_fact.return_value = mock.Mock(name='fact', fact_text='abracadabra')
        fact_id = uuid.uuid4()

        # Make call
        response = self.get_fact(fact_id)

        # Verify response status and data
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(json.dumps({'fact': 'abracadabra'}),
                         response.data)

        # Verify mocks
        get_fact.assert_called_once_with(fact_id)
예제 #9
0
    def test_post_fact(self, make_fact):
        """Verify success scenario.
        """
        # Set up mocks and test data
        fact_id = uuid.uuid4()
        make_fact.return_value = mock.Mock(name='fact', fact_id=fact_id)

        # Make call
        response = self.post_fact(fact_sentence='the otter lives in the river')

        # Verify response status and data
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(json.dumps({'id': str(fact_id)}),
                         response.data)

        # Verify mocks
        make_fact.assert_called_once_with('the otter lives in the river')
예제 #10
0
    def test_query_facts(self, query_facts):
        """Verify success scenario.
        """
        # Set up mocks and test data
        question = "who's your best friend"
        answer = "not barney"
        query_facts.return_value = answer

        # Make call
        response = self.query_facts(question)

        # Verify response status and data
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(json.dumps({'fact': answer}),
                         response.data)

        # Verify mocks
        query_facts.assert_called_once_with(question)
def test_ping(client):
    response = client.get('/ping')
    assert status.is_success(response.status_code)
    assert response.get_data(as_text=True) == 'Pong'
def test_home(client):
    response = client.get('/')
    assert status.is_success(response.status_code)
    assert response.get_data(as_text=True) == 'Hello, world!'
예제 #13
0
 def test_hello_name(self):
     name = "James"
     resp = self.app.get('/{}'.format(name))
     self.assertTrue("Hello, James" in resp.data)
     self.assertTrue(status.is_success(resp.status_code))
예제 #14
0
 def test_hello_world(self):
     resp = self.app.get('/')
     self.assertTrue("Hello, world!" in resp.data)
     self.assertTrue(status.is_success(resp.status_code))
예제 #15
0
 def test_hello_world(self):
     resp = self.app.get('/')
     self.assertTrue("Hello, world!" in resp.data)
     self.assertTrue(status.is_success(resp.status_code))
예제 #16
0
 def test_hello_name(self):
     name = "James"
     resp = self.app.get('/{}'.format(name))
     self.assertTrue("Hello, James" in resp.data)
     self.assertTrue(status.is_success(resp.status_code))