# Path: accounts/models.py
# class Account(AbstractUser):
#     """
#     This is our custom 'User' model.
#     """
# 
#     is_developer = models.BooleanField(default=False, blank=False)
#     accepted_tos = models.BooleanField(default=False, blank=False)
#     #  Add more custom fields here like avatar...
# 
#     def send_activation_email(self):
#         tvars = {
#             'user': self,
#             'username': self.username,
#             'hash': create_hash(self.id)
#         }
#         send_mail(self.email, subject='Activate your Audio Commons user account',
#                   template='emails/account_activation.txt', context=tvars)
# 
#     class Meta:
#         verbose_name = _('account')
#         verbose_name_plural = _('accounts')
# 
# Path: services/mgmt.py
# def get_service_by_name(service_name):
#     for service in available_services:
#         if service.name == service_name:
#             return service
#     raise ACServiceDoesNotExist('Service with name {0} does not exist'.format(service_name))


from django.core.management.base import BaseCommand
from django.template.loader import render_to_string
from accounts.models import Account
from services.acservice.constants import *
from ac_mediator.exceptions import *
from services.mgmt import get_service_by_name
import configparser
import os
import logging
import json

    def handle(self, *args, **options):
        """
        Iterate over all implemented components by the given service and test them. Output an HTML report
        with the results. Loads configuration parameters for the tests (e.g. query terms) from a file called
        `test_services.cfg` that should be placed in the same directory.
        """

        service_name = options['service_name']
        service = get_service_by_name(service_name)
        logger.info('Testing service {0} with id {1}'.format(service.name, service.id))

        test_config = configparser.ConfigParser()
        test_config_filename = options.get('test_config_filename')
        if test_config_filename is None:
            test_config_filename = 'services/test_services.cfg'
        test_config_path = os.path.join(test_config_filename)
        test_config.read(test_config_path)
        try:
            test_config = test_config[service.name]
        except KeyError:
            logger.info('No test configuration data found for service {0} in file {1}. '
                        'Aborting...'.format(service.name, test_config_path))
            return

        context = {  # Should return equivalent to api.views.get_request_context
            'user_account_id': None,
        }
        if options.get('account_username'):
            try:

# Path: accounts/models.py
# class Account(AbstractUser):
#     """
#     This is our custom 'User' model.
#     """
# 
#     is_developer = models.BooleanField(default=False, blank=False)
#     accepted_tos = models.BooleanField(default=False, blank=False)
#     #  Add more custom fields here like avatar...
# 
#     def send_activation_email(self):
#         tvars = {
#             'user': self,
#             'username': self.username,
#             'hash': create_hash(self.id)
#         }
#         send_mail(self.email, subject='Activate your Audio Commons user account',
#                   template='emails/account_activation.txt', context=tvars)
# 
#     class Meta:
#         verbose_name = _('account')
#         verbose_name_plural = _('accounts')
# 
# Path: services/mgmt.py
# def get_service_by_name(service_name):
#     for service in available_services:
#         if service.name == service_name:
#             return service
#     raise ACServiceDoesNotExist('Service with name {0} does not exist'.format(service_name))


# Path: services/management/commands/test_service.py
from django.core.management.base import BaseCommand
from django.template.loader import render_to_string
from accounts.models import Account
from services.acservice.constants import *
from ac_mediator.exceptions import *
from services.mgmt import get_service_by_name
import configparser
import os
import logging
import json


    def handle(self, *args, **options):
        """
        Iterate over all implemented components by the given service and test them. Output an HTML report
        with the results. Loads configuration parameters for the tests (e.g. query terms) from a file called
        `test_services.cfg` that should be placed in the same directory.
        """

        service_name = options['service_name']
        service = get_service_by_name(service_name)
        logger.info('Testing service {0} with id {1}'.format(service.name, service.id))

        test_config = configparser.ConfigParser()
        test_config_filename = options.get('test_config_filename')
        if test_config_filename is None:
            test_config_filename = 'services/test_services.cfg'
        test_config_path = os.path.join(test_config_filename)
        test_config.read(test_config_path)
        try:
            test_config = test_config[service.name]
        except KeyError:
            logger.info('No test configuration data found for service {0} in file {1}. '
                        'Aborting...'.format(service.name, test_config_path))
            return

        context = {  # Should return equivalent to api.views.get_request_context
            'user_account_id': None,
        }
        if options.get('account_username'):
            try:

                account = Account.objects.get(username=options.get('account_username'))