<commit_before>#!/usr/bin/python
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".

Replace these with more appropriate tests for your application.
"""

import sys
import os
_base = os.path.dirname(__file__)
site_root = os.path.realpath(os.path.join(_base, '../'))
from django.core.urlresolvers import reverse
sys.path.append(site_root)
import manage
from django.test import TestCase
from django.test.client import Client
from models import KeyValue, System
from core.range.models import Range
from mozdns.domain.models import Domain
from core.network.models import Network
from mozdns.view.models import View
from core.vlan.models import Vlan
from core.site.models import Site
try:
    import json
except:
    from django.utils import simplejson as json

from inventory.systems import models
from test_utils import setup_test_environment, TestCase
setup_test_environment()


class SystemDatagridTest(TestCase):
    fixtures = ['testdata.json']

    def setUp(self):
        self.client = Client()

    def test_index(self):
        resp = self.client.get("/en-US/systems/list_all_systems_ajax/?_=1326311056872&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=10&sSearch=&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=false", follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj),2)
        self.assertEqual(obj[0][0], '2,fake-hostname1')

    def test_blanket_search(self):
        resp = self.client.get("/en-US/systems/list_all_systems_ajax/?_=1326311056872&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=10&sSearch=fake-hostname&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=false", follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj),2)
        self.assertEqual(obj[0][0], '2,fake-hostname1')

    def test_specific_search(self):
        resp = self.client.get("/en-US/systems/list_all_systems_ajax/?_=1326317772224&sEcho=4&iColumns=8&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&mDataProp_5=5&mDataProp_6=6&mDataProp_7=7&sSearch=fake-hostname2&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch_7=&bRegex_7=false&bSearchable_7=true&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=false", follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj),1)
        self.assertEqual(obj[0][0], '1,fake-hostname2')

    def test_failed_search(self):
        resp = self.client.get(
            "/en-US/systems/list_all_systems_ajax/?_=1326317772224&sEcho=4&iColumns=8&sColumns=&iDisplayStart=0&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4&mDataProp_5=5&mDataProp_6=6&mDataProp_7=7&sSearch=asdfasdfasdf&bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true&sSearch_1=&bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false&bSearchable_2=true&sSearch_3=&bRegex_3=false&bSearchable_3=true&sSearch_4=&bRegex_4=false&bSearchable_4=true&sSearch_5=&bRegex_5=false&bSearchable_5=true&sSearch_6=&bRegex_6=false&bSearchable_6=true&sSearch_7=&bRegex_7=false&bSearchable_7=true&iSortingCols=1&iSortCol_0=0&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=true&bSortable_4=true&bSortable_5=true&bSortable_6=true&bSortable_7=false", follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj), 0)


class BlankTest(TestCase):
    fixtures = ['testdata.json']

    def setUp(self):
        self.client = Client()

    def test_get_adapter_names(self):
        system = System.objects.get(id=1)
        self.assertEqual(len(system.get_nic_names()), 2)

    def test_adapter_name_exists(self):
        system = System.objects.get(id=1)
        self.assertEqual(system.check_for_adapter_name('nic1'), True)
        self.assertEqual(system.check_for_adapter_name('nic0'), True)
        self.assertEqual(system.check_for_adapter_name('nic2'), False)

    def test_next_adapter_number(self):
        system = System.objects.get(id=1)
        self.assertEqual(system.get_next_adapter_number(), 2)<commit_msg>Final pep8 fixes for systems/tests.py<commit_after>#!/usr/bin/python
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".

Replace these with more appropriate tests for your application.
"""

import sys
import os
_base = os.path.dirname(__file__)
site_root = os.path.realpath(os.path.join(_base, '../'))
from django.core.urlresolvers import reverse
sys.path.append(site_root)
import manage
from django.test import TestCase
from django.test.client import Client
from models import KeyValue, System
from core.range.models import Range
from mozdns.domain.models import Domain
from core.network.models import Network
from mozdns.view.models import View
from core.vlan.models import Vlan
from core.site.models import Site
try:
    import json
except:
    from django.utils import simplejson as json

from inventory.systems import models
from test_utils import setup_test_environment, TestCase
setup_test_environment()


