...
 
Commits (2)
......@@ -16,7 +16,10 @@ test:
- 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 exec collector pip install pytest-cov
- docker exec collector pytest --cov-report term --cov=collector ../test/unit_tests.py
- docker exec collector pytest --cov-report term --cov=./ ../test/unit_tests.py
- docker exec collector rm -r __pycache__
- docker exec collector rm .coverage
- docker exec collector rm -r ../test/__pycache__
build:
only:
......
import yaml, requests, os, json, ast, time, argparse
import requests, ast, time, argparse
import schedule
from collections import defaultdict
from apiclient.discovery import build
......@@ -6,30 +6,7 @@ from datetime import datetime, timedelta
from oauth2client.service_account import ServiceAccountCredentials
from abc import ABC, abstractmethod
from influxdb import InfluxDBClient
class ConfigFactory(object):
def __init__(self, file):
with open(file, 'r') as stream:
try:
d = yaml.safe_load(stream)
self.ga_metrics = d["google_analytics_metrics"]
self.ga_dimensions = d["google_analytics_dimensions"]
except yaml.YAMLError as exc:
raise exc
# TODO: find a way to do this without volumes (env variables would be great)
KEY_FILE_LOCATION = '/ga_key_file.json'
self.ga_key_conf = json.loads(open(KEY_FILE_LOCATION).read())
try:
self.ga_view_id = os.environ['GA_VIEW_ID']
self.db_host = os.environ['DB_HOST']
self.db_port = os.environ['DB_PORT']
self.db_user = os.environ['INFLUXDB_USER']
self.db_password = os.environ['INFLUXDB_USER_PASSWORD']
self.db_name = os.environ['INFLUXDB_DB']
except KeyError as e:
print("Missing ENV VARIABLE: {}".format(e))
raise e
from utils import ConfigFactory
class GA_Batch(object):
"""Google analytics data batch"""
......
import yaml, json, os
class ConfigFactory(object):
def __init__(self, file):
with open(file, 'r') as stream:
try:
d = yaml.safe_load(stream)
self.ga_metrics = d["google_analytics_metrics"]
self.ga_dimensions = d["google_analytics_dimensions"]
except yaml.YAMLError as exc:
raise exc
# TODO: find a way to do this without volumes (env variables would be great)
KEY_FILE_LOCATION = '/ga_key_file.json'
self.ga_key_conf = json.loads(open(KEY_FILE_LOCATION).read())
try:
self.ga_view_id = os.environ['GA_VIEW_ID']
self.db_host = os.environ['DB_HOST']
self.db_port = os.environ['DB_PORT']
self.db_user = os.environ['INFLUXDB_USER']
self.db_password = os.environ['INFLUXDB_USER_PASSWORD']
self.db_name = os.environ['INFLUXDB_DB']
except KeyError as e:
print("Missing ENV VARIABLE: {}".format(e))
raise e
\ No newline at end of file
......@@ -5,6 +5,7 @@ from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
from unittest.mock import patch, Mock, MagicMock
from collector import *
from utils import *
'''UNIT TESTING'''
class TestConfigFactory:
......