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

Use pytest #1143

Merged
merged 1 commit into from
Jun 11, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Ion.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deploy
fabfile.py
manage.py
pyproject.toml
pytest.ini
requirements.txt
setup.py
.dependabot/config.yml
Expand Down Expand Up @@ -72,6 +73,8 @@ docs/sourcedoc/intranet.apps.api.rst
docs/sourcedoc/intranet.apps.auth.management.commands.rst
docs/sourcedoc/intranet.apps.auth.management.rst
docs/sourcedoc/intranet.apps.auth.rst
docs/sourcedoc/intranet.apps.bus.management.commands.rst
docs/sourcedoc/intranet.apps.bus.management.rst
docs/sourcedoc/intranet.apps.bus.rst
docs/sourcedoc/intranet.apps.dashboard.rst
docs/sourcedoc/intranet.apps.dataimport.management.commands.rst
Expand All @@ -89,6 +92,8 @@ docs/sourcedoc/intranet.apps.eighth.views.rst
docs/sourcedoc/intranet.apps.emailfwd.rst
docs/sourcedoc/intranet.apps.emerg.rst
docs/sourcedoc/intranet.apps.error.rst
docs/sourcedoc/intranet.apps.events.management.commands.rst
docs/sourcedoc/intranet.apps.events.management.rst
docs/sourcedoc/intranet.apps.events.rst
docs/sourcedoc/intranet.apps.features.rst
docs/sourcedoc/intranet.apps.feedback.rst
Expand Down Expand Up @@ -201,6 +206,7 @@ intranet/apps/bus/tasks.py
intranet/apps/bus/tests.py
intranet/apps/bus/urls.py
intranet/apps/bus/views.py
intranet/apps/bus/management/__init__.py
intranet/apps/bus/management/commands/__init__.py
intranet/apps/bus/management/commands/import_routes.py
intranet/apps/bus/management/commands/reset_routes.py
Expand Down Expand Up @@ -394,6 +400,7 @@ intranet/apps/events/tasks.py
intranet/apps/events/tests.py
intranet/apps/events/urls.py
intranet/apps/events/views.py
intranet/apps/events/management/__init__.py
intranet/apps/events/management/commands/__init__.py
intranet/apps/events/management/commands/import_sports.py
intranet/apps/events/migrations/0001_initial.py
Expand Down
4 changes: 2 additions & 2 deletions ci/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ env:
pip install -U pip setuptools
pip install -U \
flake8 pylint pylint-django pylint-plugin-utils isort black==20.8b1 autopep8 \
coverage coveralls pyyaml
coveralls pyyaml pytest-django
pip install -U -r requirements.txt
echo "PATH=$PATH" >> $GITHUB_ENV
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:

# Tests
- name: Run tests
run: coverage run ./setup.py test
run: coverage run -m pytest
- name: Migrate database
run: coverage run -a ./manage.py migrate
- name: Collect static files
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
"django": ("https://docs.djangoproject.com/en/dev", "https://docs.djangoproject.com/en/dev/_objects"),
"django": ("https://docs.djangoproject.com/en/dev", "https://docs.djangoproject.com/en/dev/_objects/"),
}
autodoc_inherit_docstrings = False

Expand Down
29 changes: 29 additions & 0 deletions docs/sourcedoc/intranet.apps.bus.management.commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
intranet.apps.bus.management.commands package
=============================================

Submodules
----------

intranet.apps.bus.management.commands.import\_routes module
-----------------------------------------------------------

.. automodule:: intranet.apps.bus.management.commands.import_routes
:members:
:undoc-members:
:show-inheritance:

intranet.apps.bus.management.commands.reset\_routes module
----------------------------------------------------------

.. automodule:: intranet.apps.bus.management.commands.reset_routes
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: intranet.apps.bus.management.commands
:members:
:undoc-members:
:show-inheritance:
18 changes: 18 additions & 0 deletions docs/sourcedoc/intranet.apps.bus.management.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
intranet.apps.bus.management package
====================================

Subpackages
-----------

.. toctree::
:maxdepth: 4

intranet.apps.bus.management.commands

Module contents
---------------

.. automodule:: intranet.apps.bus.management
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/sourcedoc/intranet.apps.bus.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
intranet.apps.bus package
=========================

Subpackages
-----------

.. toctree::
:maxdepth: 4

intranet.apps.bus.management

Submodules
----------

