GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still and

Commit 64df8b27 authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Expand tests for database functions in gettor

parent c413a8eb
......@@ -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/
#!/usr/bin/env python3
import pytest
import pytest_twisted
from datetime import datetime
from twisted.trial import unittest
from . import conftests
......@@ -10,7 +11,7 @@ class DatabaseTests(unittest.TestCase):
# Fail any tests which take longer than 15 seconds.
timeout = 15
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.conn = conftests.SQLite3(self.settings.get("dbname"))
......@@ -19,9 +20,56 @@ class DatabaseTests(unittest.TestCase):
del self.conn
def add_dummy_requests(self, num):
now_str ="%Y%m%d")
for i in (0, num):
yield self.conn.new_request(
def test_stored_locales(self):
locales = yield self.conn.get_locales()
locales = []
ls = yield self.conn.get_locales()
for l in ls:
self.assertIn('en-US', locales)
def test_requests(self):
now_str ="%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)
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__":
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment