Skip to content

Commit

Permalink
Test logic.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Todic committed Sep 9, 2016
1 parent 2b007ff commit a7b9a42
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 12 deletions.
Empty file added demo/clean/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions demo/clean/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Empty file.
3 changes: 3 additions & 0 deletions demo/clean/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
10 changes: 10 additions & 0 deletions demo/clean/templates/clean/templates/with_tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "master.html" %}
{% load app_tags %}

{% block body %}
<h1>App template</h1>
{% example_inclusion_tag %}
<p id="simple_tag">Testing: {% example_simple_tag %}</p>
<p id="assignment_tag">Testing: {% example_assignment_tag as example%}</p>
<p id="filter">Testing: {% example_simple_tag 2|plus:5 %}</p>
{% endblock body %}
3 changes: 3 additions & 0 deletions demo/clean/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions demo/clean/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
2 changes: 2 additions & 0 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
'empty',
'clean',
'unload',
)

Expand Down
Empty file added demo/empty/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions demo/empty/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
Empty file.
3 changes: 3 additions & 0 deletions demo/empty/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions demo/empty/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions demo/empty/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
14 changes: 10 additions & 4 deletions unload/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,29 @@
import sys

from .base import Template
from .utils import (get_contents, get_package_locations,
from .utils import (get_app, get_contents, get_package_locations,
get_djangotemplates_engines, output_as_table,
output_template_name, output_message, get_templates)


def list_unnecessary_loads(app=None):
def list_unnecessary_loads(app_label=None):
"""
Scan the project directory tree for template files and process each and
every one of them.
:app: AppConfig object
:app_label: String; app label supplied by the user
:returns: None (outputs to the console)
"""
if app_label:
app = get_app(app_label)
else:
app = None

dt_engines = get_djangotemplates_engines()

for dt_engine in dt_engines:
has_issues = False
templates = []
# Get the locations of installed packages
pkg_locations = get_package_locations()
Expand All @@ -31,7 +36,6 @@ def list_unnecessary_loads(app=None):
templates += get_templates(directory, pkg_locations, app)

if templates:
has_issues = False
for template in templates:
status = process_template(template, dt_engine.engine)
if status:
Expand All @@ -41,6 +45,8 @@ def list_unnecessary_loads(app=None):
else:
output_message(reason=1)

return has_issues


def process_template(filepath, engine):
"""
Expand Down
8 changes: 1 addition & 7 deletions unload/management/commands/find_unnecessary_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.utils.translation import ugettext_lazy as _

from ...logic import list_unnecessary_loads
from ...utils import get_app
from ...settings import DJANGO_VERSION

if StrictVersion(DJANGO_VERSION) < StrictVersion('1.8'):
Expand All @@ -29,9 +28,4 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
# Find the app
app_label = options.get('app', None)
if app_label:
app = get_app(app_label)
else:
app = None

list_unnecessary_loads(app=app)
list_unnecessary_loads(app_label)
14 changes: 13 additions & 1 deletion unload/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.conf import settings
from django.test import TestCase

from ..logic import process_template
from ..logic import process_template, list_unnecessary_loads
from ..utils import get_djangotemplates_engines, get_app


Expand Down Expand Up @@ -65,3 +65,15 @@ def test_process_template(self):
status = process_template(without_tags, dt_engines[0].engine)
self.assertTrue(status)

def test_list_unnecessary_loads(self):
status = list_unnecessary_loads()
self.assertTrue(status)

status = list_unnecessary_loads('app')
self.assertTrue(status)

status = list_unnecessary_loads('empty')
self.assertFalse(status)

status = list_unnecessary_loads('clean')
self.assertFalse(status)

0 comments on commit a7b9a42

Please sign in to comment.