def test_get_pep(self):
        response = self.app.get('/pep/8')
        self.assertEqual(200, response.status_code)
        json_obj = json.loads(response.data, encoding='utf-8')
        self.assertIn('data', json_obj)

        with open('pep_documents/pep-0008.txt', 'rb') as f:
            raw_content = f.read().decode('utf-8')
            pep = PEP(raw_content)
        if pep:
            pep.parse_metadata()
            pep_dict = pep.to_dict()
        self.assertDictEqual(json_obj['data'], pep_dict)
        self.assertEqual(json_obj['raw'], raw_content)
def get_pep(pep_number):
    """Get the content div of the PEP by PEP number"""
    if not pep_number:
        return abort(400)

    with open('pep_documents/pep-%04d.txt' % pep_number, 'rb') as f:
        text = f.read().decode('utf-8')
    pep = PEP(text)
    pep.parse_metadata()
    pep_dict = pep.to_dict()
    if pep_dict:
        return jsonify(dict(data=pep_dict, raw=text))
    else:
        return abort(404)
 def setUp(self):
     path = 'pep_documents/pep-0008.txt'
     with open(path, 'rb') as f:
         data = f.read()
     self.pep = PEP(data)
class PEPTest(unittest.TestCase):
    def setUp(self):
        path = 'pep_documents/pep-0008.txt'
        with open(path, 'rb') as f:
            data = f.read()
        self.pep = PEP(data)

    def test_load_pep(self):
        self.assertEqual(self.pep.pep_text,
                         PEP.load_pep(8, directory='pep_documents').pep_text)

    def test_pep_text(self):
        self.assertIsNotNone(self.pep.pep_text)
        lines = self.pep.pep_text.splitlines()
        for line in lines:
            self.assertTrue(isinstance(line, str))

    def test_pep_parse_title(self):
        self.pep.parse_metadata()

        self.assertEqual('Style Guide for Python Code',
                         self.pep.title)

    def test_pep_parse_number(self):
        self.pep.parse_metadata()
        self.assertEqual('8', self.pep.number)

    def test_pep_parse_authors(self):
        self.pep.parse_metadata()
        authors = ['Guido van Rossum <*****@*****.**>',
                   'Barry Warsaw <*****@*****.**>',
                   'Nick Coghlan <*****@*****.**>']
        self.assertTrue(isinstance(self.pep.authors, list))
        self.assertEqual(authors, self.pep.authors)

    def test_pep_parse_type(self):
        self.pep.parse_metadata()
        self.assertEqual('Process', self.pep.type)

    def test_pep_parse_status(self):
        self.pep.parse_metadata()
        self.assertEqual('Active', self.pep.status)

    def test_pep_to_dict(self):
        self.pep.parse_metadata()
        pep_dict = self.pep.to_dict()
        self.assertIsInstance(pep_dict, dict)
 def test_load_pep(self):
     self.assertEqual(self.pep.pep_text,
                      PEP.load_pep(8, directory='pep_documents').pep_text)