Skip to content

Commit

Permalink
- update tests for this code in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
arcturusannamalai committed Mar 29, 2024
1 parent 42c1fcf commit e50a8c2
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 27 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/regression.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Open-Tamil Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8,3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# Runs a single command using the runners shell
- name: Custom Python Test for Open-Tamil
run:
- name: Run Tests
run: |
python manage.py makemigrations
python manage.py migrate
python manage.py test
Binary file modified demoproject/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified demoproject/__pycache__/urls.cpython-311.pyc
Binary file not shown.
5 changes: 0 additions & 5 deletions django_jtables/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
from django.contrib import admin

from student.models import Student

# Register your models here.
admin.site.register(Student)
34 changes: 22 additions & 12 deletions django_jtables/viewbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from django.db.models import Model, F
from django.http import JsonResponse, HttpRequest

from student.models import Student


class ModelViewBuilder:
def __init__(self, ModelClass: Model, fields, editable, modifier={}, datefields=[]):
self.pk_name = ModelClass.__name__ + "Id"
Expand All @@ -20,13 +17,18 @@ def update(self, request: Request):
print("UPDATE ACTION")

r = request.POST
target = self._ModelClass.objects.filter(id=r.get(self.pk_name))
import pprint
pprint.pprint(r)
#breakpoint()
target = self._ModelClass.objects.get(id=r.get(self.pk_name))

kwargs = {name: r.get(fieldname) for name, fieldname in self._editable.items()}
for name, modifier in self._modifier.items():
kwargs[name] = modifier(kwargs[name])
print(kwargs)
target.update(**kwargs)
kwargs.pop('id')
for _field,_value in kwargs.items():
setattr(target,_field,_value)
target.save()
data = {"Result": "OK"}
return JsonResponse(data)

Expand All @@ -36,7 +38,6 @@ def read(self, request: Request):
print("LIST ACTION")
# '-' means descending
print(request.POST)
# print(students_list.order_by('-name')[:])
r = request.POST
kwargs = {fieldname: F(name) for name, fieldname in self._fields.items()}
print(kwargs)
Expand All @@ -50,12 +51,21 @@ def read(self, request: Request):
for datefield in self._datefields:
if isinstance(record[datefield], (date, datetime)):
record[datefield] = record[datefield].isoformat()
# update boolean fields for display
for field in record.keys():
if isinstance(record[field],bool):
record[field] = str(record[field])


# sorting by field:
sort_field = request.GET["jtSorting"]
field, direction = sort_field.split(" ")
reverse = direction.upper() == "DESC"
records = sorted(records, key=lambda rec: rec[field], reverse=reverse)
sort_field = request.GET.get("jtSorting","")
if sort_field:
try:
field, direction = sort_field.split(" ")
reverse = direction.upper() == "DESC"
records = sorted(records, key=lambda rec: rec[field], reverse=reverse)
except Exception:
pass

# list(s) -> "Records"
data = {"Result": "OK", "Records": records}
Expand All @@ -72,7 +82,7 @@ def create(self, request: Request):
for name, modifier in self._modifier.items():
kwargs[name] = modifier(kwargs[name])

s = Student.objects.create(**kwargs)
s = self._ModelClass.objects.create(**kwargs)

record = kwargs
record["id"] = s.id
Expand Down
51 changes: 51 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
celery==5.2.7
certifi==2023.11.17
cffi==1.16.0
charset-normalizer==3.3.2
Django==4.2.9
django-allauth==0.51.0
django-bootstrap4==23.4
django-recaptcha==4.0.0
django-rest-framework==0.1.0
django-scheduler==0.10.1
django-ses==3.5.2
django-silk==5.0.3
django-storages==1.14.2
djangorestframework==3.14.0
djoser==2.2.2
docutils==0.20.1
easypost==8.0.0
environs==9.5.0
factory-boy==3.2.1
Faker==22.5.1
numpy==1.25.2
oauthlib==3.2.2
pandas==1.5.0
psycopg2-binary==2.9.9
ytest==7.4.0
python-dotenv==1.0.1
python-fsutil==0.13.1
python3-openid==3.2.0
pytz==2023.3.post1
PyYAML==6.0.1
requests==2.31.0
scipy==1.11.4
six==1.16.0
slack-sdk==3.23.0
smart-open==7.0.1
social-auth-app-django==5.4.0
social-auth-core==4.5.3
soupsieve==2.5
sqlparse==0.4.4
statsmodels==0.14.0
tenacity==8.2.3
threadpoolctl==3.3.0
typing_extensions==4.9.0
ua-parser==0.18.0
urllib3==2.0.7
user-agents==2.2.0
validators==0.20.0
vine==5.1.0
wcwidth==0.2.13
wrapt==1.16.0
XlsxWriter==3.1.9
13 changes: 6 additions & 7 deletions student/models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from django.db import models
import random

# Create your models here.
class Student(models.Model):
def __str__(self):
return self.name

name = models.CharField(max_length=200)

email_address = models.EmailField(max_length=200)

password = models.CharField(max_length=200)

class GenderChoices(models.TextChoices):
Expand All @@ -19,9 +18,10 @@ class GenderChoices(models.TextChoices):
gender = models.CharField(
max_length=1,
choices=GenderChoices.choices,
default=random.choice(GenderChoices.choices)
)

birth_date = models.DateField()
birth_date = models.DateField(auto_now_add=True)

class EducationChoices(models.TextChoices):
PRIMARY = "1", "Primary school"
Expand All @@ -31,11 +31,10 @@ class EducationChoices(models.TextChoices):
education = models.CharField(
max_length=1,
choices=EducationChoices.choices,
default=EducationChoices.PRIMARY
)

about = models.TextField()

is_active = models.BooleanField()
about = models.TextField(blank=True)
is_active = models.BooleanField(default=False)

# auto_now_add sets the DateTimeField to the datetime of when the object is created.
record_date = models.DateTimeField(auto_now_add=True)
36 changes: 34 additions & 2 deletions student/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
from django.test import TestCase
# (C) 2024, PanMo LLC.
# This file is part of ConFab - DOE platform.
# Private and Confidential - donot distribute.

# Create your tests here.
import os
import io
import datetime
import json
from io import BytesIO

from django.test import TestCase, RequestFactory, Client
from django.urls import reverse
from django.contrib.auth.models import User, Permission
from django.utils import timezone

from .models import Student


class StudentTests(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='testuser', password='testpassword')
self.client.login(username='testuser', password='testpassword')

self.student = Student.objects.create()


########################## TEST CASES START #############################

# /confab/flow/ confab.views.flow_view confab:flow_index

def test_student_get_list_action(self):
# Case 1: Flow search is successful, and the template is rendered
request = self.client.get(reverse('student:listAction'))
self.assertEqual(request.status_code, 200)
#self.assertTemplateUsed(request, 'confab/flow_index.html')
2 changes: 1 addition & 1 deletion student/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.urls import path

from . import views

app_name='student'
urlpatterns = [
path("csrf/", views.csrf, name="csrf"),
path("listAction/", views.listAction, name="listAction"),
Expand Down

0 comments on commit e50a8c2

Please sign in to comment.