<commit_before>#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# <NAME> <<EMAIL>>
#
from django.contrib.auth.models import User
from django.core.management import call_command
from django.conf import settings
from django.test import TestCase
from common.utils import BaseAuthenticatedClient
from cdr.models import Switch, HangupCause
from cdr.forms import CdrSearchForm, CountryReportForm,\
    CdrOverviewForm, CompareCallSearchForm,\
    ConcurrentCallForm, SwitchForm,\
    WorldForm, EmailReportForm
from cdr.tasks import sync_cdr_pending, get_channels_info
from cdr.views import cdr_view, cdr_dashboard, cdr_overview,\
    cdr_report_by_hour, cdr_concurrent_calls,\
    cdr_realtime, cdr_country_report, mail_report,\
    world_map_view, index, cdr_detail, cdr_export_to_csv
from cdr.functions_def import get_switch_list, get_hangupcause_name,\
    get_hangupcause_id, get_hc_list, get_country_id
from cdr.templatetags.cdr_tags import hangupcause_name_with_title, mongo_id
from bson.objectid import ObjectId
from datetime import datetime

csv_file = open(
    settings.APPLICATION_DIR + '/cdr/fixtures/import_cdr.txt', 'r'
)


class CdrAdminInterfaceTestCase(BaseAuthenticatedClient):
    """Test cases for Cdr-Stats Admin Interface."""

    fixtures = ['auth_user.json', 'switch.json']

    def test_admin_switch_list(self):
        """Test Function to check admin switch list"""
        response = self.client.get('/admin/cdr/switch/')
        self.failUnlessEqual(response.status_code, 200)

        response = self.client.get('/admin/cdr/switch/cdr_view/')
        self.failUnlessEqual(response.status_code, 200)

    def test_admin_switch_add(self):
        """Test Function to check admin switch add"""
        response = self.client.get('/admin/cdr/switch/add/')
        self.failUnlessEqual(response.status_code, 200)

        response = self.client.post(
            '/admin/cdr/switch/add/',
            data={
                "name": "localhost",
                "ipaddress": "127.0.0.1",
            },
            follow=True)
        self.assertEqual(response.status_code, 200)

    def test_admin_switch_import_cdr(self):
        """Test Function to check admin cdr import"""
        response = self.client.post('/admin/cdr/switch/import_cdr/',
                {'switch': 1,
                 'csv_file': csv_file,
                 'accountcode_csv': '12345',
                 'caller_id_number': 1,
                 'destination_number': 3,
                 'duration': 4,
                 'billsec': 5,
                 'hangup_cause_id': 6,
                 'uuid': 8,
                 'start_uepoch': 10})
        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'admin/cdr/switch/import_cdr.html')

    def test_admin_hangupcause_list(self):
        """Test Function to check admin hangupcause list"""
        response = self.client.get('/admin/cdr/hangupcause/')
        self.failUnlessEqual(response.status_code, 200)

    def test_admin_hangupcause_add(self):
        """Test Function to check admin hangupcause add"""
        response = self.client.get('/admin/cdr/hangupcause/add/')
        self.failUnlessEqual(response.status_code, 200)

        response = self.client.post(
            '/admin/cdr/hangupcause/add/',
            data={
                "code": "1",
                "enumeration": "UNALLOCATED_NUMBER",
            })
        self.assertEqual(response.status_code, 302)


class CdrStatsCustomerInterfaceTestCase(BaseAuthenticatedClient):
    """Test cases for Cdr-Stats Customer Interface."""

    fixtures = ['auth_user.json', 'switch.json', 'country_dialcode.json', 'hangup_cause.json',
                'voip_gateway.json', 'voip_provider.json'
                'voip_billing.json', 'user_profile.json',]

    def test_mgt_command(self):
        # Test mgt command
        call_command('generate_cdr',
            '--number-cdr=10', '--delta-day=1', '--duration=10')
        call_command('generate_cdr',
            '--number-cdr=10', '--delta-day=0', '--duration=0')
        call_command('generate_cdr', '--number-cdr=10', '--delta-day=0')
        call_command('generate_cdr', '--number-cdr=10')
        call_command('sync_cdr_freeswitch', '--apply-index')
        call_command('sync_cdr_freeswitch')
        #call_command('sync_cdr_asterisk', '--apply-index')
        #call_command('sync_cdr_asterisk')
