★ wanayoo — archive 1999 https://github.com/segmentio/analytics-python/pull/106/filesNouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement E2E testing in TravisCI #106

Merged
merged 13 commits into from May 29, 2018
@@ -7,6 +7,8 @@ python:
- "3.5"
install:
- "pip install ."
script: make test
script:
- make test
- make e2e_test
matrix:
fast_finish: true
@@ -5,4 +5,16 @@ test:
dist:
python setup.py sdist bdist_wheel upload

.PHONY: test dist
e2e_test:
if [ "$(RUN_E2E_TESTS)" != "true" ]; then \
echo "Skipping end to end tests."; \
else \
echo "Running end to end tests..."; \
wget https://github.com/segmentio/library-e2e-tester/releases/download/0.1.1/tester_linux_amd64; \
chmod +x tester_linux_amd64; \
chmod +x e2e_test.sh; \
./tester_linux_amd64 -segment-write-key="$SEGMENT_WRITE_KEY" -runscope-token="$RUNSCOPE_TOKEN" -runscope-bucket="$RUNSCOPE_BUCKET" -path='./e2e_test.sh'; \
echo "End to end tests completed!"; \
fi

.PHONY: test dist e2e_test
@@ -0,0 +1,5 @@
#!/bin/sh

set -e

python ./simulator.py "$@"
Submodule library-e2e-tester added at 5e1768
@@ -0,0 +1,84 @@
import analytics
import argparse
import json
import logging

__name__ = 'simulator.py'
__version__ = '0.0.1'
__description__ = 'scripting simulator'

def json_hash(str):
if str:
return json.loads(str)

# analytics -method=<method> -segment-write-key=<segmentWriteKey> [options]

parser = argparse.ArgumentParser(description='send a segment message')

parser.add_argument('--writeKey', help='the Segment writeKey')
parser.add_argument('--type', help='The Segment message type')

parser.add_argument('--userId', help='the user id to send the event as')
parser.add_argument('--anonymousId', help='the anonymous user id to send the event as')
parser.add_argument('--context', help='additional context for the event (JSON-encoded)')

parser.add_argument('--event', help='the event name to send with the event')
parser.add_argument('--properties', help='the event properties to send (JSON-encoded)')

parser.add_argument('--name', help='name of the screen or page to send with the message')

parser.add_argument('--traits', help='the identify/group traits to send (JSON-encoded)')

parser.add_argument('--groupId', help='the group id')

options = parser.parse_args()

def failed(status, msg):
raise Exception(msg)

def track():
analytics.track(options.userId, options.event, anonymous_id = options.anonymousId,
properties = json_hash(options.properties), context = json_hash(options.context))

def page():
analytics.page(options.userId, name = options.name, anonymous_id = options.anonymousId,
properties = json_hash(options.properties), context = json_hash(options.context))

def screen():
analytics.screen(options.userId, name = options.name, anonymous_id = options.anonymousId,
properties = json_hash(options.properties), context = json_hash(options.context))

def identify():
analytics.identify(options.userId, anonymous_id = options.anonymousId,
traits = json_hash(options.traits), context = json_hash(options.context))

def group():
analytics.group(options.userId, options.groupId, json_hash(options.traits),
json_hash(options.context), anonymous_id = options.anonymousId)

def unknown():
print()

analytics.write_key = options.writeKey
analytics.on_error = failed
analytics.debug = True

log = logging.getLogger('segment')
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)

switcher = {
"track": track,
"page": page,
"screen": screen,
"identify": identify,
"group": group
}

func = switcher.get(options.type)
if func:
func()
analytics.flush()
else:
print("Invalid Message Type " + options.type)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.