зеркало из https://github.com/mozilla/subhub.git
Initial test coverage
This commit is contained in:
Родитель
5fd718e327
Коммит
ac0daf5b96
|
@ -0,0 +1,30 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import signal
|
||||
import subprocess
|
||||
import uuid
|
||||
import logging
|
||||
import json
|
||||
import psutil
|
||||
import pytest
|
||||
import stripe
|
||||
|
||||
from unittest.mock import Mock, MagicMock, PropertyMock
|
||||
|
||||
from sub.shared.cfg import CFG
|
||||
from shared.log import get_logger
|
||||
from shared.dynamodb import dynamodb
|
||||
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
THIS_PATH = os.path.join(os.path.realpath(os.path.dirname(__file__)))
|
||||
|
||||
|
||||
def pytest_configure():
|
||||
os.environ["AWS_ACCESS_KEY_ID"] = "fake"
|
||||
os.environ["AWS_SECRET_ACCESS_KEY"] = "fake"
|
|
@ -0,0 +1,122 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
import random
|
||||
import string
|
||||
|
||||
from shared.db import (
|
||||
HubEvent,
|
||||
SubHubDeletedAccount,
|
||||
SubHubAccount,
|
||||
_create_account_model,
|
||||
_create_deleted_account_model,
|
||||
_create_hub_model,
|
||||
)
|
||||
|
||||
from shared.dynamodb import dynamodb
|
||||
from past.builtins import xrange
|
||||
|
||||
####################
|
||||
# SubHubAccountModel
|
||||
# SubHubAccount
|
||||
####################
|
||||
|
||||
|
||||
def generate_random_table():
|
||||
return "".join(
|
||||
[random.choice(string.ascii_letters + string.digits) for n in xrange(32)]
|
||||
)
|
||||
|
||||
|
||||
def test_create_account_model(dynamodb):
|
||||
model = _create_account_model(generate_random_table(), "local", dynamodb)
|
||||
assert model is not None
|
||||
|
||||
|
||||
def test_new_user_account_model(dynamodb):
|
||||
subhub_account = SubHubAccount(generate_random_table(), "local", dynamodb)
|
||||
customer_model = subhub_account.new_user(
|
||||
"uid", "origin_system", "customer_identifier"
|
||||
)
|
||||
assert customer_model is not None
|
||||
|
||||
######################################################
|
||||
# TODO(med): These tests rely on the container
|
||||
# being clean which isn't guaranteed right not. These
|
||||
# merely serve as a placeholder for future tests that
|
||||
# need to be written.
|
||||
######################################################
|
||||
|
||||
# def test_get_user_account_model(dynamodb):
|
||||
# subhub_account = SubHubAccount(generate_random_table(), "local", dynamodb)
|
||||
# customer_model = subhub_account.new_user(
|
||||
# "uid", "origin_system", "customer_identifier"
|
||||
# )
|
||||
# user_model = subhub_account.get_user("uid")
|
||||
# assert user_model is not None
|
||||
|
||||
|
||||
# def test_append_customer_id_account_model(dynamodb):
|
||||
# subhub_account = SubHubAccount(generate_random_table(), "local", dynamodb)
|
||||
# customer_model = subhub_account.new_user(
|
||||
# "uid", "origin_system", "customer_identifier"
|
||||
# )
|
||||
# user_model = subhub_account.append_custid("uid", "customer_identifier2")
|
||||
# assert subhub_account.get_user("uid").cust_id == "customer_identifier2"
|
||||
|
||||
|
||||
# def test_remove_from_db_account_model(dynamodb):
|
||||
# subhub_account = SubHubAccount(generate_random_table(), "local", dynamodb)
|
||||
# customer_model = subhub_account.new_user(
|
||||
# "uid", "origin_system", "customer_identifier"
|
||||
# )
|
||||
# user_model = subhub_account.append_custid("uid", "customer_identifier2")
|
||||
# subhub_account.remove_from_db("uid")
|
||||
# assert subhub_account.get_user("uid") is None
|
||||
|
||||
|
||||
# def test_mark_deleted_account_model(dynamodb):
|
||||
# subhub_account = SubHubAccount(generate_random_table(), "local", dynamodb)
|
||||
# customer_model = subhub_account.new_user(
|
||||
# "uid", "origin_system", "customer_identifier"
|
||||
# )
|
||||
# subhub_account.mark_deleted("uid")
|
||||
# user_model = subhub_account.get_user("uid")
|
||||
# assert subhub_account.customer_status == "deleted"
|
||||
|
||||
|
||||
####################
|
||||
# HubEventModel
|
||||
####################
|
||||
|
||||
|
||||
def test_create_create_hub_model(dynamodb):
|
||||
model = _create_hub_model(generate_random_table(), "local", dynamodb)
|
||||
assert model is not None
|
||||
|
||||
|
||||
def test_append_event_hub_event(dynamodb):
|
||||
pass
|
||||
|
||||
|
||||
def test_remove_from_db_hub_event(dynamodb):
|
||||
pass
|
||||
|
||||
|
||||
####################
|
||||
# SubHubDeletedAccountModel
|
||||
####################
|
||||
|
||||
|
||||
def test_create_deleted_account_model(dynamodb):
|
||||
model = _create_deleted_account_model(generate_random_table(), "local", dynamodb)
|
||||
assert model is not None
|
||||
|
||||
|
||||
def test_new_deleted_user_created(dynamodb):
|
||||
subhub_deleted_account_model = SubHubDeletedAccount(
|
||||
generate_random_table(), "local", dynamodb
|
||||
)
|
||||
user_model = subhub_deleted_account_model.new_user("uid", "origin_system", None)
|
||||
assert user_model is not None
|
|
@ -1,5 +1,6 @@
|
|||
backoff==1.8.0
|
||||
docker==4.1.0
|
||||
future==0.18.2
|
||||
jsoncompare==0.1.2
|
||||
locustio==0.11.0
|
||||
mock==3.0.5
|
||||
|
@ -16,4 +17,4 @@ pytest-cov==2.7.1
|
|||
pytest-mock==1.10.4
|
||||
pytest-watch==4.2.0
|
||||
requests==2.22.0
|
||||
responses==0.10.6
|
||||
responses==0.10.6
|
2
tox.ini
2
tox.ini
|
@ -49,4 +49,4 @@ commands =
|
|||
py.test --cov-config={toxinidir}/.coveragerc --cov-report term-missing --cov-append --cov-branch --no-cov-on-fail --cov=src/hub -k src/hub --ignore=src/hub/shared
|
||||
py.test --cov-config={toxinidir}/.coveragerc --cov-report term-missing --cov-append --cov-branch --no-cov-on-fail --cov=src/shared -k src/shared
|
||||
[pytest]
|
||||
norecursedirs = docs *.egg-info .git appdir .tox .venv env services
|
||||
norecursedirs = docs *.egg-info .git appdir .tox .venv env services *.eggs
|
||||
|
|
Загрузка…
Ссылка в новой задаче