<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.test import TestCase
from django.contrib.auth.models import User
from .models import ImagerProfile
import factory


# Create your tests here.
class UserTest(TestCase):
    def setUp(self):
        user1 = User()
        user1.username = 'badass'
        user1.email = factory.LazyAttribute(
            lambda a: <EMAIL>'.<EMAIL>(a.username).lower()
        )
        user1.set_password('<PASSWORD>')

        user1.save()

    # Test 1
    # Check that User works as we expect as base class
    def test_create_user(self):
        new = User.objects.all()[0]
        expected = [
            'badass',
            '<EMAIL>'
        ]
        actual = [
            new.username,
            new.email
        ]
        self.assertEqual(actual, expected)
        self.assertIsInstance(new.profile, ImagerProfile)

    # Test 2
    # Check that an imagerProfile is created when user is created
    def test_create_imagerprofile(self):
        new = ImagerProfile.objects.all()[0]
        self.assertEqual(new.user.username, 'badass')

    # Test 3
    # Check that camera field can optionally hold data
    def test_camera_field(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.camera, None)
        new.camera = 'potato'
        self.assertEqual(new.camera, 'potato')

    # Test 4
    # Check that address field can optionally hold data
    def test_address_field(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.address, None)
        new.address = '123 Fake St'
        self.assertEqual(new.address, '123 Fake St')

    # Test 5
    # Check that web_url field can optionally hold data
    def test_web_url(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.web_url, None)
        new.web_url = 'example.com'
        self.assertEqual(new.web_url, 'example.<EMAIL>')

    # Test 6
    # Check that type_photography field can optionally hold data
    def test_type_photography(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.type_photography, None)
        new.web_url = 'astrophotography'
        self.assertEqual(new.web_url, 'astrophotography')

    # Test 7
    # Check that is_active property works as expected
    def test_is_active(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.user.is_active, True)
        self.assertIs(new.is_active, True)

    # Test 8
    # Check that is_active can be changed
    def test_is_not_active(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.is_active, True)
        new.user.is_active = False
        self.assertIs(new.is_active, False)

    # Test 8
    # Check that ActiveProfileManager works
    def test_active(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(len(ImagerProfile.active.get_queryset()), 1)
        new.user.is_active = False
        self.assertEqual(ImagerProfile.active.get_queryset(), [])

    # Test 9
    # Check that if user is killed, imagerProfile is killed
    def test_no_imagerprofile(self):
        new = User.objects.all()[0]
        self.assertIs(len(ImagerProfile.objects.all()), 1)
        new.delete()
        self.assertEqual(ImagerProfile.objects.all(), [])

    # Test 10
    # Check that if imagerProfile is killed, user is killed
    def test_no_user(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(len(User.objects.all()), 1)
        new.delete()
        self.assertEqual(User.objects.all(), [])<commit_msg>Pass all tests<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.test import TestCase
from django.contrib.auth.models import User
from .models import ImagerProfile
import factory


class UserFactory(factory.Factory):
    class Meta:
        model = User

    username = 'badass'
    email = factory.LazyAttribute(
        lambda a: <EMAIL>(<EMAIL>).lower()
    )


# Create your tests here.
class UserTest(TestCase):
    def setUp(self):
        user1 = UserFactory()
        user1.set_password('<PASSWORD>')
        user1.save()

    # Test 1
    # Check that User works as we expect as base class
    def test_create_user(self):
        new = User.objects.all()[0]
        expected = [
            'badass',
            '<EMAIL>'
        ]
        actual = [
            new.username,
            new.email
        ]
        self.assertEqual(actual, expected)
        self.assertIsInstance(new.profile, ImagerProfile)

    # Test 2
    # Check that an imagerProfile is created when user is created
    def test_create_imagerprofile(self):
        new = ImagerProfile.objects.all()[0]
        self.assertEqual(new.user.username, 'badass')

    # Test 3
    # Check that camera field can optionally hold data
    def test_camera_field(self):
        new = ImagerProfile.objects.all()[0]
        self.assertFalse(new.camera)
        new.camera = 'potato'
        self.assertEqual(new.camera, 'potato')

    # Test 4
    # Check that address field can optionally hold data
    def test_address_field(self):
        new = ImagerProfile.objects.all()[0]
        self.assertFalse(new.address)
        new.address = '123 Fake St'
        self.assertEqual(new.address, '123 Fake St')

    # Test 5
    # Check that web_url field can optionally hold data
    def test_web_url_field(self):
        new = ImagerProfile.objects.all()[0]
        self.assertFalse(new.web_url)
        new.web_url = 'example.com'
        self.assertEqual(new.web_url, 'example.com')

    # Test 6
    # Check that type_photography field can optionally hold data
    def test_type_photography_field(self):
        new = ImagerProfile.objects.all()[0]
        self.assertFalse(new.type_photography)
        new.web_url = 'astrophotography'
        self.assertEqual(new.web_url, 'astrophotography')

    # Test 7
    # Check that is_active property works as expected
    def test_is_active(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.user.is_active, True)
        self.assertIs(new.is_active, True)

    # Test 8
    # Check that is_active can be changed
    def test_is_not_active(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(new.is_active, True)
        new.user.is_active = False
        self.assertIs(new.is_active, False)

    # Test 9
    # Check that ActiveProfileManager works
    def test_active(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(len(ImagerProfile.active.all()), 1)
        new.user.is_active = False
        new.user.save()
        self.assertFalse(ImagerProfile.active.all())

    # Test 10
    # Check that if user is killed, imagerProfile is killed
    def test_no_imagerprofile(self):
        new = User.objects.all()[0]
        self.assertIs(len(ImagerProfile.objects.all()), 1)
        new.delete()
        self.assertFalse(ImagerProfile.objects.all())

    # Test 11
    # Check that if imagerProfile is killed, user is killed
    def test_no_user(self):
        new = ImagerProfile.objects.all()[0]
        self.assertIs(len(User.objects.all()), 1)
        new.delete()
        self.assertFalse(User.objects.all())
{'fraction_non_alphanumeric': 0.10756861657887441, 'fraction_numerical': 0.010396451344607708, 'mean_word_length': 2.500727802037846, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '2628446', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2163, 'n_words': 511}