<commit_msg>Update tests.py<commit_after>#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# <NAME> <<EMAIL>>
#
from django.contrib.auth.models import User
from django.core.management import call_command
from django.conf import settings
from django.test import TestCase
from common.utils import BaseAuthenticatedClient
from cdr.models import Switch, HangupCause
from cdr.forms import CdrSearchForm, CountryReportForm,\
    CdrOverviewForm, CompareCallSearchForm,\
    ConcurrentCallForm, SwitchForm,\
    WorldForm, EmailReportForm
from cdr.tasks import sync_cdr_pending, get_channels_info
from cdr.views import cdr_view, cdr_dashboard, cdr_overview,\
    cdr_report_by_hour, cdr_concurrent_calls,\
    cdr_realtime, cdr_country_report, mail_report,\
    world_map_view, index, cdr_detail, cdr_export_to_csv
from cdr.functions_def import get_switch_list, get_hangupcause_name,\
    get_hangupcause_id, get_hc_list, get_country_id
from cdr.templatetags.cdr_tags import hangupcause_name_with_title, mongo_id
from bson.objectid import ObjectId
from datetime import datetime

csv_file = open(
    settings.APPLICATION_DIR + '/cdr/fixtures/import_cdr.txt', 'r'
)


class CdrAdminInterfaceTestCase(BaseAuthenticatedClient):
    """Test cases for Cdr-Stats Admin Interface."""

    fixtures = ['auth_user.json', 'switch.json']

    def test_admin_switch_list(self):
        """Test Function to check admin switch list"""
        response = self.client.get('/admin/cdr/switch/')
        self.failUnlessEqual(response.status_code, 200)

        response = self.client.get('/admin/cdr/switch/cdr_view/')
        self.failUnlessEqual(response.status_code, 200)

    def test_admin_switch_add(self):
        """Test Function to check admin switch add"""
        response = self.client.get('/admin/cdr/switch/add/')
        self.failUnlessEqual(response.status_code, 200)

        response = self.client.post(
            '/admin/cdr/switch/add/',
            data={
                "name": "localhost",
                "ipaddress": "127.0.0.1",
            },
            follow=True)
        self.assertEqual(response.status_code, 200)

    def test_admin_switch_import_cdr(self):
        """Test Function to check admin cdr import"""
        response = self.client.post('/admin/cdr/switch/import_cdr/',
                {'switch': 1,
                 'csv_file': csv_file,
                 'accountcode_csv': '12345',
                 'caller_id_number': 1,
                 'destination_number': 3,
                 'duration': 4,
                 'billsec': 5,
                 'hangup_cause_id': 6,
                 'uuid': 8,
                 'start_uepoch': 10})
        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'admin/cdr/switch/import_cdr.html')

    def test_admin_hangupcause_list(self):
        """Test Function to check admin hangupcause list"""
        response = self.client.get('/admin/cdr/hangupcause/')
        self.failUnlessEqual(response.status_code, 200)

    def test_admin_hangupcause_add(self):
        """Test Function to check admin hangupcause add"""
        response = self.client.get('/admin/cdr/hangupcause/add/')
        self.failUnlessEqual(response.status_code, 200)

        response = self.client.post(
            '/admin/cdr/hangupcause/add/',
            data={
                "code": "1",
                "enumeration": "UNALLOCATED_NUMBER",
            })
        self.assertEqual(response.status_code, 302)


class CdrStatsCustomerInterfaceTestCase(BaseAuthenticatedClient):
    """Test cases for Cdr-Stats Customer Interface."""

    fixtures = ['auth_user.json', 'switch.json', 'country_dialcode.json', 'hangup_cause.json',
                'voip_gateway.json', 'voip_provider.json'
                'voip_billing.json', 'user_profile.json',]

    #def test_mgt_command(self):
    #    # Test mgt command
    #    call_command('generate_cdr',
    #        '--number-cdr=10', '--delta-day=1', '--duration=10')
    #    call_command('generate_cdr',
    #        '--number-cdr=10', '--delta-day=0', '--duration=0')
    #    call_command('generate_cdr', '--number-cdr=10', '--delta-day=0')
    #    call_command('generate_cdr', '--number-cdr=10')
    #    call_command('sync_cdr_freeswitch', '--apply-index')
    #    call_command('sync_cdr_freeswitch')
    #    #call_command('sync_cdr_asterisk', '--apply-index')
    #    #call_command('sync_cdr_asterisk')

{'fraction_non_alphanumeric': 0.11935754776401428, 'fraction_numerical': 0.015746378332983414, 'mean_word_length': 2.9029086439983613, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4082519', 'n_tokens_mistral': 3141, 'n_tokens_neox': 2936, 'n_words': 603}