Skip to content

Commit

Permalink
Merge pull request #1074 from 18F/mgwalker/add-is-active
Browse files Browse the repository at this point in the history
Add is_active property to UserData model
  • Loading branch information
Jkrzy authored May 1, 2020
2 parents b2c9f8f + ee4aa8e commit fed08b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions tock/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class UserDataSerializer(serializers.Serializer):
user = serializers.StringRelatedField()
current_employee = serializers.BooleanField()
is_18f_employee = serializers.BooleanField()
is_active = serializers.BooleanField()
is_billable = serializers.BooleanField()
unit = serializers.StringRelatedField()
organization = serializers.StringRelatedField()
Expand Down
4 changes: 4 additions & 0 deletions tock/employees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ class Meta:
def __str__(self):
return '{0}'.format(self.user)

@property
def is_active(self):
return self.user.is_active

@property
def is_billable(self):
"""
Expand Down
23 changes: 22 additions & 1 deletion tock/employees/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ class UserDataTests(TestCase):
def setUp(self):
# Create regular_user.
self.regular_user = User.objects.create(
username='aaron.snow',
username='brian.whittaker',
is_superuser=True,
is_staff=True,
is_active=True
)
self.inactive_user = User.objects.create(
username='aaron.snow',
is_superuser=True,
is_staff=True,
is_active=False
)
# Create Organization.
self.regular_user_org = Organization.objects.create(
name='18F',
Expand All @@ -78,6 +84,15 @@ def setUp(self):
organization=self.regular_user_org,
unit=self.regular_user_unit
)
self.inactive_user_userdata = UserData.objects.create(
user=self.inactive_user,
start_date= datetime.date(2014, 1, 1),
end_date=datetime.date(2100, 1, 1),
is_18f_employee=True,
current_employee=True,
organization=self.regular_user_org,
unit=self.regular_user_unit
)
# Create a sample reporting period
self.reporting_period = ReportingPeriod.objects.create(
start_date=datetime.date(2015, 1, 1),
Expand Down Expand Up @@ -118,6 +133,12 @@ def test_is_late(self):
userdata.save()
self.assertEqual(userdata.is_late, False)

def test_is_active(self):
userdata = self.regular_user_userdata
self.assertEqual(userdata.is_active, True)
userdata = self.inactive_user_userdata
self.assertEqual(userdata.is_active, False)

def test_organization_name(self):
"""
Check to see if we can get organization name and unit correctly.
Expand Down

0 comments on commit fed08b7

Please sign in to comment.