forked from neilalbrock/pw-database-url
/
test_pw_database_url.py
75 lines (58 loc) · 2.92 KB
/
test_pw_database_url.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# coding: utf-8
import os
import unittest
from unittest import mock
import pw_database_url
class DatabaseTestSuite(unittest.TestCase):
def test_truth(self):
assert True
def test_postgres_parsing(self):
url = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
url = pw_database_url.parse(url)
assert url['engine'] == 'peewee.PostgresqlDatabase'
assert url['name'] == 'd8r82722r2kuvn'
assert url['host'] == 'ec2-107-21-253-135.compute-1.amazonaws.com'
assert url['user'] == 'uf07k1i6d8ia0v'
assert url['password'] == 'wegauwhgeuioweg'
assert url['port'] == 5431
def test_postgresext_parsing(self):
url = 'postgresext://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
url = pw_database_url.parse(url)
assert url['engine'] == 'playhouse.postgres_ext.PostgresqlExtDatabase'
assert url['name'] == 'd8r82722r2kuvn'
assert url['host'] == 'ec2-107-21-253-135.compute-1.amazonaws.com'
assert url['user'] == 'uf07k1i6d8ia0v'
assert url['password'] == 'wegauwhgeuioweg'
assert url['port'] == 5431
def test_cleardb_parsing(self):
url = 'mysql://bea6eb025ca0d8:69772142@us-cdbr-east.cleardb.com/heroku_97681db3eff7580?reconnect=true'
url = pw_database_url.parse(url)
assert url['engine'] == 'peewee.MySQLDatabase'
assert url['name'] == 'heroku_97681db3eff7580'
assert url['host'] == 'us-cdbr-east.cleardb.com'
assert url['user'] == 'bea6eb025ca0d8'
assert url['password'] == '69772142'
assert url['port'] is None
def test_database_url(self):
a = pw_database_url.config()
assert not a
os.environ['DATABASE_URL'] = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
url = pw_database_url.config()
assert url['engine'] == 'peewee.PostgresqlDatabase'
assert url['name'] == 'd8r82722r2kuvn'
assert url['host'] == 'ec2-107-21-253-135.compute-1.amazonaws.com'
assert url['user'] == 'uf07k1i6d8ia0v'
assert url['password'] == 'wegauwhgeuioweg'
assert url['port'] == 5431
@mock.patch('pw_database_url.PeeweePostgresqlDatabase')
def test_instantiate_peewee_postgres_object(self, mocked):
url = 'postgres://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
pw_database_url.PostgresqlDatabase(url)
mocked.assert_called_with('d8r82722r2kuvn',
user='uf07k1i6d8ia0v',
password='wegauwhgeuioweg',
host='ec2-107-21-253-135.compute-1.amazonaws.com',
port=5431,
)
if __name__ == '__main__':
unittest.main()