Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entry Class Implementation #429

Merged
merged 11 commits into from
Nov 15, 2023
1 change: 1 addition & 0 deletions project/backend/database/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Register your models here.

admin.site.register(Workspace)
admin.site.register(Entry)
admin.site.register(BasicUser)
admin.site.register(Contributor)
admin.site.register(Reviewer)
Expand Down
19 changes: 19 additions & 0 deletions project/backend/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Workspace(models.Model):
pass



class BasicUser(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.CharField(
Expand Down Expand Up @@ -58,6 +59,24 @@ class Admin(BasicUser):
def __str__(self):
return self.user.first_name + " " + self.user.last_name

class Entry(models.Model):
entry_id = models.AutoField(primary_key=True)
#workspace_id = models.ForeignKey(Workspace,null=False, blank = False, on_delete=models.CASCADE,related_name='WorkspaceID')
content = models.TextField(null=False)
entry_date = models.DateField()
is_theorem_entry = models.BooleanField()
is_final_entry = models.BooleanField(default=False)
is_editable = models.BooleanField(default=True)
creator = models.ForeignKey(Contributor,null=True,blank=True, on_delete = models.CASCADE)
entry_number = models.IntegerField()
contributors = models.ManyToManyField(Contributor,related_name="EntryContributors")
def set_as_final(self):
self.is_final_entry = True
def set_as_theorem(self):
self.is_theorem_entry = True
def set_entry_content(self,cont):
self.content += cont

class Request(models.Model):
request_status_choices = [
("P", "Pending"),
Expand Down
23 changes: 23 additions & 0 deletions project/backend/database/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,27 @@ def test_theorem_model(self):
self.assertEqual(theorem.theorem_title, "Test Theorem")
self.assertEqual(theorem.theorem_content, "This is a test theorem content.")

class EntryModelTestCase(TestCase):
def tearDown(self):
Entry.objects.all().delete()
print("All tests for the Entry Model are completed!")

def test_entry_model(self):

entry = Entry.objects.create(
entry_id = 1,
content = "This is an entry.",
entry_date = "2023-11-11",
is_theorem_entry = True,
entry_number = 1,
)
self.assertEqual(entry.entry_id, 1)
self.assertEqual(entry.entry_number, 1)
self.assertEqual(entry.content, "This is an entry.")
self.assertEqual(entry.entry_date, "2023-11-11")
self.assertEqual(entry.is_theorem_entry, True)
self.assertEqual(entry.is_final_entry,False)

class ReviewRequestTestCase(TestCase):
def tearDown(self):
Workspace.objects.all().delete()
Expand Down Expand Up @@ -393,6 +414,7 @@ def test_reject(self):
req = Request.objects.get(sender=self.contributor_sender)
self.assertEqual(req.status, "R", "Reject method didn't work as expected")


class RequestModelTestCase(TestCase):
def tearDown(self):
Request.objects.all().delete()
Expand All @@ -407,6 +429,7 @@ def setUp(self):
)
self.sender = Contributor.objects.create(user=sender_user, bio="Test bio 1")


receiver_user = User.objects.create(
username="testuser2",
email="[email protected]",
Expand Down