From a4b87aea53ccf606ba2acd4b290125fc58151b2b Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Wed, 17 Nov 2021 13:08:05 -0500 Subject: [PATCH 01/10] ensure the user field in categorizers table is one to one --- ponder/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ponder/models.py b/ponder/models.py index 2398aae..18fc3b4 100644 --- a/ponder/models.py +++ b/ponder/models.py @@ -62,7 +62,8 @@ def email_categorizer(self): class Categorizer(models.Model): name = models.CharField(unique=True, max_length=254) initials = models.CharField(unique=True, max_length=3) - user = models.CharField(max_length=254) + #user = models.CharField(max_length=254) + user = models.OneToOneField(User, on_delete=models.DO_NOTHING,) class Meta: db_table = 'categorizers' From 0e14284722154bf924de731d232f2aacc8cab768 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sat, 20 Nov 2021 22:41:57 -0500 Subject: [PATCH 02/10] referencing to the --- ponder/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ponder/models.py b/ponder/models.py index 18fc3b4..5b75cf3 100644 --- a/ponder/models.py +++ b/ponder/models.py @@ -63,7 +63,7 @@ class Categorizer(models.Model): name = models.CharField(unique=True, max_length=254) initials = models.CharField(unique=True, max_length=3) #user = models.CharField(max_length=254) - user = models.OneToOneField(User, on_delete=models.DO_NOTHING,) + user = models.OneToOneField(User, to_field="username", db_column='user', on_delete=models.DO_NOTHING) class Meta: db_table = 'categorizers' From a7df598e104828395bc2842d4381618092181539 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Wed, 24 Nov 2021 17:00:31 -0500 Subject: [PATCH 03/10] remove unnecessary code --- ponder/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ponder/models.py b/ponder/models.py index 5b75cf3..89901ca 100644 --- a/ponder/models.py +++ b/ponder/models.py @@ -62,7 +62,6 @@ def email_categorizer(self): class Categorizer(models.Model): name = models.CharField(unique=True, max_length=254) initials = models.CharField(unique=True, max_length=3) - #user = models.CharField(max_length=254) user = models.OneToOneField(User, to_field="username", db_column='user', on_delete=models.DO_NOTHING) class Meta: From 3e4263ffdca7ec7ff8d1032646a4a0972b51795b Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 28 Nov 2021 17:30:04 -0500 Subject: [PATCH 04/10] add tests for the categorizer model --- ponder/tests.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ponder/tests.py b/ponder/tests.py index 6ae0ac7..78063df 100644 --- a/ponder/tests.py +++ b/ponder/tests.py @@ -5,6 +5,8 @@ from ponder.models import Categorization, Categorizer, Commit, Dataset, ProblemCategory, ProblemCause, ProblemSymptom, ProblemFix from django.contrib.auth.models import User from ponder.forms import CategorizationForm + +from django.db import IntegrityError # Create your tests here. class AddCategorizationFormTests(TestCase): @@ -231,3 +233,37 @@ def test_category_text_not_null_and_func_fix_null(self): symptom_text='', symptom_description='',sha='0000000', data={"is_func_fix": False}, user='testUser') self.assertFalse(form.is_valid()) # The form should not be valid. self.assertEqual(form.errors["is_func_fix"], ["This field should be checked. An existing problem category indicates a bug fix."]) + +class CategorizerTests(TestCase): + @classmethod + def setUpTestData(self): + self.user1 = User.objects.create_user(username='testUser1', password='testpassword') + self.user2 = User.objects.create_user(username='testUser2', password='testpassword') + + #case when a new categorizer is being added when the given name already exists in the table + def test_same_name(self): + Categorizer.objects.all().delete() + Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) + #second categorizer is inserted with the same name and different initials and username. + Categorizer.objects.create(name='John Smith', initials='AB', user=self.user2) + #both testUser1 and testUser2 with the name "John Smith" should be in the table because two categorziers can have the same name + self.assertTrue(Categorizer.objects.filter(user='testUser1').exists()) + self.assertTrue(Categorizer.objects.filter(user='testUser2').exists()) + + #case when a new categorizer is being added when the given initial already exists in the table + def test_same_initials(self): + Categorizer.objects.all().delete() + Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) + #second categorizer is inserted with the same initials and different name and username. + Categorizer.objects.create(name='Jane Scott', initials='JS', user=self.user2) + #both testUser1 and testUser2 with the initials "JS" should be in the table because two categorziers can have the same initials + self.assertTrue(Categorizer.objects.filter(user='testUser1').exists()) + self.assertTrue(Categorizer.objects.filter(user='testUser2').exists()) + + #case when a new categorizer is being added when the given user already exists in the table + def test_same_user(self): + Categorizer.objects.all().delete() + Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) + #the same user is inserted again with different name and initials + #expecting an exaception when Categorizer.objects.create(name='Michelle Reed', initials='MR', user=self.user1) is called + self.assertRaises(IntegrityError, Categorizer.objects.create, name='Michelle Reed', initials='MR', user=self.user1) \ No newline at end of file From a27e5aa636cf7538499a7f4904ef61079f1e86b1 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 30 Nov 2021 17:17:57 -0500 Subject: [PATCH 05/10] Update models.py Add comments. --- ponder/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ponder/models.py b/ponder/models.py index 89901ca..06fbe77 100644 --- a/ponder/models.py +++ b/ponder/models.py @@ -62,6 +62,8 @@ def email_categorizer(self): class Categorizer(models.Model): name = models.CharField(unique=True, max_length=254) initials = models.CharField(unique=True, max_length=3) + + # The Django user this categorizer is related to. user = models.OneToOneField(User, to_field="username", db_column='user', on_delete=models.DO_NOTHING) class Meta: From 71311f2f328ff66bf640d4756be94330354b6768 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 30 Nov 2021 17:22:22 -0500 Subject: [PATCH 06/10] Update tests.py Comments. --- ponder/tests.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ponder/tests.py b/ponder/tests.py index 78063df..b362799 100644 --- a/ponder/tests.py +++ b/ponder/tests.py @@ -237,20 +237,26 @@ def test_category_text_not_null_and_func_fix_null(self): class CategorizerTests(TestCase): @classmethod def setUpTestData(self): + # Create two new Django users. self.user1 = User.objects.create_user(username='testUser1', password='testpassword') self.user2 = User.objects.create_user(username='testUser2', password='testpassword') - #case when a new categorizer is being added when the given name already exists in the table + # Case when a new categorizer is being added when the given name already exists in the table. def test_same_name(self): + # Make sure there are no other categorizers. Categorizer.objects.all().delete() + + # Create a categorizer John Smith. Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) - #second categorizer is inserted with the same name and different initials and username. + + # Second categorizer is inserted with the same name and different initials and username. Categorizer.objects.create(name='John Smith', initials='AB', user=self.user2) - #both testUser1 and testUser2 with the name "John Smith" should be in the table because two categorziers can have the same name + + # Both testUser1 and testUser2 with the name "John Smith" should be in the table because two categorziers can have the same name self.assertTrue(Categorizer.objects.filter(user='testUser1').exists()) self.assertTrue(Categorizer.objects.filter(user='testUser2').exists()) - #case when a new categorizer is being added when the given initial already exists in the table + # case when a new categorizer is being added when the given initial already exists in the table def test_same_initials(self): Categorizer.objects.all().delete() Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) @@ -266,4 +272,4 @@ def test_same_user(self): Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) #the same user is inserted again with different name and initials #expecting an exaception when Categorizer.objects.create(name='Michelle Reed', initials='MR', user=self.user1) is called - self.assertRaises(IntegrityError, Categorizer.objects.create, name='Michelle Reed', initials='MR', user=self.user1) \ No newline at end of file + self.assertRaises(IntegrityError, Categorizer.objects.create, name='Michelle Reed', initials='MR', user=self.user1) From 6b18ee03626e0bc1fb69c146b777f8bb88d78958 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 30 Nov 2021 17:29:05 -0500 Subject: [PATCH 07/10] Update tests.py Initials should be unique. --- ponder/tests.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ponder/tests.py b/ponder/tests.py index b362799..ee0fd6b 100644 --- a/ponder/tests.py +++ b/ponder/tests.py @@ -256,15 +256,23 @@ def test_same_name(self): self.assertTrue(Categorizer.objects.filter(user='testUser1').exists()) self.assertTrue(Categorizer.objects.filter(user='testUser2').exists()) - # case when a new categorizer is being added when the given initial already exists in the table + # Case when a new categorizer is being added when the given initial already exists in the table. def test_same_initials(self): + # Make sure there are no other categorizers. Categorizer.objects.all().delete() + + # Create a categorizer John Smith. Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) - #second categorizer is inserted with the same initials and different name and username. + + # Second categorizer is inserted with the same initials and different name and username. Categorizer.objects.create(name='Jane Scott', initials='JS', user=self.user2) - #both testUser1 and testUser2 with the initials "JS" should be in the table because two categorziers can have the same initials + + # Exception here because the two users have the same initials. + self.assertRaises(IntegrityError, Categorizer.objects.create, name='Jane Scott', initials='JS', user=self.user2) + + # testUser1 with the initials "JS" should be in the table but not testUser2 because two categorziers can't have the same initials. self.assertTrue(Categorizer.objects.filter(user='testUser1').exists()) - self.assertTrue(Categorizer.objects.filter(user='testUser2').exists()) + self.assertFalse(Categorizer.objects.filter(user='testUser2').exists()) #case when a new categorizer is being added when the given user already exists in the table def test_same_user(self): From be5ae7fb082f960ff77c62760aaa3312d587535a Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 30 Nov 2021 17:34:08 -0500 Subject: [PATCH 08/10] Update tests.py Clarify tests. --- ponder/tests.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ponder/tests.py b/ponder/tests.py index ee0fd6b..42d5ebd 100644 --- a/ponder/tests.py +++ b/ponder/tests.py @@ -265,8 +265,6 @@ def test_same_initials(self): Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) # Second categorizer is inserted with the same initials and different name and username. - Categorizer.objects.create(name='Jane Scott', initials='JS', user=self.user2) - # Exception here because the two users have the same initials. self.assertRaises(IntegrityError, Categorizer.objects.create, name='Jane Scott', initials='JS', user=self.user2) @@ -274,10 +272,14 @@ def test_same_initials(self): self.assertTrue(Categorizer.objects.filter(user='testUser1').exists()) self.assertFalse(Categorizer.objects.filter(user='testUser2').exists()) - #case when a new categorizer is being added when the given user already exists in the table + # Case when a new categorizer is being added when the given user already exists in the table def test_same_user(self): + # Make sure there are no other categorizers. Categorizer.objects.all().delete() + + # Create a categorizer John Smith. Categorizer.objects.create(name='John Smith', initials='JS', user=self.user1) - #the same user is inserted again with different name and initials - #expecting an exaception when Categorizer.objects.create(name='Michelle Reed', initials='MR', user=self.user1) is called + + # The same user is inserted again with different name and initials. + # Expecting an exception because two categorizers can't be related to the same Django user. self.assertRaises(IntegrityError, Categorizer.objects.create, name='Michelle Reed', initials='MR', user=self.user1) From f57febe927937fa1daece655abeed5040d296dfd Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 30 Nov 2021 17:46:20 -0500 Subject: [PATCH 09/10] Update models.py More comments. --- ponder/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ponder/models.py b/ponder/models.py index 06fbe77..7cf2575 100644 --- a/ponder/models.py +++ b/ponder/models.py @@ -63,7 +63,7 @@ class Categorizer(models.Model): name = models.CharField(unique=True, max_length=254) initials = models.CharField(unique=True, max_length=3) - # The Django user this categorizer is related to. + # The Django user this categorizer is related to. User is the Django user. user = models.OneToOneField(User, to_field="username", db_column='user', on_delete=models.DO_NOTHING) class Meta: From 22f0356523572a100407d143ae77dc9881f73bfe Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Tue, 30 Nov 2021 17:47:56 -0500 Subject: [PATCH 10/10] Update tests.py Remove comment. --- ponder/tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ponder/tests.py b/ponder/tests.py index 42d5ebd..afd8f7e 100644 --- a/ponder/tests.py +++ b/ponder/tests.py @@ -7,7 +7,6 @@ from ponder.forms import CategorizationForm from django.db import IntegrityError -# Create your tests here. class AddCategorizationFormTests(TestCase): '''