Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
test: Added tests for model
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwickraj78 authored and SanketDG committed Jul 25, 2020
1 parent 6637a67 commit 48cd42c
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion systers_portal/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
data-toggle="dropdown">{{ user }} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li {% if '/settings/' in request.path %}class="active"{% endif %}>
<a role="menuitem" href="{% url 'edit_settings' user.username %}">Settings</a>
<a role="menuitem" href="{% url 'edit_settings' user.username %}">Email Settings</a>
</li>
<li {% if '/users/' in request.path and '/settings/' not in request.path %}class="active"{% endif %}>
<a href="{% url 'user' user.username %}">Profile</a>
Expand Down
2 changes: 1 addition & 1 deletion systers_portal/templates/users/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% block content%}
{% load crispy_forms_tags %}
<div class="col-md-4 col-md-offset-4">
<h1>Subscription Settings</h1>
<h2>Email Subscription Settings</h2>
<hr>
</div>
<div class="col-md-4 col-md-offset-4">
Expand Down
2 changes: 1 addition & 1 deletion systers_portal/users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, *args, **kwargs):
super(EditUserSettings, self).__init__(*args, **kwargs)

def save(self, commit=True):
"""Override save to add created_by and meetup_location to the instance"""
"""Override save to add user field to the instance"""
instance = super(EditUserSettings, self).save(commit=False)
instance.user = SystersUser.objects.get(user=self.user)
if commit:
Expand Down
35 changes: 35 additions & 0 deletions systers_portal/users/migrations/0003_auto_20200722_1126.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2020-07-22 11:26
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('users', '0002_usersetting'),
]

operations = [
migrations.AlterField(
model_name='usersetting',
name='location_change',
field=models.BooleanField(default=False, verbose_name='Get Notified on Change in Location for Meetups'),
),
migrations.AlterField(
model_name='usersetting',
name='reminder',
field=models.BooleanField(default=False, verbose_name="Get Reminders for rsvp'd Meetups"),
),
migrations.AlterField(
model_name='usersetting',
name='time_change',
field=models.BooleanField(default=False, verbose_name='Get Notified on Change in Timings for Meetups'),
),
migrations.AlterField(
model_name='usersetting',
name='weekly_digest',
field=models.BooleanField(default=True, verbose_name='Receive Weekly Digests from Communities'),
),
]
16 changes: 12 additions & 4 deletions systers_portal/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,18 @@ def create_systers_user(sender, instance, created, **kwargs):

class UserSetting(models.Model):
user = models.OneToOneField(SystersUser, on_delete=models.CASCADE)
weekly_digest = models.BooleanField(default=False)
location_change = models.BooleanField(default=False)
time_change = models.BooleanField(default=False)
reminder = models.BooleanField(default=False)
weekly_digest = models.BooleanField(
default=True,
verbose_name="Receive Weekly Digests from Communities")
location_change = models.BooleanField(
default=False,
verbose_name="Get Notified on Change in Location for Meetups")
time_change = models.BooleanField(
default=False,
verbose_name="Get Notified on Change in Timings for Meetups")
reminder = models.BooleanField(
default=False,
verbose_name="Get Reminders for rsvp'd Meetups")

def __str__(self):
return "Settings for {0}".format(self.user)
20 changes: 19 additions & 1 deletion systers_portal/users/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from community.utils import create_groups
from community.permissions import groups_templates
from membership.models import JoinRequest
from users.models import SystersUser
from users.models import SystersUser, UserSetting


class SystersUserTestCase(TestCase):
Expand Down Expand Up @@ -216,3 +216,21 @@ def test_str(self):
self.user.last_name = "Bar"
self.user.save()
self.assertEqual(str(self.user), 'Foo Bar')


class UserSettingTestCase(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='foo', password='foobar')
self.systers_user = SystersUser.objects.get(user=self.user)
self.user_settings = UserSetting.objects.get(user=self.systers_user)

def test_create_settings(self):
self.assertEqual(UserSetting.objects.count(), 2)
self.assertEqual(self.systers_user, self.user_settings.user)
self.assertEqual(self.user_settings.weekly_digest, True)
self.assertEqual(self.user_settings.reminder, False)
self.assertEqual(self.user_settings.location_change, False)
self.assertEqual(self.user_settings.time_change, False)

def test_str(self):
self.assertEqual(str(self.user_settings), 'Settings for foo')
4 changes: 2 additions & 2 deletions systers_portal/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class EditSettings(UpdateView, LoginRequiredMixin):
template_name = "users/settings.html"
form_class = EditUserSettings
raise_exception = True
form_valid_message = (u"Settings added Successfully")
form_valid_message = u"Settings updated Successfully"

def get_success_url(self):
return reverse('index')
return reverse('user', kwargs={'username': self.request.user.username})

def get_form_kwargs(self):
kwargs = super(EditSettings, self).get_form_kwargs()
Expand Down

0 comments on commit 48cd42c

Please sign in to comment.