Exemplo n.º 1
0
 def test_change_username_method_with_user_id_not_included_in_library_records_should_return_message(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.change_username(13, 'George')
     self.assertEqual(result, 'There is no user with id = 13!')
Exemplo n.º 2
0
 def test_remove_user_method_with_user_not_registered_should_return_message(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.remove_user(p)
     self.assertEqual(result, 'We could not find such user to remove!')
Exemplo n.º 3
0
 def test_remove_user_method_with_valid_data_should_update_library_records_properly(
         self):
     user = User(12, 'Valentina')
     library = Library()
     library.add_user(user)
     library.add_user(User(13, 'Peter'))
     library.remove_user(user)
     self.assertEqual(library.user_records[0].__str__(), '13, Peter, []')
Exemplo n.º 4
0
 def test_change_username_method_with_valid_data_should_return_message_and_update_library_records(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.change_username(12, 'Violeta')
     self.assertEqual(
         result, 'Username successfully changed to: Violeta for userid: 12')
     self.assertEqual(library.user_records[0].__str__(), '12, Violeta, []')
Exemplo n.º 5
0
 def test_change_username_method_with_user_id_included_in_library_records_but_provided_new_username_is_the_same_should_return_message(
         self):
     v = User(12, 'Valentina')
     p = User(13, 'Peter')
     library = Library()
     library.add_user(v)
     result = library.change_username(12, 'Valentina')
     self.assertEqual(
         result,
         'Please check again the provided username - it should be different than the username used so far!'
     )
Exemplo n.º 6
0
 def test_add_user_already_registered_in_the_library_should_return_message(
         self):
     user = User(12, 'Valentina')
     library = Library()
     library.add_user(user)
     result = library.add_user(user)
     self.assertEqual(
         result, 'User with id = 12 already registered in the library!')
Exemplo n.º 7
0
 def test_get_book_method_with_book_already_rented_should_return_a_message(
         self):
     self.library.books_available.update({
         'J.K.Rowling': [
             'Harry Potter and the Philosopher\'s Stone',
             'Harry Potter and the Philosopher\'s Stone',
             'Harry Potter and the Deathly Hallows',
             'Harry Potter and the Order of the Phoenix'
         ]
     })
     self.user.get_book('J.K.Rowling',
                        'Harry Potter and the Deathly Hallows', 17,
                        self.library)
     second_user = User(13, 'Peter')
     result = second_user.get_book('J.K.Rowling',
                                   'Harry Potter and the Deathly Hallows',
                                   17, self.library)
     self.assertEqual(
         result,
         'The book "Harry Potter and the Deathly Hallows" is already rented and will be available in 17 days!'
     )
     self.assertEqual(self.user.books,
                      ["Harry Potter and the Deathly Hallows"])
     self.assertEqual(second_user.books, [])
     self.assertEqual(
         self.library.rented_books,
         {'Valentina': {
             'Harry Potter and the Deathly Hallows': 17
         }})
     self.assertEqual(
         self.library.books_available, {
             'J.K.Rowling': [
                 'Harry Potter and the Philosopher\'s Stone',
                 'Harry Potter and the Philosopher\'s Stone',
                 'Harry Potter and the Order of the Phoenix'
             ]
         })
from project.library import Library
from project.user import User

user = User(12, 'Peter')
library = Library()
library.add_user(user)
print(library.add_user(user))
library.remove_user(user)
print(library.remove_user(user))
library.add_user(user)
print(library.change_username(2, 'Igor'))
print(library.change_username(12, 'Peter'))
print(library.change_username(12, 'George'))

[
    print(
        f'{user_record.user_id}, {user_record.username}, {user_record.books}')
    for user_record in library.user_records
]
library.books_available.update({
    'J.K.Rowling': [
        'The Chamber of Secrets', 'The Prisoner of Azkaban',
        'The Goblet of Fire', 'The Order of the Phoenix',
        'The Half-Blood Prince', 'The Deathly Hallows'
    ]
})

user.get_book('J.K.Rowling', 'The Deathly Hallows', 17, library)
print(library.books_available)
print(library.rented_books)
print(user.books)
Exemplo n.º 9
0
from flask import Blueprint, request, render_template, url_for, flash, make_response, redirect
from project.pool import Pool
from project.bracket import Bracket
from project.user import User
import datetime

bracket_blueprint = Blueprint('bracket', __name__, template_folder='templates')

bracket = Bracket()
pool = Pool()
user = User()


## show brackets for display or editing
@bracket_blueprint.route('/bracket/<bracket_type_label>/<user_token>',
                         methods=['GET', 'POST', 'PUT'])
def user_bracket(user_token, bracket_type_label):
    ''' Show the user bracket form '''

    # check to see if we are the admin/master bracket
    admin_user_token = user.get_admin_edit_token()
    is_admin = 0

    # if the user token equals the admin token
    if admin_user_token == user_token:
        is_admin = 1

    # check pool status
    pool_name = pool.get_pool_name()
    pool_status = pool.check_pool_status()
Exemplo n.º 10
0
 def setUp(self):
     self.user = User(12, 'Valentina')
     self.library = Library()
Exemplo n.º 11
0
from project.library import Library
from project.user import User

# TODO: Fix if needed- Users not added and removed from the library can access it

user = User(12, 'Peter')
user2 = User(13, 'Simo')
user3 = User(14, 'Boris')

library = Library()

library.books_available.update({
    'J.K.Rowling': [
        'The Chamber of Secrets', 'The Prisoner of Azkaban',
        'The Goblet of Fire', 'The Order of the Phoenix',
        'The Half-Blood Prince', 'The Deathly Hallows'
    ]
})

library.add_user(user)
print(library.remove_user(user))
print(library.remove_user(user))
# print(library.change_username(12, "Asen"))
# print(user.get_book("J.K.Rowling", 'The Chamber of Secrets', 10, library))
# print(user.get_book("J.K.Rowling", 'The Deathly Hallows', 12, library))
# print(user2.get_book("J.K.Rowling", 'The Order of the Phoenix', 14, library))
# print(library.rented_books)
print(user.info())