Skip to content

Commit

Permalink
Merge branch '272-emin-add-unittests' of https://github.com/bounswe/b…
Browse files Browse the repository at this point in the history
…ounswe2024group9 into 272-emin-add-unittests
  • Loading branch information
mehmeteminipekdal committed Nov 25, 2024
2 parents 3edce0a + e44e7f6 commit 28e9e45
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 72 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ cd bounswe2024group9</code></pre>
AWS_HOST=XXX
JUDGE0_API_KEY=XXX
DJANGO_SECRET_KEY=XXX
ALTERNATIVE_JUDGE0_API_KEY=XXX
REACT_APP_API_URL=XXX</code></pre>
JUDGE0_API_KEY_POOL=XXX
REACT_APP_API_URL=XXX
REACT_APP_FRONTEND_URL=XXX
EMAIL_HOST_USER=XXX
GEMINI_AI_KEY_POOL=XXX
</code></pre>
<li>Run the following command to run Docker image
<pre><code>docker compose up</code></pre>
</li>
Expand Down
21 changes: 0 additions & 21 deletions django_project_491/django_app/migrations/0006_topic.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 5.1.2 on 2024-11-25 17:46

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('django_app', '0006_annotation'),
('django_app', '0006_topic'),
]

operations = [
]
39 changes: 20 additions & 19 deletions django_project_491/django_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,6 @@ def check_and_promote(self):

return self.userType

class Topic(models.Model):
name = models.CharField(max_length=100, unique=True)
related_url = models.URLField()

def __str__(self):
return self.name

@staticmethod
def get_all_topics():
return Topic.objects.all()

@staticmethod
def get_url_for_topic(topic_name):
try:
topic = Topic.objects.get(name__iexact=topic_name)
return topic.related_url
except Topic.DoesNotExist:
return None


class Annotation(models.Model):
_id = models.AutoField(primary_key=True)
Expand All @@ -320,3 +301,23 @@ def __repr__(self):

def __unicode__(self):
return self.text


class Topic(models.Model):
name = models.CharField(max_length=100, unique=True)
related_url = models.URLField()

def __str__(self):
return self.name

@staticmethod
def get_all_topics():
return Topic.objects.all()

