Ejemplo n.º 1
0
def get_fact_subject(topic):
    """
    Generates a random fact about a particular topic
    
    :param topic: The topic that a fact should be related to
    :type topic: str

    :rtype: int
    """
    try:
        subject, facts = FG.get_fact_subject(topic)
    except:
        return {
            "error":
            "An internal error occurred while attempting to contact Wikipedia"
        }, status.HTTP_502_BAD_GATEWAY
    response = {}
    if (subject is not "error"):
        response["subject"] = subject
        response["facts"] = facts
        code = status.HTTP_200_OK
    else:
        response["error"] = facts
        code = status.HTTP_404_NOT_FOUND
    return jsonify(response), code
Ejemplo n.º 2
0
 def test_get_fact_subject_fail(self):
     """ Tests that an error message is returned when an invalid subject is given"""
     print("\n\n")
     subject = 'ergopoiewgporewom'
     response = FG.get_fact_subject(subject)
     return_subject = response[0]
     facts = response[1]
     self.assertEqual(return_subject, 'error')
     self.assertTrue('ergopoiewgporewom' in facts)
     print(response)
     print("\n")
Ejemplo n.º 3
0
 def test_get_fact_subject(self):
     """ Tests that facts can be returned for 'Barack Obama' """
     print("\n\n")
     subject = 'Barack Obama'
     response = FG.get_fact_subject(subject)
     return_subject = response[0]
     facts = response[1]
     self.assertEqual(return_subject, 'Barack Obama')
     self.assertTrue('Obama' in facts)
     print(response)
     print("\n")