python, please
Write a class called User which will be used to represent a user of our Music Library web application. The constructor of this class requires user_id, a non-negative integer and two string arguments, username, and password. Internally, the user class stores a list of tracks a user liked (objects of class Track) as well as a list of comments the user has written (objects of class Review). In summary, these are the read only attributes (implement access via Python property mechanism) that are required:
The following methods have to be correctly implemented for the User class:
We will test this class with a number of mostly hidden unit tests.
Note: you have to copy four of the classes we have already developed (Artist, Album, Track, Review) into the answer window as well, since the User class depends on them.
Some example test cases (may not cover all hidden test cases) -
# Invalid ID type raises error
# Test ID less than 0 raises error
# Test username is all lowercase
# Invalid username type sets username to None
# Invalid password type set password to None
# Password length < 7 sets password to None
# Password of length 7 sets the password correctly
# Check equality with different types
# Test users are successfully added and removed from the set.
# Test it does not add review of invalid types
# Test it does not add the same review twice
# Test removing non-existing review does nothing
For example:
Test | Result |
---|---|
user1 = User(123, 'Shyamli', 'pw12345') user2 = User(345, 'asma', 'pw67890') user3 = User(567, 'Daniel', 'pw87465') print(user1) print(user2) print(user3) |
<User shyamli, user id = 123> <User asma, user id = 345> <User daniel, user id = 567> |