# Path: commands.py
# class AddUser(Command):
#     """ Adds an user to the database """
# 
#     def __init__(self, app_context, app_bcrypt):
#         super(AddUser, self).__init__()
#         self.app_context = app_context
#         self.app_bcrypt = app_bcrypt
# 
#     def get_options(self):
#         return [
#             Option('--username', '-', dest='username', required=True),
#             Option('--password', '-p', dest='password', required=False),
#         ]
# 
#     def run(self, username, password=None):
#         with self.app_context():
#             if not password:
#                 wordfile = xp.locate_wordfile()
#                 mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8)
#                 password = xp.generate_xkcdpassword(mywords, acrostic="ambit")
#                 print("generated password: '%s'" % password)
# 
#             assert not User.query.filter_by(username=username).scalar(), "user already exists"
# 
#             user = User(username=username)
#             user.password = self.app_bcrypt.generate_password_hash(password, 10)
# 
#             if user.password is not str:
#                 user.password = user.password.decode('utf-8')
# 
#             user.active = True
#             db.session.add(user)
#             db.session.commit()
# 
#             print("created user '%s' in '%s'" % (user.username, db.engine.url))
# 
# Path: model.py
# class JsonEncodedDict(TypeDecorator):
# class Device(db.Model):
# class User(db.Model):
# class UserPreference(db.Model):
# class Move(db.Model):
# class Sample(db.Model):
# class MoveEdit(db.Model):
# class AlembicVersion(db.Model):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def is_authenticated(self):
#     def is_active(self):
#     def is_anonymous(self):
#     def has_strava(self):
#     def get_strava_access_token(self):
#     def get_id(self):
#     def __init__(self, key, value):


from datetime import timedelta, datetime
from flask import json
from commands import AddUser
from gpx_import import GPX_IMPORT_OPTION_PAUSE_DETECTION, GPX_IMPORT_OPTION_PAUSE_DETECTION_THRESHOLD, GPX_DEVICE_NAME, \
    GPX_ACTIVITY_TYPE, GPX_DEVICE_SERIAL, GPX_SAMPLE_TYPE, GPX_TRK, GPX_IMPORT_PAUSE_TYPE_PAUSE_DETECTION
from model import db, User, Move, MoveEdit
import html5lib
import os
import pytest
import re
import openmoves
    def test_dashboard_all_moves(self, tmpdir):
        self._login()
        response = self.client.get('/dashboard?start_date=2014-01-01&end_date=2014-12-31')
        response_data = self._validate_response(response, tmpdir)
        assert '<title>OpenMoves – Dashboard</title>' in response_data
        assert '>#Moves<' in response_data
        assert '>4<' in response_data
        assert '<th>Total Distance</th><td>33.55 km</td>' in response_data
        assert '<th>Total Duration</th><td>03:47:09.60</td>' in response_data
        assert '<th>Total Average</th>' in response_data
        assert '<th>Total Ascent</th><td>110 m</td>' in response_data
        assert '<th>Total Descent</th><td>218 m</td>' in response_data

    def test_dashboard_with_date_range(self, tmpdir):
        self._login()
        response = self.client.get('/dashboard?start_date=2014-08-01&end_date=2014-12-01')
        response_data = self._validate_response(response, tmpdir)
        assert '<title>OpenMoves – Dashboard</title>' in response_data
        assert '>#Moves<' in response_data
        assert '>2<' in response_data
        assert '<th>Total Distance</th><td>10.05 km</td>' in response_data
        assert '<th>Total Duration</th><td>02:20:23.30</td>' in response_data

    def test_edit_move_different_user(self):
        username = 'some different user'
        password = 'some other password'
        with app.test_request_context():
            user = User(username=username, active=True)
            user.password = openmoves.app_bcrypt.generate_password_hash(password, 10)
            db.session.add(user)

