class test_tweet(unittest.TestCase): def setUp(self): self.aScrape = Scraping("realdonaldtrump", 2) self.aScrape.scrape_data() self.shortlist = self.aScrape.get_posts() def test_tweet(self): """ Testing that scraping actually returns a 'Tweet' type """ newTweet = self.shortlist[0] self.assertIsInstance(newTweet, tweet) def test_print_all(self): """ Trying to a raise an error by putting non-tweet types into a list of tweets, and printing them all with this method, causing a 'AttributeError', and showing the downside to pythons dynamic ducktyping. More specificly, im trying to put at scraping-object into the list """ dumbScrape = Scraping("realdonaldtrump", 1) self.shortlist.append(dumbScrape) self.assertRaises(AttributeError, tweet.print_tweetlist, self.shortlist)
def test_getpostList_Json(self): """ Testing that, when reading from a generated file, it is possible to get python-postpbjects from it. it is a little dumb, but you have to provide console input to run test """ newScrape = Scraping("BarackObama", 3) newScrape.scrape_data() payload = newScrape.get_posts() Organizer.create_project("BarackObama") Organizer.write_file_json(payload, "BarackObama") supposedpath = os.getcwd() + "/Jsondata_files/BarackObama" list , path = Organizer.getpostList_Json() self.assertIsInstance(list[0], tweet) self.assertEqual(path, supposedpath)
def test_get_posts(self): """ Trying to fill the wrong types of objects into """ aScrape = Scraping("realdonaldtrump", 2) aScrape.scrape_data() listofposts = aScrape.get_posts() self.assertTrue(listofposts)