-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dockerfile + limited sample for #13
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |