Skip to content

Commit

Permalink
Merge pull request #18 from Lemmah/develop
Browse files Browse the repository at this point in the history
Developments on User Feature
  • Loading branch information
Lemmah authored Jul 24, 2017
2 parents d231df8 + e693f8f commit e8cef0b
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/bucketlist/bucketlist_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def change_bucketlist_details(self, target_bucketlist, new_bucketlist_descriptio

def delete_bucketlist(self, bucketlist):
''' Functionality to delete bucketlist '''
target_bucketlist = bucketlist
target_bucketlist = bucketlist.name
self.available_bucketlists.remove(bucketlist.name)
bucketlist.name = None
return "Successfully deleted {} bucketlist".format(target_bucketlist)
73 changes: 73 additions & 0 deletions app/tests/test_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Tests for the class user

import unittest
from app.user.user import User
from app.bucketlist.bucketlist_controller import BucketListController
from app.bucketlist.bucketlist import BucketList


class TestUser(unittest.TestCase):
'''
A user is a bucketlist controller
A user is has a name, email and password
A user can do everything a bucketlist controller does
'''

def setUp(self):
''' Set up reusable variables and instances '''
self.user_details = ("jnlemayian@gmail.com", "Password", "James Lemayian")
self.user_instance = User(*self.user_details)
self.bucketlist_details = ("ItemName", "Description: optional")
self.bucketlist = BucketList(*self.bucketlist_details, owner=self.user_details[0])

# 1. Test structure and user instance creation
def test_user_inherits_bucketlistcontroler(self):
''' Test that user inherits bucketlist controller '''
# Assert that it's a user instance
self.assertEqual(isinstance(self.user_instance, User), True)
# Assert that it's also a bucketlist controller instance
self.assertEqual(isinstance(self.user_instance, BucketListController), True)

def test_user_has_all_properties(self):
''' Ensure user has name, email, password '''
self.assertEqual(self.user_instance.name, self.user_details[2])
self.assertEqual(self.user_instance.email, self.user_details[0])
self.assertEqual(self.user_instance.password, self.user_details[1])

def test_user_representation(self):
''' Assert that __repr__ function returns a useful object representation '''
self.assertEqual(str(self.user_instance), "James Lemayian")

## The user is just an extension of the bucketlist controller
# 2. Test bucketlist controller operations
def test_user_can_create_bucketlist(self):
''' Asserting that a user can create a bucketlist '''
new_bucketlist_details = ("NewName", "Description: Optional")
new_bucketlist = self.user_instance.add_bucketlist(new_bucketlist_details)
self.assertEqual(isinstance(new_bucketlist[0], BucketList), True)
self.assertEqual(new_bucketlist_details[0] in self.user_instance.available_bucketlists, True)
self.assertEqual(new_bucketlist[1], "{} bucketlist has been created".format(new_bucketlist_details[0]))

def test_user_instance_can_update_bucketlist(self):
''' Asserting that user can change bucketlist details '''
# rename, change details
new_name, new_description = "NewBucket", "NewDetails: This is new"
old_name = self.bucketlist.name
rename = self.user_instance.rename_bucketlist(self.bucketlist, new_name)
self.assertEqual(rename, "{} bucketlist has been renamed to {}".format(old_name, new_name))
self.assertEqual(self.bucketlist.name, new_name)
change_details = self.user_instance.change_bucketlist_details(self.bucketlist, new_description)
self.assertEqual(change_details, "{} has been updated accordingly".format(self.bucketlist.name))
self.assertEqual(self.bucketlist.description, new_description)

def test_user_instance_can_delete_bucketlist(self):
''' Asserting that a user can delete a bucketlist '''
# add set up test bucketlist to list of available bucketlists
self.user_instance.available_bucketlists.append(self.bucketlist.name)
# capture bucketlist name before deleting it
bucketlist_name = self.bucketlist.name
self.assertEqual(self.bucketlist.name in self.user_instance.available_bucketlists, True)
delete_bucketlist = self.user_instance.delete_bucketlist(self.bucketlist)
self.assertEqual(delete_bucketlist, "Successfully deleted {} bucketlist".format(bucketlist_name))
self.assertEqual(self.bucketlist.name not in self.user_instance.available_bucketlists, True)
self.assertEqual(str(self.bucketlist), 'Bucketlist does not exist')
Empty file added app/user/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions app/user/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Modelling a user
# A user is a bucketlist controller so,

from app.bucketlist.bucketlist_controller import BucketListController

class User(BucketListController):
''' A user who is also a bucketlist controller '''
def __init__(self, email, password, name):
''' Construct an instance of a user '''
BucketListController.__init__(self, email)
self.name = name
self.email = email
self.password = password

def __repr__(self):
''' A representation of the user object '''
return "{}".format(self.name)

0 comments on commit e8cef0b

Please sign in to comment.