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

Feature/backend style action #63

Merged
merged 7 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/backend-style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: backend-style

on: [push, pull_request, workflow_dispatch]

jobs:
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8.12
architecture: x64
- name: Install flake8
run: pip install flake8
- name: Run flake8
run: flake8 . --max-line-length 91
working-directory: eap_backend
2 changes: 0 additions & 2 deletions eap_backend/eap_api/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from django.urls import path, include
from django.contrib.auth.models import User
from rest_framework import routers
from . import views


Expand Down
5 changes: 1 addition & 4 deletions eap_backend/eap_api/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import json
from django.http import HttpRequest, HttpResponse, JsonResponse
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from rest_framework import viewsets
from rest_framework import permissions
from rest_framework import generics
from .models import (
AssuranceCase,
Expand Down
4 changes: 2 additions & 2 deletions eap_backend/eap_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

## use sqlite db for tests
# use sqlite db for tests
if (
"test" in sys.argv or "test_coverage" in sys.argv
): # Covers regular testing and django-coverage
Expand All @@ -110,7 +110,7 @@
}
}
else:
if not "DBHOST" in os.environ.keys():
if "DBHOST" not in os.environ.keys():
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
Expand Down
1 change: 0 additions & 1 deletion eap_backend/eap_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""
from django.contrib import admin
from django.urls import include, path
from eap_api import views


urlpatterns = [
Expand Down
39 changes: 0 additions & 39 deletions eap_backend/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,9 @@
CONTEXT_INFO,
DESCRIPTION_INFO,
PROPERTYCLAIM1_INFO,
PROPERTYCLAIM2_INFO,
ARGUMENT1_INFO_NO_ID,
ARGUMENT2_INFO,
EVIDENTIALCLAIM1_INFO,
EVIDENTIALCLAIM2_INFO,
EVIDENTIALCLAIM3_INFO,
EVIDENTIALCLAIM4_INFO,
EVIDENCE1_INFO_NO_ID,
EVIDENCE2_INFO,
EVIDENCE3_INFO,
EVIDENCE4_INFO,
EVIDENCE5_INFO,
EVIDENCE6_INFO,
EVIDENCE7_INFO,
)

# Create your tests here.
Expand Down Expand Up @@ -68,7 +57,6 @@ def create_test_entry(self):

def test_goal_creation(self):
test_name = GOAL_INFO["name"]
test_keywords = GOAL_INFO["keywords"]
test_entry = self.create_test_entry()
self.assertTrue(isinstance(test_entry, TopLevelNormativeGoal))
self.assertEqual(test_entry.name, test_name)
Expand Down Expand Up @@ -156,33 +144,6 @@ def test_property_claim_creation(self):
self.assertTrue(isinstance(test_entry.goal.assurance_case, AssuranceCase))


class PropertyClaimTestCase(TestCase):
"""
creates a PropertyClaim object and tests foreign key and
whether the created title matches the expected title
"""

def create_test_entry(self):
case = AssuranceCase.objects.create(**CASE_INFO)
goal = TopLevelNormativeGoal.objects.create(**GOAL_INFO)
goal.assurance_case = case
pclaim = PropertyClaim.objects.create(**PROPERTYCLAIM1_INFO)
pclaim.goal = goal
return pclaim

def test_property_claim_creation(self):
test_name = PROPERTYCLAIM1_INFO["name"]
test_desc = PROPERTYCLAIM1_INFO["short_description"]
test_entry = self.create_test_entry()
self.assertTrue(isinstance(test_entry, PropertyClaim))
self.assertEqual(test_entry.name, test_name)
self.assertEqual(test_entry.short_description, test_desc)
# test one-step relation
self.assertTrue(isinstance(test_entry.goal, TopLevelNormativeGoal))
# test two-step relation
self.assertTrue(isinstance(test_entry.goal.assurance_case, AssuranceCase))


class ArgumentTestCase(TestCase):
"""
creates an Argument object and tests foreign key and
Expand Down
27 changes: 3 additions & 24 deletions eap_backend/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
from django.test import TestCase
from django.urls import reverse, path
from eap_api.views import (
case_list,
case_detail,
goal_list,
goal_detail,
context_list,
context_detail,
description_list,
description_detail,
property_claim_list,
property_claim_detail,
argument_list,
argument_detail,
evidential_claim_list,
evidential_claim_detail,
evidence_list,
evidence_detail,
make_summary,
)
from django.urls import reverse
from eap_api.views import make_summary
from eap_api.models import (
AssuranceCase,
TopLevelNormativeGoal,
Expand Down Expand Up @@ -52,9 +34,6 @@
ARGUMENT1_INFO_NO_ID,
ARGUMENT2_INFO_NO_ID,
EVIDENTIALCLAIM1_INFO,
EVIDENTIALCLAIM2_INFO,
EVIDENTIALCLAIM3_INFO,
EVIDENTIALCLAIM4_INFO,
# for many-to-many relations, need to NOT have
# e.g. evidential_claim_id in the JSON
EVIDENCE1_INFO_NO_ID,
Expand Down Expand Up @@ -84,7 +63,7 @@ def test_case_list_view_post(self):
)
self.assertEqual(response_post.status_code, 201)
self.assertEqual(response_post.json()["name"], post_data["name"])
## check we now have two cases in the db
# check we now have two cases in the db
response_get = self.client.get(reverse("case_list"))
self.assertEqual(len(response_get.json()), 2)

Expand Down