Skip to content

Commit

Permalink
Added Dockerfile + limited sample for #13
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvinus committed Jan 22, 2016
1 parent f2506eb commit 9f0fca6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM debian:jessie

# Add extra repositories
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list

RUN apt-get update
RUN apt-get install -y sudo mongodb-org-server gcc make g++ build-essential python-pip python-dev

# Put Python pip requirements files
ADD requirements.txt /tmp/requirements.txt
ADD requirements-tests.txt /tmp/requirements-tests.txt

RUN pip install -r /tmp/requirements.txt
RUN pip install -r /tmp/requirements-tests.txt

RUN mkdir -p /data/db
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ test_cext:
python setup.py build_ext && cp build/lib.macosx-10.10-intel-2.7/mongokat/_cbson.so mongokat/ && py.test tests -sv

pypi:
python setup.py sdist upload -r pypi
python setup.py sdist upload -r pypi

docker_build:
docker build -t pricingassistant/mongokat .

docker_ssh:
docker run -v `pwd`:/app:rw -w /app -t -i pricingassistant/mongokat bash

start_mongod:
mongod --smallfiles --noprealloc --nojournal &

docker_test: docker_build
docker run -v `pwd`:/app:rw -w /app -t -i pricingassistant/mongokat sh -c 'make start_mongod && py.test tests/ -v'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Tests

You can just do `make test` to run the tests after setting up your environment (`make virtualenv` might help)

Alternatively, you can use `make docker_test` to run tests inside a Docker image, without worrying about installing MongoDB on your machine.

Contributing
============

Expand Down
57 changes: 57 additions & 0 deletions tests/test_shortnames.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from mongokat import Document, Collection


class ShortNamesDocument(Document):
""" This Document subclass supports limited alias names, as suggested in https://github.com/pricingassistant/mongokat/issues/13
Note that they don't work in queries, field name lists, or dict(doc). Further subclassing would be necessary
for that to work. Pull Requests welcome, though we won't include that in MongoKat itself.
"""

short_names = {
"description": "d",
"value": "v"
}

def __getitem__(self, key):
if key in self.short_names:
return self.get(self.short_names[key])
return self.get(key)

def __setitem__(self, key, value):
if key in self.short_names:
key = self.short_names[key]
dict.__setitem__(self, key, value)


class ShortNamesCollection(Collection):
document_class = ShortNamesDocument


def test_shortnames(db):
db.test_shortnames.drop()
SN = ShortNamesCollection(collection=db.test_shortnames)

doc = SN({"regular": "1"})
doc.save()

docs = list(SN.find())
print docs
assert len(docs) == 1
assert docs[0]["regular"] == "1"

docs[0]["value"] = "2"
docs[0].save()

docs = list(SN.find())
print docs
print dict(docs[0])
assert len(docs) == 1
assert docs[0]["value"] == "2"
assert docs[0]["v"] == "2"

# Bypass mongokat to see the real document
raw_docs = list(db.test_shortnames.find())
assert len(raw_docs) == 1
assert "value" not in raw_docs[0]
assert raw_docs[0]["v"] == "2"

0 comments on commit 9f0fca6

Please sign in to comment.