Expand Down
21 changes: 21 additions & 0 deletions docs/sourcedoc/intranet.apps.events.management.commands.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
intranet.apps.events.management.commands package
================================================

Submodules
----------

intranet.apps.events.management.commands.import\_sports module
--------------------------------------------------------------

.. automodule:: intranet.apps.events.management.commands.import_sports
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: intranet.apps.events.management.commands
:members:
:undoc-members:
:show-inheritance:
18 changes: 18 additions & 0 deletions docs/sourcedoc/intranet.apps.events.management.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
intranet.apps.events.management package
=======================================

Subpackages
-----------

.. toctree::
:maxdepth: 4

intranet.apps.events.management.commands

Module contents
---------------

.. automodule:: intranet.apps.events.management
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions docs/sourcedoc/intranet.apps.events.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
intranet.apps.events package
============================

Subpackages
-----------

.. toctree::
:maxdepth: 4

intranet.apps.events.management

Submodules
----------

Expand Down
4 changes: 2 additions & 2 deletions intranet/apps/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_api_eighth_signup_list(self):

def test_api_bus_list(self):
self.make_token()
route = Route.objects.create(route_name="JT-001", bus_number="JT-001")
route = Route.objects.create(route_name="JT-01", bus_number="JT-01")
response = self.client.get(reverse("api_bus_list"), HTTP_AUTHORIZATION=self.auth)

self.assertEqual(response.status_code, 200)
Expand All @@ -517,7 +517,7 @@ def test_api_bus_list(self):

def test_api_bus_detail(self):
self.make_token()
route_1 = Route.objects.create(route_name="JT-001", bus_number="JT-001")
route_1 = Route.objects.create(route_name="JT-01", bus_number="JT-01")
response = self.client.get(reverse("api_bus_detail", args=[route_1.pk]), HTTP_AUTHORIZATION=self.auth)

self.assertEqual(response.status_code, 200)
Expand Down
6 changes: 2 additions & 4 deletions intranet/apps/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from django.views.generic.base import View

