def setUp(self): rand_text = list() for _ in range(3): rand_text.append(''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8))) p = {"scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=" + rand_text[0], "full_url": "https://pastebin.com/" + rand_text[0], "date": "1442911802", "key": rand_text[0], "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": rand_text[1:], } self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url")) self.database = MongoDB(collectionname="pastepwn_test")
class SQLiteDBTest(unittest.TestCase): def setUp(self): rand_text = [] for _ in range(3): rand_text.append("".join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8))) p = { "scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=" + rand_text[0], "full_url": "https://pastebin.com/" + rand_text[0], "date": "1442911802", "key": rand_text[0], "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": rand_text[1:], } self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url")) self.database = SQLiteDB(dbpath="sqlite_test/pastepwn_test") def tearDown(self): self.database.close_connection() shutil.rmtree(os.path.dirname(self.database.dbpath)) def test_insert_same_key(self): for body_text in self.p["body"]: self.paste.set_body(body_text) self.database.store(self.paste) self.assertEqual( self.database.cursor.execute( "SELECT body FROM pastes WHERE key = \'{0}\'".format( self.p["key"])).fetchone()[0], self.p["body"][1])
class MongoDBTest(unittest.TestCase): def setUp(self): rand_text = [] for _ in range(3): rand_text.append("".join( random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(8))) p = { "scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=" + rand_text[0], "full_url": "https://pastebin.com/" + rand_text[0], "date": "1442911802", "key": rand_text[0], "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": rand_text[1:], } self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url")) self.database = MongoDB(collectionname="pastepwn_test") def tearDown(self): self.database.db.drop_collection("pastepwn_test") def test_insert_same_key(self): # Insert a paste two times with the same body for body_text in self.p.get("body"): self.paste.set_body(body_text) self.database.store(self.paste) stored_paste = self.database.get(self.p.get("key")) comparison = self.p.get("body")[1] self.assertEqual(stored_paste.next().get("body"), comparison)
class PasteTest(unittest.TestCase): def setUp(self): p = {"scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=0CeaNm8Y", "full_url": "https://pastebin.com/0CeaNm8Y", "date": "1442911802", "key": "0CeaNm8Y", "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": "This is a test for pastepwn"} self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url")) def tearDown(self): pass def test_init_paste(self): self.assertEqual(self.p.get("key"), self.paste.key) self.assertEqual(self.p.get("title"), self.paste.title) self.assertEqual(self.p.get("user"), self.paste.user) self.assertEqual(self.p.get("size"), self.paste.size) self.assertEqual(self.p.get("date"), self.paste.date) self.assertEqual(self.p.get("expire"), self.paste.expire) self.assertEqual(self.p.get("syntax"), self.paste.syntax) self.assertEqual(self.p.get("scrape_url"), self.paste.scrape_url) self.assertEqual(self.p.get("full_url"), self.paste.full_url) self.assertEqual(None, self.paste.body) def test_set_body(self): my_body = "This is a test for pastepwn" self.paste.set_body(my_body) self.assertEqual(my_body, self.paste.body) def test_to_dict(self): my_body = "This is a test for pastepwn" self.paste.set_body(my_body) paste_dict = self.paste.to_dict() self.assertEqual(self.p, paste_dict)
def setUp(self): p = { "scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=0CeaNm8Y", "full_url": "https://pastebin.com/0CeaNm8Y", "date": "1442911802", "key": "0CeaNm8Y", "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": "this is a test paste" } self.p = p self.paste = Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url"))
def generate_paste(): """Returns a paste for testing""" p = { "scrape_url": "https://scrape.pastebin.com/api_scrape_item.php?i=0CeaNm8Y", "full_url": "https://pastebin.com/0CeaNm8Y", "date": "1442911802", "key": "0CeaNm8Y", "size": "890", "expire": "1442998159", "title": "Once we all know when we goto function", "syntax": "java", "user": "******", "body": "This is a test for pastepwn" } return Paste(p.get("key"), p.get("title"), p.get("user"), p.get("size"), p.get("date"), p.get("expire"), p.get("syntax"), p.get("scrape_url"), p.get("full_url"))