-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #48 * mongodb: test if two same-key insertions update body * change mongodb insert to upsert * skip mongodb test when running via travis * sqlitedb: test if two same-key insertions update body * sqlite: add upsert
- Loading branch information
1 parent
27ed1f8
commit 86344b3
Showing
5 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import random | ||
import string | ||
import unittest | ||
|
||
from pastepwn import Paste | ||
from pastepwn.database import MongoDB | ||
|
||
|
||
@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.") | ||
class MongoDBTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
rand_text = list() | ||
for i 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": "admin", | ||
"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): | ||
for body_text in self.p['body']: | ||
self.paste.set_body(body_text) | ||
self.database.store(self.paste) | ||
|
||
self.assertEqual(self.database.get(self.p['key']).next()['body'], self.p['body'][1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import random | ||
import shutil | ||
import string | ||
import unittest | ||
|
||
from pastepwn import Paste | ||
from pastepwn.database import SQLiteDB | ||
|
||
|
||
class SQLiteDBTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
rand_text = list() | ||
for i 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": "admin", | ||
"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): | ||
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]) |