from ...utils.date import get_senior_graduation_date, get_senior_graduation_year
from ...utils.helpers import dark_mode_enabled, get_ap_week_warning
from ...utils.helpers import awaredate, dark_mode_enabled, get_ap_week_warning
from ..dashboard.views import dashboard_view, get_fcps_emerg
from ..eighth.models import EighthBlock
from ..events.models import Event
Expand Down Expand Up @@ -92,9 +92,7 @@ def get_week_sports_school_events() -> Tuple[Container[Event], Container[Event]]
"""
cache_result = cache.get("sports_school_events")
if not isinstance(cache_result, tuple):
events = Event.objects.filter(
time__gte=timezone.localtime(), time__lte=(timezone.localdate() + relativedelta(weeks=1)), public=True
).this_year()
events = Event.objects.filter(time__gte=timezone.localtime(), time__lte=(awaredate() + relativedelta(weeks=1)), public=True).this_year()
sports_events = list(events.filter(approved=True, category="sports").order_by("time")[:3])
school_events = list(events.filter(approved=True, category="school").order_by("time")[:3])

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions intranet/apps/bus/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ def reset_status(self):

def __str__(self):
return self.route_name

class Meta:
ordering = ["route_name"]
4 changes: 2 additions & 2 deletions intranet/apps/bus/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_bus(self):
m.assert_called()

def test_routes(self):
route = Route.objects.get_or_create(route_name="JT-101", bus_number="JT-101")[0]
route = Route.objects.get_or_create(route_name="JT-01", bus_number="JT-01")[0]
route.status = "a"
route.space = "_1"
route.save()
Expand All @@ -47,7 +47,7 @@ def test_routes(self):
self.assertEqual(route.space, "")

def test_route_representation(self):
route = Route.objects.get_or_create(route_name="JT-101", bus_number="JT-101")[0]
route = Route.objects.get_or_create(route_name="JT-01", bus_number="JT-01")[0]
route_str = str(route)

self.assertEqual(route.route_name, route_str)
3 changes: 2 additions & 1 deletion intranet/apps/eighth/tests/admin/test_admin_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from intranet.apps.groups.models import Group

from .....utils.helpers import awaredate
from ...models import EighthActivity, EighthBlock, EighthRoom, EighthSponsor
from ..eighth_test import EighthAbstractTest

Expand Down Expand Up @@ -33,7 +34,7 @@ def test_eighth_admin_dashboard_view(self):
response = self.client.get(reverse("eighth_admin_dashboard"))
self.assertTemplateUsed(response, "eighth/admin/dashboard.html")

self.assertEqual(response.context["start_date"], timezone.localdate())
self.assertEqual(response.context["start_date"], awaredate())
self.assertQuerysetEqual(response.context["all_activities"], [repr(activity) for activity in EighthActivity.objects.all().order_by("name")])
self.assertQuerysetEqual(response.context["blocks_after_start_date"], [repr(block) for block in EighthBlock.objects.all()])
self.assertQuerysetEqual(response.context["groups"], [repr(group) for group in Group.objects.all().order_by("name")])
Expand Down
10 changes: 5 additions & 5 deletions intranet/apps/eighth/tests/admin/test_admin_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_download_group_csv_view(self):
group = Group.objects.get_or_create(name="test group 5")[0]
user1 = get_user_model().objects.get_or_create(username="2021ttest", first_name="Tommy", last_name="Test", student_id=1234568)[0]
user2 = get_user_model().objects.get_or_create(username="2021ttest1", first_name="Thomas", last_name="Test", student_id=1234567)[0]
user3 = get_user_model().objects.get_or_create(username="2021awilliam", first_name="A", last_name="William", student_id=12345679)[0]
user3 = get_user_model().objects.get_or_create(username="2021awilliam", first_name="A", last_name="William", student_id=1234569)[0]
for member in [user1, user2, user3]:
member.groups.add(group)
member.save()
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_eighth_admin_signup_group(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down Expand Up @@ -281,7 +281,7 @@ def test_eighth_admin_distribute_group(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_eighth_admin_distribute_unsigned(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down Expand Up @@ -417,7 +417,7 @@ def test_eighth_admin_distribute_action(self):
username="2021awilliam",
first_name="A",
last_name="William",
student_id=12345679,
student_id=1234569,
user_type="student",
graduation_year=get_senior_graduation_year(),
)[0]
Expand Down
6 changes: 4 additions & 2 deletions intranet/apps/eighth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

from django.utils import timezone

from ...utils.helpers import awaredate

DATE_FORMAT = "%m-%d-%Y"


def get_start_date(request):
if "start_date" in request.session and request.session.get("start_date_set_date") == timezone.localdate().strftime(DATE_FORMAT):
date = request.session["start_date"]
return datetime.strptime(date, DATE_FORMAT).date()
return timezone.make_aware(datetime.strptime(date, DATE_FORMAT))
else:
now = timezone.localdate()
now = awaredate()
set_start_date(request, now)
return now

Expand Down
5 changes: 3 additions & 2 deletions intranet/apps/eighth/views/admin/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.contrib.auth import get_user_model
from django.db.models import Count, Q
from django.shortcuts import redirect, render
from django.utils import timezone

from .....utils.helpers import is_entirely_digit
from ....auth.decorators import eighth_admin_required
Expand Down Expand Up @@ -198,12 +199,12 @@ def after_deadline_signup_view(request):
end_date = request.GET.get("end", "")

try:
start_date = datetime.strptime(start_date, "%Y-%m-%d")
start_date = timezone.make_aware(datetime.strptime(start_date, "%Y-%m-%d"))
except ValueError:
start_date = get_start_date(request)

try:
end_date = datetime.strptime(end_date, "%Y-%m-%d")
end_date = timezone.make_aware(datetime.strptime(end_date, "%Y-%m-%d"))
except ValueError:
end_date = start_date + timedelta(days=7)

Expand Down
1 change: 1 addition & 0 deletions intranet/apps/eighth/views/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def metrics_view(request):
)
.filter(unique_signups__lt=F("total_signups"))
.values_list("id", F("total_signups") - F("unique_signups"))
.order_by("date", "block_letter")
.nocache()
):
metrics['intranet_eighth_duplicate_signups{{block_id="{}"}}'.format(block_id)] = num_duplicates
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions intranet/apps/events/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_add_event(self):
"location": "Location",
"scheduled_activity": "",
"announcement": "",
"groups": 1,
"groups": [],
"show_attending": "on",
"show_on_dashboard": "on",
"category": "sports",
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_modify_event(self):
"location": "New location",
"scheduled_activity": "",
"announcement": "",
"groups": 1,
"groups": [],
"show_attending": "on",
"show_on_dashboard": "on",
"category": "sports",
Expand Down
Loading