Skip to content

Commit

Permalink
Merge pull request #429 from bounswe/entryClass
Browse files Browse the repository at this point in the history
Entry Class Implementation
  • Loading branch information
gebenalimert authored Nov 15, 2023
2 parents 369aedb + 3aab8ee commit e88c5bf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
26 changes: 19 additions & 7 deletions project/backend/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,23 @@ class Request(models.Model):
"""
pass
class Entry(models.Model):
"""
This class definition is written beforehand (to be implemented afterwards)
in order to be referred from other classes. e.g. Contributor
This class definition is written beforehand (to be implemented afterwards)
in order to be referred from other classes. e.g. Workspace
"""
pass
entry_id = models.AutoField(primary_key=True)
entry_index = models.IntegerField()
#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
# Create your models here.
class Workspace(models.Model): #Node and Review Requests may be added later
workspace_id = models.AutoField(primary_key=True)
Expand All @@ -76,6 +86,7 @@ def finalize_workspace(self):
return True



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



class Request(models.Model):
request_status_choices = [
("P", "Pending"),
Expand Down
24 changes: 24 additions & 0 deletions project/backend/database/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,28 @@ 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,
entry_index = 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 @@ -458,6 +480,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 @@ -472,6 +495,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

0 comments on commit e88c5bf

Please sign in to comment.