class SystemDatagridTest(TestCase):
    fixtures = ['testdata.json']

    def setUp(self):
        self.client = Client()

    def test_index(self):
        resp = self.client.get(
            "/en-US/systems/list_all_systems_ajax/?_=1326311056 \
            872&sEcho=1&iColumns=3&sColumns=&iDisplayStart=0 \
            &iDisplayLength=10&sSearch=&bRegex=false \
            &sSearch_0=&bRegex_0=false&bSearchable_0=true \
            &sSearch_1=&bRegex_1=false&bSearchable_1=true \
            &sSearch_2=&bRegex_2=false&bSearchable_2=true \
            &iSortingCols=1&iSortCol_0=0&sSortDir_0=asc \
            &bSortable_0=true&bSortable_1=true&bSortable_2=false",
            follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj), 2)
        self.assertEqual(obj[0][0], '2,fake-hostname1')

    def test_blanket_search(self):
        resp = self.client.get("/en-US/systems/list_all_systems_ajax/ \
                ?_=1326311056872&sEcho=1&iColumns=3&sColumns= \
                &iDisplayStart=0&iDisplayLength=10 &sSearch=fake-hostname \
                &bRegex=false&sSearch_0=&bRegex_0=false&bSearchable_0=true \
                &sSearch_1=&bRegex_1=false&bSearchable_1=true \
                &sSearch_2=&bRegex_2=false&bSearchable_2=true&iSortingCols=1 \
                &iSortCol_0=0&sSortDir_0=asc&bSortable_0=true \
                &bSortable_1=true&bSortable_2=false", follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj), 2)
        self.assertEqual(obj[0][0], '2,fake-hostname1')

    def test_specific_search(self):
        resp = self.client.get("/en-US/systems/list_all_systems_ajax/ \
            ?_=1326317772224&sEcho=4&iColumns=8&sColumns= \
            &iDisplayStart=0&iDisplayLength=10&mDataProp_0=0 \
            &mDataProp_1=1&mDataProp_2=2&mDataProp_3=3&mDataProp_4=4 \
            &mDataProp_5=5&mDataProp_6=6&mDataProp_7=7 \
            &sSearch=fake-hostname2&bRegex=false&sSearch_0= \
            &bRegex_0=false&bSearchable_0=true&sSearch_1= \
            &bRegex_1=false&bSearchable_1=true&sSearch_2=&bRegex_2=false \
            &bSearchable_2=true&sSearch_3=&bRegex_3=false \
            &bSearchable_3=true&sSearch_4=&bRegex_4=false \
            &bSearchable_4=true&sSearch_5=&bRegex_5=false \
            &bSearchable_5=true&sSearch_6=&bRegex_6=false \
            &bSearchable_6=true&sSearch_7=&bRegex_7=false \
            &bSearchable_7=true&iSortingCols=1&iSortCol_0=0 \
            &sSortDir_0=asc&bSortable_0=true&bSortable_1=true \
            &bSortable_2=true&bSortable_3=true&bSortable_4=true \
            &bSortable_5=true&bSortable_6=true&bSortable_7=false", follow=True)

        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj), 1)
        self.assertEqual(obj[0][0], '1,fake-hostname2')

    def test_failed_search(self):
        resp = self.client.get(
            "/en-US/systems/list_all_systems_ajax/?_=1326317772224&sEcho=4 \
                    &iColumns=8&sColumns=&iDisplayStart=0&iDisplayLength=10 \
                    &mDataProp_0=0&mDataProp_1=1&mDataProp_2=2&mDataProp_3=3 \
                    &mDataProp_4=4&mDataProp_5=5&mDataProp_6=6&mDataProp_7=7 \
                    &sSearch=asdfasdfasdf&bRegex=false&sSearch_0= \
                    &bRegex_0=false&bSearchable_0=true&sSearch_1= \
                    &bRegex_1=false&bSearchable_1=true&sSearch_2= \
                    &bRegex_2=false&bSearchable_2=true&sSearch_3=& \
                    bRegex_3=false&bSearchable_3=true&sSearch_4= \
                    &bRegex_4=false&bSearchable_4=true&sSearch_5= \
                    &bRegex_5=false&bSearchable_5=true&sSearch_6= \
                    &bRegex_6=false&bSearchable_6=true&sSearch_7= \
                    &bRegex_7=false&bSearchable_7=true&iSortingCols=1 \
                    &iSortCol_0=0&sSortDir_0=asc&bSortable_0=true \
                    &bSortable_1=true&bSortable_2=true&bSortable_3=true \
                    &bSortable_4=true&bSortable_5=true&bSortable_6=true \
                    &bSortable_7=false", follow=True)
        self.assertEqual(resp.status_code, 200)
        obj = json.loads(resp.content)
        obj = obj['aaData']
        self.assertEqual(len(obj), 0)


class BlankTest(TestCase):
    fixtures = ['testdata.json']

    def setUp(self):
        self.client = Client()

    def test_get_adapter_names(self):
        system = System.objects.get(id=1)
        self.assertEqual(len(system.get_nic_names()), 2)

    def test_adapter_name_exists(self):
        system = System.objects.get(id=1)
        self.assertEqual(system.check_for_adapter_name('nic1'), True)
        self.assertEqual(system.check_for_adapter_name('nic0'), True)
        self.assertEqual(system.check_for_adapter_name('nic2'), False)

    def test_next_adapter_number(self):
        system = System.objects.get(id=1)
        self.assertEqual(system.get_next_adapter_number(), 2)
{'fraction_non_alphanumeric': 0.11953097654882744, 'fraction_numerical': 0.04296464823241162, 'mean_word_length': 4.1045109423849935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1306754', 'n_tokens_mistral': 4288, 'n_tokens_neox': 4085, 'n_words': 450}