...
 
Commits (2)
.secrets
.env
\ No newline at end of file
.env
src/__pycache__
src/.coverage
test/__pycache__
\ No newline at end of file
......@@ -6,6 +6,10 @@ services:
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- apk update
- apk upgrade
- apk add python python-dev py-pip build-base libffi-dev openssl-dev
- pip install docker-compose
stages:
- test
......@@ -13,8 +17,7 @@ stages:
test:
script:
- docker build -t col_img ./src
- docker run -d -it -p 1312:1312 -e "DB_HOST=db" -e "DB_PORT=8086" -e "GA_VIEW_ID=983581608" -e "INFLUXDB_DB=some_name" -e "INFLUXDB_USER=some_user" -e "INFLUXDB_USER_PASSWORD=db_user_password" -v `pwd`/test:/usr/src/test -v `pwd`/test/ga_fake_key.json:/ga_key_file.json --name=collector col_img
- docker-compose -f docker-compose.test.yml up -d
- docker exec collector pip install pytest-cov
- docker exec collector pytest --cov-report term --cov=./ ../test/unit_tests.py
- docker exec collector rm -r __pycache__
......
......@@ -8,7 +8,7 @@ from collector import *
from utils import *
'''UNIT TESTING'''
class TestConfigFactory:
class TestConfigFactory(unittest.TestCase):
def test_instantiation(self):
config = ConfigFactory("config.yml")
assert hasattr(config,"db_host")
......@@ -26,6 +26,12 @@ class TestConfigFactory:
assert type(config.db_port) == str
assert type(config.ga_key_conf) == dict
@patch.dict(os.environ,{'DB_HOST':'some host'} , clear=True)
def test_missing_env_variable_raises_exception(self):
with self.assertRaises(Exception) as context:
config = ConfigFactory("config.yml")
class Test_GA_Batch:
"""test EXTRACT"""
......@@ -67,3 +73,9 @@ class TestDataFormater:
points = DataFormater.ga2influx(batch)
assert sum([view["fields"]["ga:sessions"] for view in points]) == int(total_session)
class TestDbConnector:
def test_data_base_connectivity(self):
config = ConfigFactory("../test/config/config.yml")
db_client = DbClient(config)