<commit_before>import json
from unittest import mock

from django.test import TestCase, override_settings
from django.urls import reverse

from promgen import models
from promgen.tests import TEST_ALERT, TEST_IMPORT, TEST_SETTINGS


class RouteTests(TestCase):
    longMessage = True

    @override_settings(PROMGEN=TEST_SETTINGS)
    def test_alert(self):
        response = self.client.post(reverse('alert'), data=json.dumps(TEST_ALERT), content_type='application/json')
        self.assertEqual(response.status_code, 200)

    @mock.patch('promgen.signals._write_config')
    def test_import(self, mock_reload):
        response = self.client.post(reverse('import'), {
            'config': json.dumps(TEST_IMPORT)
        })
        self.assertEqual(response.status_code, 302)
        self.assertEqual(models.Service.objects.count(), 1, 'Import one service')
        self.assertEqual(models.Project.objects.count(), 2, 'Import two projects')
        self.assertEqual(models.Exporter.objects.count(), 2, 'Import two exporters')
        self.assertEqual(models.Host.objects.count(), 3, 'Import three hosts')
<commit_msg>Simple tests for a few more routes.<commit_after>import json
from unittest import mock

from django.test import TestCase, override_settings
from django.urls import reverse

from promgen import models
from promgen.tests import TEST_ALERT, TEST_IMPORT, TEST_SETTINGS


class RouteTests(TestCase):
    longMessage = True

    @override_settings(PROMGEN=TEST_SETTINGS)
    def test_alert(self):
        response = self.client.post(reverse('alert'), data=json.dumps(TEST_ALERT), content_type='application/json')
        self.assertEqual(response.status_code, 200)

    @mock.patch('promgen.signals._write_config')
    def test_import(self, mock_reload):
        response = self.client.post(reverse('import'), {
            'config': json.dumps(TEST_IMPORT)
        })
        self.assertEqual(response.status_code, 302)
        self.assertEqual(models.Service.objects.count(), 1, 'Import one service')
        self.assertEqual(models.Project.objects.count(), 2, 'Import two projects')
        self.assertEqual(models.Exporter.objects.count(), 2, 'Import two exporters')
        self.assertEqual(models.Host.objects.count(), 3, 'Import three hosts')

    def test_service(self):
        response = self.client.get(reverse('service-list'))
        self.assertEqual(response.status_code, 200)

    def test_project(self):
        service = models.Service.objects.create(name='Service Test')
        project = models.Project.objects.create(name='Project Test', service=service)

        response = self.client.get(reverse('project-detail', kwargs={'pk': project.pk}))
        self.assertEqual(response.status_code, 200)

    def test_farms(self):
        response = self.client.get(reverse('farm-list'))
        self.assertEqual(response.status_code, 200)

    def test_hosts(self):
        response = self.client.get(reverse('host-list'))
        self.assertEqual(response.status_code, 200)

{'fraction_non_alphanumeric': 0.11813643926788686, 'fraction_numerical': 0.01064891846921797, 'mean_word_length': 3.952224052718287, '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': '6317093', 'n_tokens_mistral': 883, 'n_tokens_neox': 846, 'n_words': 175}