@staticmethod
def get_url_for_topic(topic_name):
try:
topic = Topic.objects.get(name__iexact=topic_name)
return topic.related_url
except Topic.DoesNotExist:
return None
67 changes: 62 additions & 5 deletions django_project_491/django_app/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def setUp(self):
# Create a test question
self.question = Question.objects.create(
title='Sample Question',
language='Python',
language='Python (3.12.5)',
details='How to test models in Django?',
code_snippet='print("Test")',
author=self.user
Expand Down Expand Up @@ -240,7 +240,7 @@ def setUp(self):
# Create a test question
self.question = Question.objects.create(
title='Sample Question',
language='Python',
language='Python (3.12.5)',
language_id=71, # Language ID for Python
details='How to test models in Django?',
code_snippet='print("Test")',
Expand All @@ -260,7 +260,7 @@ def test_mark_as_answered(self):
comment = Comment.objects.create(
details='This is a test comment',
code_snippet='print("Test comment")',
language='Python',
language='Python (3.12.5)',
question=self.question,
author=self.user
)
Expand Down Expand Up @@ -288,7 +288,7 @@ def setUp(self):
# Create a test question
self.question = Question.objects.create(
title='Sample Question',
language='Python',
language='Python (3.12.5)',
details='How to test models in Django?',
code_snippet='print("Test")',
author=self.user
Expand All @@ -298,7 +298,7 @@ def setUp(self):
self.comment = Comment.objects.create(
details='This is a test comment',
code_snippet='print("Test comment")',
language='Python',
language='Python (3.12.5)',
question=self.question,
author=self.user
)
Expand Down Expand Up @@ -997,3 +997,60 @@ def test_mark_comment_as_answer(self):
# Refresh the comment object to check if it's marked as an answer
comment.refresh_from_db()
self.assertTrue(comment.answer_of_the_question) # Ensure the comment is marked as the answer



class UtilsViews(TestCase):
def setUp(self):
self.user = User.objects.create_user(
username='testuser',
password='password',
email="[email protected]"
)

self.question = Question.objects.create(
title='Test Question',
language='Python (3.12.5)',
language_id=71,
tags=['tag1', 'tag2'],
details='This is a test question.',
code_snippet='print("Test")',
author=self.user
)

self.comment = Comment.objects.create(
details='This is a test comment.',
author=self.user,
question=self.question,
language='Python (3.12.5)',
language_id=71,
code_snippet='print("Testfrom comment)'
)



def test_run_code_of_comment(self):
response = self.client.get(reverse('run_code', args=["comment", self.comment._id]))
self.assertEqual(response.status_code, 200)
response_data = response.json()
self.assertTrue( 'SyntaxError: EOL while scanning string literal' in response_data['output'][-1],)

def test_run_code_of_question(self):
response = self.client.get(reverse('run_code', args=["question", self.question._id]))
self.assertEqual(response.status_code, 200)
response_data = response.json()
print(response_data)
self.assertEqual(response_data['output'][0], 'Test')


def test_upvote_comment(self):
response = self.client.post(reverse('upvote_object', args=["question",self.question._id]), **{'HTTP_User-ID': self.user.user_id})
self.assertEqual(response.status_code, 200)
self.question.refresh_from_db()
self.assertEqual(self.question.upvotes, 1)

def test_downvote_comment(self):
response = self.client.post(reverse('downvote_object', args=["comment", self.comment._id]), **{'HTTP_User-ID': self.user.user_id})
self.assertEqual(response.status_code, 200)
self.comment.refresh_from_db()
self.assertEqual(self.comment.upvotes, -1)
5 changes: 5 additions & 0 deletions django_project_491/django_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@
path('questions/<int:question_id>/topic/', question_views.get_topic_url, name='get_topic_url'),
path('topics/', question_views.list_all_topics, name='list_all_topics'),

path('create_annotation/', annotation_views.create_annotation, name='create_annotation'),
path('delete_annotation/<int:annotation_id>/', annotation_views.delete_annotation, name='delete_annotation'),
path('edit_annotation/<int:annotation_id>/', annotation_views.edit_annotation, name='edit_annotation'),
path('get_annotations_by_language_id/<int:language_qid>/', annotation_views.get_annotations_by_language, name='get_annotations_by_language_id'),
path('annotations/all/', annotation_views.get_all_annotations, name='get_all_annotations'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
15 changes: 10 additions & 5 deletions koduyorum-web/src/Annotation.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
.annotation {
position: relative;
cursor: pointer;
font-style: italic;
color: darkcyan; /* Example: Tomato color */
}
font-style: italic; /* Italicize the text to differentiate it from the rest */
background-color: cyan; /* Light yellow background for highlight effect */
padding: 2px; /* Add padding for better appearance */
border-radius: 2px; /* Slightly round the edges to mimic a marker stroke */
display: inline-block; /* Keep it inline while allowing styling */
color: black; /* Ensure the text is readable */
}


.annotation-tooltip {
position: absolute;
top: 120%;
left: 20%;
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 5px;
padding: 10px; /* Comfortable padding */
border-radius: 3px;
font-size: 12px;
max-width: 200px;
max-width: 300px; /* Limit width to prevent overflowing */
white-space: nowrap;
z-index: 10;
opacity: 0;
Expand Down
29 changes: 25 additions & 4 deletions koduyorum-web/src/CreateAnnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ const CreateAnnotation = ({ visible, selectedText, startIndex, endIndex, languag
placeholder="Enter your annotation..."
/>
<div className="modal-buttons">
<button onClick={handleSubmit}>{annotationId ? 'Save Changes' : 'Create'}</button>
<button className="cancel-button" onClick={onClose}>Cancel</button>
<button
className={annotationId ? "save-button" : "create-button"}
onClick={handleSubmit}
>
{annotationId ? "Save Changes" : "Create"}
</button>
<button className="cancel-button" onClick={onClose}>
Cancel
</button>
</div>
</div>

Expand Down Expand Up @@ -109,14 +116,28 @@ const CreateAnnotation = ({ visible, selectedText, startIndex, endIndex, languag
justify-content: space-between;
gap: 10px;
}
.submit-button {
background: #4CAF50;
.save-button {
background: #007bff; /* Blue color for Save Changes */
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.save-button:hover {
background: #0056b3; /* Darker blue on hover */
}
.create-button {
background: #28a745; /* Green color for Create */
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
.create-button:hover {
background: #218838; /* Darker green on hover */
}
.cancel-button {
background: #f44336;
color: white;
Expand Down
Loading

0 comments on commit 28e9e45

Please sign in to comment.