Skip to content

Commit

Permalink
Merge pull request #26 from vishaltanwar96/feature/start-indexing-red…
Browse files Browse the repository at this point in the history
…eem-code-in-a-gc

create unique index for redeem code as it should be unique
  • Loading branch information
vishaltanwar96 authored Nov 4, 2022
2 parents d78bfef + f03f532 commit cd086d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion gcmanager/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from urllib.parse import quote

from kink import Container
from pymongo import ASCENDING
from pymongo import MongoClient
from pymongo.collection import Collection
from pymongo.database import Database
Expand Down Expand Up @@ -61,7 +62,9 @@ def _build_mongodb_database(container: Container) -> None:
def _build_mongodb_collection(container: Container) -> None:
database = container[Database]
settings = container[Settings]
container[Collection] = lambda c: database[settings["MONGODB_GC_COLLECTION_NAME"]]
collection = database[settings["MONGODB_GC_COLLECTION_NAME"]]
collection.create_index([("redeem_code", ASCENDING)], unique=True)
container[Collection] = lambda c: collection


def _build_mongodb_repository(container: Container) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_raises_exception_when_required_env_variables_absent(self) -> None:

def test_returns_container_when_required_env_variables_present(self) -> None:
when(os.environ).get("APP_ENV").thenReturn("PROD")
when(os.environ).get("MONGODB_USERNAME").thenReturn("someuser")
when(os.environ).get("MONGODB_PASSWORD").thenReturn("somepassword")
when(os.environ).get("MONGODB_HOST").thenReturn("somehost")
when(os.environ).get("MONGODB_PORT", "27017").thenReturn("27017")
when(os.environ).get("MONGODB_DBNAME", "gcmanager").thenReturn("somedb")
when(os.environ).get("MONGODB_USERNAME").thenReturn("testing_user")
when(os.environ).get("MONGODB_PASSWORD").thenReturn("testing")
when(os.environ).get("MONGODB_HOST").thenReturn("localhost")
when(os.environ).get("MONGODB_PORT", "27017").thenReturn("27020")
when(os.environ).get("MONGODB_DBNAME", "gcmanager").thenReturn("testdb")
when(os.environ).get("MONGODB_GC_COLLECTION_NAME", "giftcards").thenReturn(
"somecollection",
"testcollection",
)
self.assertIsInstance(build_dependency_container(), Container)

0 comments on commit cd086d6

Please sign in to comment.