Skip to content

Commit

Permalink
Merge pull request #33 from LegoStormtroopr/draft_0_4
Browse files Browse the repository at this point in the history
Draft 0 4
  • Loading branch information
LegoStormtroopr authored Dec 18, 2020
2 parents 5f48d6c + 78f0e48 commit e815940
Show file tree
Hide file tree
Showing 18 changed files with 359 additions and 180 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: Testing
on:
push:
branches:
- master
- develop
on: [push, pull_request]

jobs:
python_lint:
Expand All @@ -25,13 +21,6 @@ jobs:
needs:
- python_lint
name: Testing
strategy:
matrix:
django:
- '2.2'
- '3.0'
- '3.1'

runs-on: ubuntu-latest

steps:
Expand All @@ -41,7 +30,7 @@ jobs:
python-version: 3.8

- name: Install tox
run: pip install --upgrade setuptools pip poetry
run: pip install tox

- name: Run tests
run: poetry config virtualenvs.create false && poetry install && django-admin test
run: tox
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.8-buster

# Install python package management tools
RUN pip install --upgrade setuptools pip poetry

COPY ./* /usr/src/app/
WORKDIR /usr/src/app

ENV PYTHONPATH=/usr/src/app/django_spaghetti DJANGO_SETTINGS_MODULE=tests.settings
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ A complex live-demo
To see a complex example, where ``django-spaghetti-and-meatballs`` really shines,
checkout the live version built for the `Aristotle Metadata Registry <http://registry.aristotlemetadata.com/labs/plate/>`_

Testing and developing
----------------------

I like keeping my development environments isolated in docker. You can too. If you want to install `poetry` locally, you can skip this bit.

* Build a container with Pythong and Poetry installed - `docker build . -t spaghetti`
* Run a container for developing `docker run -v "$(realpath .)":/site -w /site -p 8000:8000 -it --rm spaghetti bash`

* Install the dependencies - `poetry install`
* Open a poetry shell - `poetry shell`
* Run the server - `django-admin runserver 0.0.0.0:8000`

If you navigate to `127.0.0.1:8000` should should see the demo app.

.. |docs| image:: https://readthedocs.org/projects/django-spaghetti-and-meatballs/badge/?version=latest
:target: https://django-spaghetti-and-meatballs.readthedocs.io/en/latest/
:alt: Documentation Status
Expand All @@ -108,3 +122,4 @@ checkout the live version built for the `Aristotle Metadata Registry <http://reg

.. |travis| image:: https://travis-ci.org/LegoStormtroopr/django-spaghetti-and-meatballs.svg?branch=master
:target: https://travis-ci.org/LegoStormtroopr/django-spaghetti-and-meatballs

47 changes: 47 additions & 0 deletions django_spaghetti/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Testing
on:
push:
branches:
- master
- develop

jobs:
python_lint:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v1
- name: Setup Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install flake8
run: pip install flake8
- name: Lint
run: flake8

test:
needs:
- python_lint
name: Testing
strategy:
matrix:
django:
- '2.2'
- '3.0'
- '3.1'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install tox
run: pip install --upgrade setuptools pip poetry

- name: Run tests
run: poetry config virtualenvs.create false && poetry install && django-admin test
19 changes: 0 additions & 19 deletions django_spaghetti/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
__version_info__ = {
'major': 0,
'minor': 3,
'micro': 1,
'releaselevel': 'final',
'serial': 0
}


def get_version(release_level=True):
"""
Return the formatted version information
"""
vers = ["%(major)i.%(minor)i.%(micro)i" % __version_info__]
if release_level and __version_info__['releaselevel'] != 'final':
vers.append('%(releaselevel)s%(serial)i' % __version_info__)
return ''.join(vers)

__version__ = get_version()
8 changes: 4 additions & 4 deletions django_spaghetti/templates/django_spaghetti/meatball.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% load i18n %}
<div style="max-width:350px;white-space: normal;">
<div style="border-bottom:1px solid black">
{% if model.is_proxy %}
{% trans "Proxy for:" %} {{ model.proxy }} <br>
{% if model_meta.is_proxy %}
{% trans "Proxy for:" %} {{ model_meta.proxy }} <br>
{% endif %}
{% trans "Model:" %} {{ model.model }}<br>
{% trans "App:" %} {{ model.app_label }}
{% trans "Model:" %} {{ model_meta.model_name }}<br>
{% trans "App:" %} {{ model_meta.app_label }}
</div>
<div style="white-space:pre-line">
{{ model.doc }}
Expand Down
64 changes: 64 additions & 0 deletions django_spaghetti/tests/templates/tests/home_plate.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/vis/4.7.0/vis.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.7.0/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Django Spaghetti and Meatballs Demo</h1>

<ul>
<li>
<a href="{% url 'test_plate_settings' %}">Plate settings override</a>
</li>
<li>
<a href="{% url 'test_plate_show_m2m_field_detail' %}">M2M override test</a>
</li>
<li>
<a href="{% url 'test_plate_override' %}">Plate override test</a>
</li>
<li>
<a href="{% url 'spaghetti:plate' %}">Generic plate view</a>
</li>
</ul>


<hr>

<div id="visualization" style="max-height:500px"></div>

<script>
var nodes = new vis.DataSet(
{{ meatballs|safe }}
);

var edges = new vis.DataSet(
{{ spaghetti|safe }}
);

var data = {
nodes: nodes,
edges: edges
};

var container = document.getElementById('visualization');
var options = {
"edges": {
"smooth": {
"type": "dynamic"
}
},

"layout": {
hierarchical: {
sortMethod: 'hubsize',
direction:'LR'
}
},

};

var timeline = new vis.Network(container, data, options);

</script>
</body>
</html>
1 change: 1 addition & 0 deletions django_spaghetti/tests/templates/tests/meatball.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Overriden to have nothing for testing purposes
18 changes: 7 additions & 11 deletions django_spaghetti/tests/test_it.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
from django.test import TestCase
from django.urls import reverse


class LoadThePlate(TestCase):
def test_plate(self):
response = self.client.get("/plate")
resp_str = str(response.content)
self.assertEqual(response.status_code, 200)
self.assertTrue('Officer' in resp_str)
self.assertTrue('All arrests made by the officer' not in resp_str)
self.assertContains(response, 'Officer')
self.assertContains(response, 'All arrests made by the officer')

def test_plate_with_settings(self):
response = self.client.get("/test/plate_settings")
self.assertEqual(response.status_code, 200)
self.assertTrue('Officer' not in str(response.content))
self.assertNotContains(response, 'Officer')

def test_plate_show_m2m_field_detail(self):
response = self.client.get("/test/plate_show_m2m_field_detail")
resp_str = str(response.content)
self.assertEqual(response.status_code, 200)
self.assertTrue('Officer' in resp_str)
self.assertTrue('All arrests made by the officer' in resp_str)
self.assertContains(response, 'Officer')
self.assertContains(response, 'All arrests made by the officer')

def test_plate_with_override_settings(self):
response = self.client.get("/test/plate_override")
Expand All @@ -31,13 +28,12 @@ def test_plate_with_override_settings(self):
def test_no_override_after_override(self):
response1 = self.client.get("/test/plate_override")
response2 = self.client.get("/plate")
resp_str = str(response2.content)
self.assertEqual(response1.status_code, 200)
self.assertEqual(response2.status_code, 200)
self.assertTrue('policeofficer' in str(response1.content).lower())
self.assertTrue('policestation' not in str(response1.content).lower())
self.assertTrue('Officer' in resp_str)
self.assertTrue('All arrests made by the officer' not in resp_str)
self.assertContains(response1, 'Officer')
self.assertNotContains(response1, 'All arrests made by the officer')

def test_meatball(self):
response = self.client.get("/test/plate_show_m2m_field_detail")
Expand Down
7 changes: 5 additions & 2 deletions django_spaghetti/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.conf.urls import url, include
from django_spaghetti.views import plate, Plate
from django_spaghetti.views import Plate

urlpatterns = [
url(r'^$', Plate.as_view(
plate_template_name="tests/home_plate.html"
), name='test_plate_override$'),
url(r'^test/plate_settings$', Plate.as_view(
settings={
'apps': ['auth'],
Expand All @@ -20,6 +23,6 @@
},
},
meatball_template_name="tests/meatball.html"
), name='test_plate_override$'),
), name='test_plate_override'),
url(r'plate', include('django_spaghetti.urls', namespace="spaghetti")),
]
Loading

0 comments on commit e815940

Please sign in to comment.