Skip to content

Commit 09afa80

Browse files
committed
Initial commit
0 parents  commit 09afa80

7 files changed

Lines changed: 155 additions & 0 deletions

File tree

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.idea/
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
env/
13+
bin/
14+
build/
15+
develop-eggs/
16+
dist/
17+
eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# Installer logs
28+
pip-log.txt
29+
pip-delete-this-directory.txt
30+
31+
# Unit test / coverage reports
32+
htmlcov/
33+
.tox/
34+
.coverage
35+
.cache
36+
nosetests.xml
37+
coverage.xml
38+
39+
# Translations
40+
*.mo
41+
42+
# Mr Developer
43+
.mr.developer.cfg
44+
.project
45+
.pydevproject
46+
47+
# Rope
48+
.ropeproject
49+
50+
# Django stuff:
51+
*.log
52+
*.pot
53+
54+
# Sphinx documentation
55+
docs/_build/
56+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Tim
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Python PostgreSQL Sample [![Build Status](https://apibeta.shippable.com/projects/537a42ba326b4d0f004a332c/badge/master)](https://beta.shippable.com/projects/537a42ba326b4d0f004a332c)
2+
======================
3+
4+
Tests basic SQL commands using the psycopg2 driver for Python.

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
psycopg2
2+
nose
3+
coverage

shippable.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: python
2+
3+
python:
4+
- 2.7
5+
6+
install:
7+
- pip install -r requirements.txt
8+
9+
# Postgres binds to 127.0.0.1 by default and is started on boot. Default username is "postgres" with no password
10+
# Create a DB as part of before script to use it
11+
12+
before_script:
13+
- psql -c 'create database test;' -U postgres
14+
- mkdir -p shippable/testresults
15+
- mkdir -p shippable/codecoverage
16+
17+
script:
18+
- nosetests test.py --with-xunit --xunit-file=shippable/testresults/nosetests.xml
19+
- which python && coverage run --branch test.py
20+
- which python && coverage xml -o shippable/codecoverage/coverage.xml test.py

sql.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import psycopg2 as pg
2+
3+
4+
class Postgres():
5+
def __init__(self):
6+
self.conn_string = "host='127.0.0.1' dbname='test' user='postgres' password=''"
7+
self.conn = pg.connect(self.conn_string)
8+
self.cursor = self.conn.cursor()
9+
10+
def populate(self):
11+
self.cursor.execute("DROP TABLE IF EXISTS things;")
12+
self.cursor.execute("CREATE TABLE things (name varchar(20));")
13+
self.cursor.execute("INSERT INTO things(name) VALUES('Dre');")
14+
self.cursor.execute("INSERT INTO things(name) VALUES('Smalls');")
15+
self.cursor.execute("INSERT INTO things(name) VALUES('West');")
16+
self.cursor.execute("INSERT INTO things(name) VALUES('Combs');")
17+
self.cursor.execute("INSERT INTO things(name) VALUES('Flame');")
18+
19+
def read(self):
20+
self.cursor.execute("SELECT * FROM things;")
21+
count = self.cursor.fetchall()
22+
return len(count)
23+
24+
def disconnect(self):
25+
if self.conn:
26+
self.conn.close()
27+
28+
if __name__ == '__main__':
29+
postgres = Postgres()
30+
postgres.populate()
31+
postgres.read()
32+
postgres.disconnect()

test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
from sql import Postgres
3+
4+
5+
class Test(unittest.TestCase):
6+
7+
def test_db(self):
8+
pg = Postgres()
9+
pg.populate()
10+
count = pg.read()
11+
self.failIf(count != 5)
12+
pg.disconnect()
13+
14+
15+
def main():
16+
unittest.main()
17+
18+
if __name__ == '__main__':
19+
main()

0 commit comments

Comments
 (0)