Skip to content

Commit

Permalink
Finalized tests and workspace model
Browse files Browse the repository at this point in the history
  • Loading branch information
gebenalimert committed Nov 8, 2023
1 parent 1815038 commit bda5137
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 82 deletions.
145 changes: 71 additions & 74 deletions project/backend/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,49 @@
import copy
from datetime import datetime

# Create your models here.
class Workspace(models.Model):

class SemanticTag(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
label = models.CharField(max_length=50, unique=True)
desc = models.CharField(max_length=100)
parent_tag = models.ForeignKey("SemanticTag", on_delete=models.CASCADE, null=True, blank=True,
related_name="sub_tags")

@property
def count(self):
return self.node_set.all().count()

@property
def nodes(self):
return self.node_set.all()

@property
def recursive_nodes(self):
nodes = list(self.nodes)

for sub in self.sub_tags.all():
nodes.extend(sub.recursive_nodes)

return nodes

@property
def recursive_count(self):
return len(self.recursive_nodes)

class Meta:
constraints = [
models.UniqueConstraint(fields=['label', 'parent_tag'],
name='semantictag_label_parenttag_unique_constraint')
]

class WikiTag(models.Model):
pass
class Request(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
in order to be referred from other classes. e.g. ReviewRequest
"""
pass

class Entry(models.Model):
"""
This class definition is written beforehand (to be implemented afterwards)
Expand All @@ -22,6 +55,26 @@ class Entry(models.Model):
in order to be referred from other classes. e.g. Workspace
"""
pass
# Create your models here.
class Workspace(models.Model): #Node and Review Requests may be added later
workspace_id = models.AutoField(primary_key=True)
workspace_title = models.CharField(max_length=100)
collab_requests = models.ManyToManyField(Request, blank=True,related_name='CollaborationRequests')
semantic_tags = models.ManyToManyField(SemanticTag, blank=True,related_name = 'WorkspaceSemanticTags')
wiki_tags = models.ManyToManyField(WikiTag,blank=True,related_name = 'WorkspaceWikiTags')
is_finalized = models.BooleanField(null = True)
is_published = models.BooleanField(null = True)
is_in_review = models.BooleanField(null = True)
is_rejected = models.BooleanField(null = True)
theorem_posted = models.BooleanField(null = True)
num_approvals = models.IntegerField(null = True)
theorem_entry = models.ManyToManyField(Entry,related_name='TheoremEntry')
final_entry = models.ForeignKey(Entry,null=True, on_delete=models.CASCADE,related_name='FinalEntry')
def finalize_workspace(self):
self.is_finalized = True
self.is_in_review = False
return True


class BasicUser(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
Expand All @@ -47,7 +100,17 @@ def __str__(self):
after implementation of Workspace class.
"""
def create_workspace(self):
new_workspace = Workspace.objects.create()
new_workspace = Workspace.objects.create(
workspace_id=1,
workspace_title="Test Workspace",
is_finalized=False,
is_published=False,
is_in_review=False,
is_rejected=False,
theorem_posted=False,
num_approvals=0,
final_entry=None
)
self. workspaces.add(new_workspace)
return new_workspace

Expand All @@ -69,12 +132,7 @@ class Admin(BasicUser):
def __str__(self):
return self.user.first_name + " " + self.user.last_name

class Request(models.Model):
"""
This class definition is written beforehand (to be implemented afterwards)
in order to be referred from other classes. e.g. ReviewRequest
"""
pass

class ReviewRequest(Request):
"""
This class definition is written beforehand (to be implemented afterwards)
Expand All @@ -96,43 +154,6 @@ class Theorem(models.Model):
publish_date = models.DateField()


class SemanticTag(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
label = models.CharField(max_length=50, unique=True)
desc = models.CharField(max_length=100)
parent_tag = models.ForeignKey("SemanticTag", on_delete=models.CASCADE, null=True, blank=True, related_name="sub_tags")

@property
def count(self):
return self.node_set.all().count()

@property
def nodes(self):
return self.node_set.all()

@property
def recursive_nodes(self):
nodes = list(self.nodes)

for sub in self.sub_tags.all():
nodes.extend(sub.recursive_nodes)

return nodes

@property
def recursive_count(self):
return len(self.recursive_nodes)

class Meta:
constraints = [
models.UniqueConstraint(fields=['label', 'parent_tag'], name='semantictag_label_parenttag_unique_constraint')
]


class WikiTag(models.Model):
pass


class Annotation(models.Model):
pass

Expand All @@ -157,30 +178,6 @@ class Node(models.Model):
def increment_num_visits(self):
self.num_visits += 1

class Workspace(models.Model):
workspace_id = models.AutoField(primary_key=True)
node = models.ForeignKey(Node, on_delete=models.CASCADE, related_name="Workspaces") #?
workspace_title = models.CharField(max_length=100)
contributors = models.ManyToManyField(Contributor, related_name='WorkspaceContributors')
collab_requests = models.ManyToManyField(Request, blank=True,related_name='CollaborationRequests')
references = models.ManyToManyField(Node,related_name = 'WorkspaceReferences')
reviews = models.ManyToManyField(ReviewRequest,blank=True,related_name = 'WorkspaceReviews') #?
semantic_tags = models.ManyToManyField(SemanticTag, blank=True,related_name = 'WorkspaceSemanticTags')
wiki_tags = models.ManyToManyField(WikiTag,blank=True,related_name = 'WorkspaceWikiTags')
is_finalized = models.BooleanField()
is_published = models.BooleanField()
is_in_review = models.BooleanField()
is_rejected = models.BooleanField()
theorem_posted = models.BooleanField()
num_approvals = models.IntegerField()
theorem_entry = models.ManyToManyField(Entry,related_name='TheoremEntry')
final_entry = models.ForeignKey(Entry,on_delete=models.CASCADE,related_name='FinalEntry')
def finalize_workspace(self):
self.is_finalized = True
self.is_in_review = False
return True


class Proof(models.Model):
proof_id = models.AutoField(primary_key=True)
proof_title = models.CharField(max_length=100, null=False)
Expand Down
32 changes: 24 additions & 8 deletions project/backend/database/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,17 @@ def test_create_workspace(self):
def test_delete_workspace(self):
# Create a workspace and add it to the contributor
contributor = Contributor.objects.create(user=User.objects.create())
workspace = Workspace.objects.create()
workspace = Workspace.objects.create(
workspace_id=1,
workspace_title="Test Workspace",
is_finalized=False,
is_published=False,
is_in_review=False,
is_rejected=False,
theorem_posted=False,
num_approvals=0,
final_entry=None
)
contributor.workspaces.add(workspace)

# Test the delete_workspace method
Expand All @@ -97,7 +107,17 @@ def test_delete_workspace(self):
def test_delete_nonexistent_workspace(self):
# Create a workspace, but don't add it to the contributor
contributor = Contributor.objects.create(user=User.objects.create())
workspace = Workspace.objects.create()
workspace = Workspace.objects.create(
workspace_id=1,
workspace_title="Test Workspace",
is_finalized=False,
is_published=False,
is_in_review=False,
is_rejected=False,
theorem_posted=False,
num_approvals=0,
final_entry=None
)

# Test the delete_workspace method with a non-existent workspace
contributor.delete_workspace(workspace) # This should not raise an error
Expand Down Expand Up @@ -216,14 +236,12 @@ def test_workspace_model(self): #Testing workspace model creation
workspace = Workspace.objects.create(
workspace_id = 1,
workspace_title = "Test Workspace",
node = None,
is_finalized = False,
is_published= False,
is_in_review = False,
is_rejected = False,
theorem_posted = False,
num_approvals = 0,
theorem_entry = None,
final_entry = None
)

Expand All @@ -235,28 +253,26 @@ def test_workspace_model(self): #Testing workspace model creation
self.assertEqual(workspace.is_rejected, False)
self.assertEqual(workspace.theorem_posted, False)
self.assertEqual(workspace.num_approvals, 0)
self.assertIsNone(workspace.theorem_entry)
self.assertIsNone(workspace.final_entry)

def test_finalize_workspace(self): #Testing finalize workspace function
def test_finalize_workspace(self): #Testing finalize workspace function
workspace = Workspace.objects.create(
workspace_id=1,
workspace_title="Test Workspace",
node=None,
is_finalized=False,
is_published=False,
is_in_review=False,
is_rejected=False,
theorem_posted=False,
num_approvals=0,
theorem_entry=None,
final_entry=None
)
Workspace.finalize_workspace(workspace)
self.assertEqual(workspace.is_finalized, True)
self.assertEqual(workspace.is_in_review, False)



class NodeModelTestCase(TestCase):
def tearDown(self):
Node.objects.all().delete()
Expand Down

0 comments on commit bda5137

Please sign in to comment.