def test_it_returns_data_if_no_user(self): ''' A request should indicate if there is no user ''' request = MockRequest(AnonymousUser()) response = data(request) self.assertEqual(response.status_code, 200) self.assertEqual( decode_json_content(response.content)['loggedIn'], False )
def test_empty_string_for_username_of_anon(self): ''' A request should have an empty string as a name if the user was AnonymousUser ''' request = MockRequest(AnonymousUser()) response = data(request) self.assertEqual(response.status_code, 200) self.assertEqual( decode_json_content(response.content)['username'], '' )
def test_it_returns_data_if_a_user(self): ''' A request should indicate if there is a user ''' user = User.objects.create_user( 'john', '*****@*****.**', 'johnpassword' ) request = MockRequest(user) response = data(request) self.assertEqual(response.status_code, 200) self.assertEqual( decode_json_content(response.content)['loggedIn'], True )
def test_it_returns_username(self): ''' A request should have username as name if there is one. ''' user = User.objects.create_user( 'john', '*****@*****.**', 'johnpassword' ) request = MockRequest(user) response = data(request) self.assertEqual(response.status_code, 200) self.assertEqual( decode_json_content(response.content)['username'], 'john' )
def test_user_is_a_customer(self): ''' Returns permissions for a customer ''' user = User.objects.create_user( 'john', '*****@*****.**', 'johnpassword' ) request = MockRequest(user) response = data(request) self.assertEqual(response.status_code, 200) self.assertEqual( decode_json_content(response.content)['isManager'], False ) self.assertEqual( decode_json_content(response.content)['isTeller'], False )
def test_user_is_a_manager(self): ''' return permissions for a manager ''' user = User.objects.create_user( 'john', '*****@*****.**', 'johnpassword' ) user.user_permissions.add(MANAGER) request = MockRequest(user) response = data(request) self.assertEqual(response.status_code, 200) self.assertEqual( decode_json_content(response.content)['isManager'], True ) self.assertEqual( decode_json_content(response.content)['isTeller'], True )