mirror of
https://github.com/torproject/gettor.git
synced 2025-02-08 19:56:08 +00:00
Expand tests for database functions in gettor
This commit is contained in:
parent
c413a8ebda
commit
64df8b27b3
@ -82,5 +82,7 @@ GetTor includes PyTest unit tests. To run the tests, first install the dependenc
|
|||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
$ pytest-3 tests/
|
$ python3 scripts/create_db -n -c -o -f tests/gettor.db
|
||||||
|
$ python3 scripts/add_links_to_db -f tests/gettor.db
|
||||||
|
$ pytest-3 -s -v tests/
|
||||||
```
|
```
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_twisted
|
import pytest_twisted
|
||||||
|
from datetime import datetime
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
from . import conftests
|
from . import conftests
|
||||||
@ -10,7 +11,7 @@ class DatabaseTests(unittest.TestCase):
|
|||||||
# Fail any tests which take longer than 15 seconds.
|
# Fail any tests which take longer than 15 seconds.
|
||||||
timeout = 15
|
timeout = 15
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.settings = conftests.options.parse_settings("en","./gettor.conf.json")
|
self.settings = conftests.options.parse_settings("en","tests/test.conf.json")
|
||||||
self.locales = conftests.strings.get_locales()
|
self.locales = conftests.strings.get_locales()
|
||||||
|
|
||||||
self.conn = conftests.SQLite3(self.settings.get("dbname"))
|
self.conn = conftests.SQLite3(self.settings.get("dbname"))
|
||||||
@ -19,9 +20,56 @@ class DatabaseTests(unittest.TestCase):
|
|||||||
print("tearDown()")
|
print("tearDown()")
|
||||||
del self.conn
|
del self.conn
|
||||||
|
|
||||||
|
@pytest_twisted.inlineCallbacks
|
||||||
|
def add_dummy_requests(self, num):
|
||||||
|
now_str = datetime.now().strftime("%Y%m%d")
|
||||||
|
for i in (0, num):
|
||||||
|
yield self.conn.new_request(
|
||||||
|
id='testid',
|
||||||
|
command='links',
|
||||||
|
platform='linux',
|
||||||
|
language='en',
|
||||||
|
service='email',
|
||||||
|
date=now_str,
|
||||||
|
status="ONHOLD",
|
||||||
|
)
|
||||||
|
|
||||||
@pytest_twisted.inlineCallbacks
|
@pytest_twisted.inlineCallbacks
|
||||||
def test_stored_locales(self):
|
def test_stored_locales(self):
|
||||||
locales = yield self.conn.get_locales()
|
locales = []
|
||||||
|
ls = yield self.conn.get_locales()
|
||||||
|
for l in ls:
|
||||||
|
locales.append(l[0])
|
||||||
|
self.assertIn('en-US', locales)
|
||||||
|
|
||||||
|
@pytest_twisted.inlineCallbacks
|
||||||
|
def test_requests(self):
|
||||||
|
now_str = datetime.now().strftime("%Y%m%d")
|
||||||
|
yield self.add_dummy_requests(2)
|
||||||
|
num = yield self.conn.get_num_requests("testid", "email")
|
||||||
|
self.assertEqual(num[0][0], 2)
|
||||||
|
|
||||||
|
requests = yield self.conn.get_requests("ONHOLD", "links", "email")
|
||||||
|
for request in requests:
|
||||||
|
self.assertEqual(request[1], "links")
|
||||||
|
self.assertEqual(request[4], "email")
|
||||||
|
self.assertEqual(request[5], now_str)
|
||||||
|
self.assertEqual(request[6], "ONHOLD")
|
||||||
|
self.assertEqual(len(requests), 2)
|
||||||
|
|
||||||
|
yield self.conn.remove_request("testid", "email", now_str)
|
||||||
|
num = yield self.conn.get_num_requests("testid", "email")
|
||||||
|
self.assertEqual(num[0][0], 0)
|
||||||
|
|
||||||
|
@pytest_twisted.inlineCallbacks
|
||||||
|
def test_links(self):
|
||||||
|
links = yield self.conn.get_links("linux", "en-US", "ACTIVE")
|
||||||
|
|
||||||
|
for link in links:
|
||||||
|
self.assertEqual(link[1], "linux")
|
||||||
|
self.assertEqual(link[2], "en-US")
|
||||||
|
self.assertEqual(link[6], "ACTIVE")
|
||||||
|
self.assertIn(link[5], ["github", "gitlab"])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user