# Path: commands.py
# class AddUser(Command):
#     """ Adds an user to the database """
# 
#     def __init__(self, app_context, app_bcrypt):
#         super(AddUser, self).__init__()
#         self.app_context = app_context
#         self.app_bcrypt = app_bcrypt
# 
#     def get_options(self):
#         return [
#             Option('--username', '-', dest='username', required=True),
#             Option('--password', '-p', dest='password', required=False),
#         ]
# 
#     def run(self, username, password=None):
#         with self.app_context():
#             if not password:
#                 wordfile = xp.locate_wordfile()
#                 mywords = xp.generate_wordlist(wordfile=wordfile, min_length=5, max_length=8)
#                 password = xp.generate_xkcdpassword(mywords, acrostic="ambit")
#                 print("generated password: '%s'" % password)
# 
#             assert not User.query.filter_by(username=username).scalar(), "user already exists"
# 
#             user = User(username=username)
#             user.password = self.app_bcrypt.generate_password_hash(password, 10)
# 
#             if user.password is not str:
#                 user.password = user.password.decode('utf-8')
# 
#             user.active = True
#             db.session.add(user)
#             db.session.commit()
# 
#             print("created user '%s' in '%s'" % (user.username, db.engine.url))
# 
# Path: model.py
# class JsonEncodedDict(TypeDecorator):
# class Device(db.Model):
# class User(db.Model):
# class UserPreference(db.Model):
# class Move(db.Model):
# class Sample(db.Model):
# class MoveEdit(db.Model):
# class AlembicVersion(db.Model):
#     def process_bind_param(self, value, dialect):
#     def process_result_value(self, value, dialect):
#     def is_authenticated(self):
#     def is_active(self):
#     def is_anonymous(self):
#     def has_strava(self):
#     def get_strava_access_token(self):
#     def get_id(self):
#     def __init__(self, key, value):


# Path: tests/test_openmoves.py
from datetime import timedelta, datetime
from flask import json
from commands import AddUser
from gpx_import import GPX_IMPORT_OPTION_PAUSE_DETECTION, GPX_IMPORT_OPTION_PAUSE_DETECTION_THRESHOLD, GPX_DEVICE_NAME, \
    GPX_ACTIVITY_TYPE, GPX_DEVICE_SERIAL, GPX_SAMPLE_TYPE, GPX_TRK, GPX_IMPORT_PAUSE_TYPE_PAUSE_DETECTION
from model import db, User, Move, MoveEdit
import html5lib
import os
import pytest
import re
import openmoves

    def test_dashboard_all_moves(self, tmpdir):
        self._login()
        response = self.client.get('/dashboard?start_date=2014-01-01&end_date=2014-12-31')
        response_data = self._validate_response(response, tmpdir)
        assert '<title>OpenMoves – Dashboard</title>' in response_data
        assert '>#Moves<' in response_data
        assert '>4<' in response_data
        assert '<th>Total Distance</th><td>33.55 km</td>' in response_data
        assert '<th>Total Duration</th><td>03:47:09.60</td>' in response_data
        assert '<th>Total Average</th>' in response_data
        assert '<th>Total Ascent</th><td>110 m</td>' in response_data
        assert '<th>Total Descent</th><td>218 m</td>' in response_data

    def test_dashboard_with_date_range(self, tmpdir):
        self._login()
        response = self.client.get('/dashboard?start_date=2014-08-01&end_date=2014-12-01')
        response_data = self._validate_response(response, tmpdir)
        assert '<title>OpenMoves – Dashboard</title>' in response_data
        assert '>#Moves<' in response_data
        assert '>2<' in response_data
        assert '<th>Total Distance</th><td>10.05 km</td>' in response_data
        assert '<th>Total Duration</th><td>02:20:23.30</td>' in response_data

    def test_edit_move_different_user(self):
        username = 'some different user'
        password = 'some other password'
        with app.test_request_context():
            user = User(username=username, active=True)
            user.password = openmoves.app_bcrypt.generate_password_hash(password, 10)
            db.session.add(user)

            db.session.commit()