Skip to content

Commit

Permalink
Merge pull request #47 from cisagov/improvement/update-mongo-tests
Browse files Browse the repository at this point in the history
Update mongo tests
  • Loading branch information
king-alexander authored Aug 21, 2023
2 parents 3cfcde5 + 194fb7f commit cf69dc0
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 30 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
include:
- os: ubuntu-20.04
python-version: "3.6"
steps:
- uses: actions/checkout@v3
- id: setup-python
Expand Down Expand Up @@ -215,9 +212,6 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
include:
- os: ubuntu-20.04
python-version: "3.6"
steps:
- uses: actions/checkout@v3
- id: setup-python
Expand Down Expand Up @@ -268,9 +262,6 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
include:
- os: ubuntu-20.04
python-version: "3.6"
steps:
- uses: actions/checkout@v3
- id: setup-python
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Note: Add any additional requirements to setup.py's install_requires field
--editable .
docker-compose
wheel
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ def get_version(version_file):
# that you indicate whether you support Python 2, Python 3 or both.
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
],
python_requires=">=3.6",
python_requires=">=3.7",
# What does your project relate to?
keywords="celery certificate-transparency cisa-directives",
packages=find_packages(where="src"),
Expand All @@ -96,11 +95,9 @@ def get_version(version_file):
"defusedxml",
"dnspython",
"docopt",
# MongoEngine 0.27.0 introduces a breaking change to the mongomock
# connection method. See #50 for more details.
"mongoengine >= 0.16.3,<0.27.0",
"mongoengine >= 0.27.0",
"python-dateutil >= 2.7.5",
"PyYAML >=4.2b1",
"PyYAML >= 6.0.0",
"redis >= 3.2.0",
"requests <2.21,>=2.6.1",
"schedule >= 0.4.2",
Expand Down
2 changes: 1 addition & 1 deletion src/admiral/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""This file defines the version of this module."""
__version__ = "1.3.3"
__version__ = "1.4.0"
5 changes: 3 additions & 2 deletions src/admiral/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Third-Party Libraries
from mongoengine import connect
import pymongo
import yaml


Expand All @@ -13,10 +14,10 @@ def load_config(filename="/run/secrets/config.yml"):
return config


def connect_from_config(config=None):
def connect_from_config(config=None, client=pymongo.MongoClient):
"""Create connections from a confguration."""
if not config:
config = load_config()
connections = config["connections"]
for alias in connections.keys():
connect(host=connections[alias]["uri"], alias=alias)
connect(host=connections[alias]["uri"], mongo_client_class=client, alias=alias)
12 changes: 5 additions & 7 deletions tests/cert_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Third-Party Libraries
import dateutil.tz as tz
import mongoengine
from mongoengine import connect
from mongomock import MongoClient
import pytest

# cisagov Libraries
Expand Down Expand Up @@ -48,11 +50,7 @@
@pytest.fixture(scope="class", autouse=True)
def connection():
"""Create connections for tests to use."""
# Third-Party Libraries
from mongoengine import connect

# TODO: Update this connection method. See #50 for more details.
connect(host="mongomock://localhost", alias="default")
connect(host="mongodb://localhost", mongo_client_class=MongoClient, alias="default")


class TestCerts:
Expand All @@ -68,8 +66,8 @@ def test_empty_creation(self):
def test_subjects(self):
"""Validate that subjects and trimmed_subjects are calulcated correctly."""
cert = Cert()
cert.subjects = ["cisa.gov", "cyber.dhs.gov"]
assert set(cert.trimmed_subjects) == {"cisa.gov", "dhs.gov"}
cert.subjects = ["cisa.gov", "cyber.dhs.gov", "cisa.dhs.fed.us"]
assert set(cert.trimmed_subjects) == {"cisa.gov", "dhs.gov", "dhs.fed.us"}

def test_simple_creation(self):
"""Create a new user, and save it."""
Expand Down
4 changes: 2 additions & 2 deletions tests/data/valid_config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
connections:
local:
uri: mongomock://local-user:example@mongo:27017/local
uri: mongodb://local-user:example@mongo:27017/local
production:
uri: mongomock://production-user:example@mongo:27017/production
uri: mongodb://production-user:example@mongo:27017/production
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test the functionality of the util sub-module."""

# Third-Party Libraries
import mongomock
import pytest

# cisagov Libraries
Expand Down Expand Up @@ -32,5 +33,4 @@ def test_load_config_valid():

def test_connect_from_config_valid(valid_config):
"""Test that a valid configuration connects to appropriate connections."""
# TODO: Update this connection method. See #50 for more details.
util.connect_from_config(valid_config)
util.connect_from_config(valid_config, mongomock.MongoClient)

0 comments on commit cf69dc0

Please sign in to comment.