<commit_before>from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase

from .models import ClientSite
from servers.models import Server


class ClientSiteTest(TestCase):
    def test_create_new_clientsite(self):
        clientsite = ClientSite()
        clientsite.name = 'Atlas'
        clientsite.domain = 'www.atlasperformancechicago.com'

        self.assertFalse(clientsite.id)
        clientsite.save()
        self.assertTrue(clientsite.id)

        clientsite = ClientSite.objects.get(id=clientsite.id)
        self.assertEqual(clientsite.name, 'Atlas')
        self.assertEqual(clientsite.domain, 'www.atlasperformancechicago.com')


class ClientSiteViewTest(TestCase):
    def setUp(self):
        self.url = reverse('clientsites')

    def test_clientsite_should_be_accessible(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

    def test_clientsite_should_use_correct_template(self):
        response = self.client.get(self.url)
        self.assertTemplateUsed(response, 'clientsites.html')

    def test_clientsite_should_have_title(self):
        response = self.client.get(self.url)

        expected = '<title>Still with Us?</title>'
        self.assertContains(response, expected, status_code=200)

    def test_clientsite_should_render_html_for_clientsites_correctly(self):
        response = self.client.get(self.url)

        expected = '<h1>Client Sites</h1>'
        self.assertContains(response, expected, status_code=200)

        expected = '<thead><tr><th>Domain</th><th>Still with Us?'
        expected += '</th><th>Note</th></tr></thead>'
        self.assertContains(response, expected, status_code=200)

    def test_clientsite_should_query_domains_and_check_if_still_with_us(self):
        Server.objects.create(
            name='AWS ELB',
            ip='172.16.31.10'
        )
        Server.objects.create(
            name='Bypronto',
            ip='172.16.58.3'
        )
        Server.objects.create(
            name='Pronto Server',
            ip='192.168.127.12'
        )

        ClientSite.objects.create(
            name='Pronto',
            domain='www.prontomarketing.com'
        )
        ClientSite.objects.create(
            name='Atlas',<commit_msg>Add another server to fix test (in case IP changes)<commit_after>from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase

from .models import ClientSite
from servers.models import Server


class ClientSiteTest(TestCase):
    def test_create_new_clientsite(self):
        clientsite = ClientSite()
        clientsite.name = 'Atlas'
        clientsite.domain = 'www.atlasperformancechicago.com'

        self.assertFalse(clientsite.id)
        clientsite.save()
        self.assertTrue(clientsite.id)

        clientsite = ClientSite.objects.get(id=clientsite.id)
        self.assertEqual(clientsite.name, 'Atlas')
        self.assertEqual(clientsite.domain, 'www.atlasperformancechicago.com')


class ClientSiteViewTest(TestCase):
    def setUp(self):
        self.url = reverse('clientsites')

    def test_clientsite_should_be_accessible(self):
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

    def test_clientsite_should_use_correct_template(self):
        response = self.client.get(self.url)
        self.assertTemplateUsed(response, 'clientsites.html')

    def test_clientsite_should_have_title(self):
        response = self.client.get(self.url)

        expected = '<title>Still with Us?</title>'
        self.assertContains(response, expected, status_code=200)

    def test_clientsite_should_render_html_for_clientsites_correctly(self):
        response = self.client.get(self.url)

        expected = '<h1>Client Sites</h1>'
        self.assertContains(response, expected, status_code=200)

        expected = '<thead><tr><th>Domain</th><th>Still with Us?'
        expected += '</th><th>Note</th></tr></thead>'
        self.assertContains(response, expected, status_code=200)

    def test_clientsite_should_query_domains_and_check_if_still_with_us(self):
        Server.objects.create(
            name='AWS ELB',
            ip='172.16.31.10'
        )
        Server.objects.create(
            name='Bypronto',
            ip='172.16.58.3'
        )
        Server.objects.create(
            name='Pronto Server 1',
            ip='192.168.127.12'
        )
        Server.objects.create(
            name='Pronto Server 2',
            ip='172.16.31.10'
        )

        ClientSite.objects.create(
            name='Pronto',
            domain='www.prontomarketing.com'
        )
        ClientSite.objects.create(
            name='Atlas',
{'fraction_non_alphanumeric': 0.11025587684626587, 'fraction_numerical': 0.019762845849802372, 'mean_word_length': 2.7917981072555205, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 7, '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': '7536133', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1435, 'n_words': 224}