<commit_before>from django.test import client, TestCase

from members.models import User
from datetime import time
from .models import Report
from protocols.models import Topic, Institution, Protocol


client = client.Client()


class ReportTest(TestCase):
    def setUp(self):
        self.kril = User.objects.create(
            username='Kril',
            faculty_number='61277',
            email='<EMAIL>',)
        self.kril.set_password('<PASSWORD>')
        self.kril.save()

        self.institution = Institution.objects.create(
            name='some institution name')

        self.protocol = Protocol.objects.create(
            institution=self.institution,
            number='2341',
            scheduled_time=time(9, 0, 0),
            start_time=time(10, 0, 0),
            quorum=32,
            majority=5,
            current_majority=4,
            information="best protocol ever",
            )

        self.topic1 = Topic.objects.create(
            name='1',
            description='first',
            voted_for=13,
            voted_against=4,
            voted_abstain=5,
            protocol=self.protocol)
        self.topic2 = Topic.objects.create(
            name='2',
            description='second',
            voted_for=13,
            voted_against=4,
            voted_abstain=5,
            protocol=self.protocol)
        self.topic3 = Topic.objects.create(
            name='3',
            description='third',
            voted_for=13,
            voted_against=4,
            voted_abstain=5,
            protocol=self.protocol)

    def test_add_report(self):
        client.login(username='Kril', password='<PASSWORD>')
        response = client.post('/reports/add/', {
            "addressed_to": "Hackfmi",
            "reported_from": self.kril.pk,
            "content": "This is a report test",
            "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
            "signed_from": "rozovo zaiche", })

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(Report.objects.all()))<commit_msg>Add invlid post data test and tests for users archive<commit_after>from django.test import client, TestCase

from members.models import User
from datetime import time
from .models import Report
from protocols.models import Topic, Institution, Protocol


client = client.Client()


class ReportTest(TestCase):
    def setUp(self):
        self.kril = User.objects.create(
            username='Kril',
            faculty_number='61277',
            email='<EMAIL>',)
        self.kril.set_password('<PASSWORD>')
        self.kril.save()

        self.institution = Institution.objects.create(
            name='some institution name')

        self.protocol = Protocol.objects.create(
            institution=self.institution,
            number='2341',
            scheduled_time=time(9, 0, 0),
            start_time=time(10, 0, 0),
            quorum=32,
            majority=5,
            current_majority=4,
            information="best protocol ever",
            )

        self.topic1 = Topic.objects.create(
            name='1',
            description='first',
            voted_for=13,
            voted_against=4,
            voted_abstain=5,
            protocol=self.protocol)
        self.topic2 = Topic.objects.create(
            name='2',
            description='second',
            voted_for=13,
            voted_against=4,
            voted_abstain=5,
            protocol=self.protocol)
        self.topic3 = Topic.objects.create(
            name='3',
            description='third',
            voted_for=13,
            voted_against=4,
            voted_abstain=5,
            protocol=self.protocol)

    def test_add_report(self):
        client.login(username='Kril', password='<PASSWORD>')
        response = client.post('/reports/add/', {
            "addressed_to": "Hackfmi",
            "reported_from": self.kril.pk,
            "content": "This is a report test",
            "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
            "signed_from": "rozovo zaiche", })

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(Report.objects.all()))

    def test_add_report_with_incomplete_data(self):
        client.login(username='Kril', password='<PASSWORD>')
        response = client.post('/reports/add/', {
            "addressed_to": "Hackfmi",
            "reported_from": self.kril.pk,
            "content": "This is a report test",
            "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
            })

        self.assertEqual(200, response.status_code)
        self.assertEqual(0, len(Report.objects.all()))

    def test_user_reports_count_1(self):
        client.login(username='Kril', password='<PASSWORD>')
        response = client.post('/reports/add/', {
            "addressed_to": "Hackfmi",
            "reported_from": self.kril.pk,
            "content": "This is a report test",
            "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
            "signed_from": "rozovo zaiche", })

        self.assertEqual(200, response.status_code)
        self.assertEqual(1, len(User.objects.get().report_set.all()))

    def test_user_reports_count_2(self):
        client.login(username='Kril', password='<PASSWORD>')
        response = client.post('/reports/add/', {
            "addressed_to": "Hackfmi",
            "reported_from": self.kril.pk,
            "content": "This is a report test",
            "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
            "signed_from": "rozovo zaiche", })

        self.assertEqual(200, response.status_code)

        response = client.post('/reports/add/', {
            "addressed_to": "Hackfmi",
            "reported_from": self.kril.pk,
            "content": "This is a report test",
            "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
            "signed_from": "rozovo zaiche", })

        self.assertEqual(200, response.status_code)
        self.assertEqual(2, len(User.objects.get().report_set.all()))

    def test_user_is_spamer(self):
        client.login(username='Kril', password='<PASSWORD>')
        for report in range(10):
            response = client.post('/reports/add/', {
                "addressed_to": "Hackfmi",
                "reported_from": self.kril.pk,
                "content": "This is a report test",
                "copies": [self.topic1.pk, self.topic2.pk, self.topic3.pk],
                "signed_from": "rozovo zaiche", })
            self.assertEqual(200, response.status_code)

        self.assertEqual(10, len(User.objects.get().report_set.all()))
{'fraction_non_alphanumeric': 0.12964899178491412, 'fraction_numerical': 0.019268110530246452, 'mean_word_length': 2.072969251950436, 'pattern_counts': {'":': 34, '<': 13, '<?xml version=': 0, '>': 13, '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': '1254230', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1961, 'n_words': 354}