AssertionError: <bound method comment.created_at of > is not an instance of
I am new to python and am trying to learn OOP. I have this mock up quiz that i have been trying to solve. So far am able to pass 5 test
Here is the challenge
Users come in 3 flavors, normal users, moderators, and admins. Normal users can only create new comments, and edit the their own comments. Moderators have the added ability to delete comments (to remove trolls), while admins have the ability to edit or delete any comment.
Users can log in and out, and we track when they last logged in
Comments
Encapsulation of Properties
All classes should have no publicly accessible fields
You should make sure you at least "hide" the required fields, for example, using _name instead of _name. Alternatively, feel free to use a better solution as extra credit.
The method-based API is provided. These must be completed as-is.
Additional methods are allowed, though remember to keep read-only properties read-only.
Instantiation
Classes should be instantiated with properties (as provided), to create instances with values already assigned.
User/Moderator/Admin defaults:
Should be marked as not logged in
Should return None for the last logged in at property
Comment defaults:
Should set the current timestamp for the created at property upon instantiation
Replied To is optional, and should be None if not provided.
Inheritance & Access Control
User
Users can be logged in and out.
When logging in, set the last_logged_in_at timestamp. Do not modify this timestamp when logging out
Users can only edit their own comments
Users cannot delete any comments
Moderator is a User
Moderators can only edit their own comments
Moderators can delete any comments
Admin is both a User and a Moderator
Admins can edit any comments
Admins can delete any comments
Composition
Comments contain a reference to the User who created it (author)
Comments optionally contain a reference to another comment (replied_to)
When converting to a string (to_string), the following format is used:
No replied to:
message + " by " + author.name
With replied to:
message + " by " + author.name + " (replied to " + repliedTo.author.name + ")"
this is my solution
import datetime
class user:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = None
def name(self):
return self.name
def name(self, value):
self.name = value
def is_logged_in(self):
return self.loggedIn
def last_logged_in_at(self):
return self.lastloggedIn
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow()
def log_out(self):
self.loggedIn = False
def can_edit(self, comment):
if comment.author.name == self.name:
return True
else:
return False
def can_delete(self, comment):
return False
# def to_string(self):
# pass
class moderator(user):
def __init__(self, name):
user.__init__(self, name)
def can_delete(self, comment):
return True
class admin(moderator):
def __init__(self, name):
moderator.__init__(self, name)
def can_edit(self, comment):
return True
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now()
self.author = author
self.message = message
self.replied_to = replied_to
def author(self):
return self._author
def author(self, value):
self.author = value
def message(self):
return self.message
def message(self, value):
self.message = value
def created_at(self):
return self.createdAt
def replied_to(self):
return self.replied_to
def replied_to(self, value):
self.replied_to = value
def to_string(self):
if self.replied_to == None:
return self.replied_to + " by " + self.author.name
import unittest
user1 = user('User 1')
mod = moderator('Moderator')
class Test(unittest.TestCase):
def test_instantiation(self):
self.assertEqual(user1.name,'User 1', 'User name is set correctly')
user1.name = 'User 1 Updated'
self.assertEqual(user1.name,'User 1 Updated', 'User name can be updated')
self.assertIsInstance(mod, user, 'Moderator is a user')
Am getting two main errors. the last_logged_in method should return None and the datetime.datetime.now() doesn't seem to be working correctly
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
python-3.x
|
show 1 more comment
I am new to python and am trying to learn OOP. I have this mock up quiz that i have been trying to solve. So far am able to pass 5 test
Here is the challenge
Users come in 3 flavors, normal users, moderators, and admins. Normal users can only create new comments, and edit the their own comments. Moderators have the added ability to delete comments (to remove trolls), while admins have the ability to edit or delete any comment.
Users can log in and out, and we track when they last logged in
Comments
Encapsulation of Properties
All classes should have no publicly accessible fields
You should make sure you at least "hide" the required fields, for example, using _name instead of _name. Alternatively, feel free to use a better solution as extra credit.
The method-based API is provided. These must be completed as-is.
Additional methods are allowed, though remember to keep read-only properties read-only.
Instantiation
Classes should be instantiated with properties (as provided), to create instances with values already assigned.
User/Moderator/Admin defaults:
Should be marked as not logged in
Should return None for the last logged in at property
Comment defaults:
Should set the current timestamp for the created at property upon instantiation
Replied To is optional, and should be None if not provided.
Inheritance & Access Control
User
Users can be logged in and out.
When logging in, set the last_logged_in_at timestamp. Do not modify this timestamp when logging out
Users can only edit their own comments
Users cannot delete any comments
Moderator is a User
Moderators can only edit their own comments
Moderators can delete any comments
Admin is both a User and a Moderator
Admins can edit any comments
Admins can delete any comments
Composition
Comments contain a reference to the User who created it (author)
Comments optionally contain a reference to another comment (replied_to)
When converting to a string (to_string), the following format is used:
No replied to:
message + " by " + author.name
With replied to:
message + " by " + author.name + " (replied to " + repliedTo.author.name + ")"
this is my solution
import datetime
class user:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = None
def name(self):
return self.name
def name(self, value):
self.name = value
def is_logged_in(self):
return self.loggedIn
def last_logged_in_at(self):
return self.lastloggedIn
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow()
def log_out(self):
self.loggedIn = False
def can_edit(self, comment):
if comment.author.name == self.name:
return True
else:
return False
def can_delete(self, comment):
return False
# def to_string(self):
# pass
class moderator(user):
def __init__(self, name):
user.__init__(self, name)
def can_delete(self, comment):
return True
class admin(moderator):
def __init__(self, name):
moderator.__init__(self, name)
def can_edit(self, comment):
return True
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now()
self.author = author
self.message = message
self.replied_to = replied_to
def author(self):
return self._author
def author(self, value):
self.author = value
def message(self):
return self.message
def message(self, value):
self.message = value
def created_at(self):
return self.createdAt
def replied_to(self):
return self.replied_to
def replied_to(self, value):
self.replied_to = value
def to_string(self):
if self.replied_to == None:
return self.replied_to + " by " + self.author.name
import unittest
user1 = user('User 1')
mod = moderator('Moderator')
class Test(unittest.TestCase):
def test_instantiation(self):
self.assertEqual(user1.name,'User 1', 'User name is set correctly')
user1.name = 'User 1 Updated'
self.assertEqual(user1.name,'User 1 Updated', 'User name can be updated')
self.assertIsInstance(mod, user, 'Moderator is a user')
Am getting two main errors. the last_logged_in method should return None and the datetime.datetime.now() doesn't seem to be working correctly
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
python-3.x
1
Your question is way too long for SO. Should you read Minimal, Complete, and Verifiable example before asking. Please, edit your question.
– Rarblack
Nov 21 at 5:04
self.assertIsInstance(mod, user, 'Moderator is a user')
The third argument is a message that is displayed when the assertion fails. You've got it backwards -- it should beModerator is not a user
.
– John Gordon
Nov 21 at 5:13
Your code cannot be python-3.x and python-2.7 at the same time. Please remove one of the tags.
– tripleee
Nov 21 at 5:19
@Rarblack , thank you. Am working on that
– muzz-art
Nov 21 at 5:51
1
I'm not sure I understand the errors you're getting from your unit tests, but I do see some obvious issues in your code. To start with, you're very often using the same name for instance variables and for methods at the same time. That is very unlikely to work as you want it to. You're also defining multiple methods with different signatures, but the same name. That kind of name overloading is allowed in some other languages (like C++), but it doesn't work as you probably intend it to in Python.
– Blckknght
Nov 21 at 5:53
|
show 1 more comment
I am new to python and am trying to learn OOP. I have this mock up quiz that i have been trying to solve. So far am able to pass 5 test
Here is the challenge
Users come in 3 flavors, normal users, moderators, and admins. Normal users can only create new comments, and edit the their own comments. Moderators have the added ability to delete comments (to remove trolls), while admins have the ability to edit or delete any comment.
Users can log in and out, and we track when they last logged in
Comments
Encapsulation of Properties
All classes should have no publicly accessible fields
You should make sure you at least "hide" the required fields, for example, using _name instead of _name. Alternatively, feel free to use a better solution as extra credit.
The method-based API is provided. These must be completed as-is.
Additional methods are allowed, though remember to keep read-only properties read-only.
Instantiation
Classes should be instantiated with properties (as provided), to create instances with values already assigned.
User/Moderator/Admin defaults:
Should be marked as not logged in
Should return None for the last logged in at property
Comment defaults:
Should set the current timestamp for the created at property upon instantiation
Replied To is optional, and should be None if not provided.
Inheritance & Access Control
User
Users can be logged in and out.
When logging in, set the last_logged_in_at timestamp. Do not modify this timestamp when logging out
Users can only edit their own comments
Users cannot delete any comments
Moderator is a User
Moderators can only edit their own comments
Moderators can delete any comments
Admin is both a User and a Moderator
Admins can edit any comments
Admins can delete any comments
Composition
Comments contain a reference to the User who created it (author)
Comments optionally contain a reference to another comment (replied_to)
When converting to a string (to_string), the following format is used:
No replied to:
message + " by " + author.name
With replied to:
message + " by " + author.name + " (replied to " + repliedTo.author.name + ")"
this is my solution
import datetime
class user:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = None
def name(self):
return self.name
def name(self, value):
self.name = value
def is_logged_in(self):
return self.loggedIn
def last_logged_in_at(self):
return self.lastloggedIn
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow()
def log_out(self):
self.loggedIn = False
def can_edit(self, comment):
if comment.author.name == self.name:
return True
else:
return False
def can_delete(self, comment):
return False
# def to_string(self):
# pass
class moderator(user):
def __init__(self, name):
user.__init__(self, name)
def can_delete(self, comment):
return True
class admin(moderator):
def __init__(self, name):
moderator.__init__(self, name)
def can_edit(self, comment):
return True
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now()
self.author = author
self.message = message
self.replied_to = replied_to
def author(self):
return self._author
def author(self, value):
self.author = value
def message(self):
return self.message
def message(self, value):
self.message = value
def created_at(self):
return self.createdAt
def replied_to(self):
return self.replied_to
def replied_to(self, value):
self.replied_to = value
def to_string(self):
if self.replied_to == None:
return self.replied_to + " by " + self.author.name
import unittest
user1 = user('User 1')
mod = moderator('Moderator')
class Test(unittest.TestCase):
def test_instantiation(self):
self.assertEqual(user1.name,'User 1', 'User name is set correctly')
user1.name = 'User 1 Updated'
self.assertEqual(user1.name,'User 1 Updated', 'User name can be updated')
self.assertIsInstance(mod, user, 'Moderator is a user')
Am getting two main errors. the last_logged_in method should return None and the datetime.datetime.now() doesn't seem to be working correctly
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
python-3.x
I am new to python and am trying to learn OOP. I have this mock up quiz that i have been trying to solve. So far am able to pass 5 test
Here is the challenge
Users come in 3 flavors, normal users, moderators, and admins. Normal users can only create new comments, and edit the their own comments. Moderators have the added ability to delete comments (to remove trolls), while admins have the ability to edit or delete any comment.
Users can log in and out, and we track when they last logged in
Comments
Encapsulation of Properties
All classes should have no publicly accessible fields
You should make sure you at least "hide" the required fields, for example, using _name instead of _name. Alternatively, feel free to use a better solution as extra credit.
The method-based API is provided. These must be completed as-is.
Additional methods are allowed, though remember to keep read-only properties read-only.
Instantiation
Classes should be instantiated with properties (as provided), to create instances with values already assigned.
User/Moderator/Admin defaults:
Should be marked as not logged in
Should return None for the last logged in at property
Comment defaults:
Should set the current timestamp for the created at property upon instantiation
Replied To is optional, and should be None if not provided.
Inheritance & Access Control
User
Users can be logged in and out.
When logging in, set the last_logged_in_at timestamp. Do not modify this timestamp when logging out
Users can only edit their own comments
Users cannot delete any comments
Moderator is a User
Moderators can only edit their own comments
Moderators can delete any comments
Admin is both a User and a Moderator
Admins can edit any comments
Admins can delete any comments
Composition
Comments contain a reference to the User who created it (author)
Comments optionally contain a reference to another comment (replied_to)
When converting to a string (to_string), the following format is used:
No replied to:
message + " by " + author.name
With replied to:
message + " by " + author.name + " (replied to " + repliedTo.author.name + ")"
this is my solution
import datetime
class user:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = None
def name(self):
return self.name
def name(self, value):
self.name = value
def is_logged_in(self):
return self.loggedIn
def last_logged_in_at(self):
return self.lastloggedIn
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow()
def log_out(self):
self.loggedIn = False
def can_edit(self, comment):
if comment.author.name == self.name:
return True
else:
return False
def can_delete(self, comment):
return False
# def to_string(self):
# pass
class moderator(user):
def __init__(self, name):
user.__init__(self, name)
def can_delete(self, comment):
return True
class admin(moderator):
def __init__(self, name):
moderator.__init__(self, name)
def can_edit(self, comment):
return True
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now()
self.author = author
self.message = message
self.replied_to = replied_to
def author(self):
return self._author
def author(self, value):
self.author = value
def message(self):
return self.message
def message(self, value):
self.message = value
def created_at(self):
return self.createdAt
def replied_to(self):
return self.replied_to
def replied_to(self, value):
self.replied_to = value
def to_string(self):
if self.replied_to == None:
return self.replied_to + " by " + self.author.name
import unittest
user1 = user('User 1')
mod = moderator('Moderator')
class Test(unittest.TestCase):
def test_instantiation(self):
self.assertEqual(user1.name,'User 1', 'User name is set correctly')
user1.name = 'User 1 Updated'
self.assertEqual(user1.name,'User 1 Updated', 'User name can be updated')
self.assertIsInstance(mod, user, 'Moderator is a user')
Am getting two main errors. the last_logged_in method should return None and the datetime.datetime.now() doesn't seem to be working correctly
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
python-3.x
python-3.x
edited Nov 21 at 6:09
asked Nov 21 at 4:58
muzz-art
14
14
1
Your question is way too long for SO. Should you read Minimal, Complete, and Verifiable example before asking. Please, edit your question.
– Rarblack
Nov 21 at 5:04
self.assertIsInstance(mod, user, 'Moderator is a user')
The third argument is a message that is displayed when the assertion fails. You've got it backwards -- it should beModerator is not a user
.
– John Gordon
Nov 21 at 5:13
Your code cannot be python-3.x and python-2.7 at the same time. Please remove one of the tags.
– tripleee
Nov 21 at 5:19
@Rarblack , thank you. Am working on that
– muzz-art
Nov 21 at 5:51
1
I'm not sure I understand the errors you're getting from your unit tests, but I do see some obvious issues in your code. To start with, you're very often using the same name for instance variables and for methods at the same time. That is very unlikely to work as you want it to. You're also defining multiple methods with different signatures, but the same name. That kind of name overloading is allowed in some other languages (like C++), but it doesn't work as you probably intend it to in Python.
– Blckknght
Nov 21 at 5:53
|
show 1 more comment
1
Your question is way too long for SO. Should you read Minimal, Complete, and Verifiable example before asking. Please, edit your question.
– Rarblack
Nov 21 at 5:04
self.assertIsInstance(mod, user, 'Moderator is a user')
The third argument is a message that is displayed when the assertion fails. You've got it backwards -- it should beModerator is not a user
.
– John Gordon
Nov 21 at 5:13
Your code cannot be python-3.x and python-2.7 at the same time. Please remove one of the tags.
– tripleee
Nov 21 at 5:19
@Rarblack , thank you. Am working on that
– muzz-art
Nov 21 at 5:51
1
I'm not sure I understand the errors you're getting from your unit tests, but I do see some obvious issues in your code. To start with, you're very often using the same name for instance variables and for methods at the same time. That is very unlikely to work as you want it to. You're also defining multiple methods with different signatures, but the same name. That kind of name overloading is allowed in some other languages (like C++), but it doesn't work as you probably intend it to in Python.
– Blckknght
Nov 21 at 5:53
1
1
Your question is way too long for SO. Should you read Minimal, Complete, and Verifiable example before asking. Please, edit your question.
– Rarblack
Nov 21 at 5:04
Your question is way too long for SO. Should you read Minimal, Complete, and Verifiable example before asking. Please, edit your question.
– Rarblack
Nov 21 at 5:04
self.assertIsInstance(mod, user, 'Moderator is a user')
The third argument is a message that is displayed when the assertion fails. You've got it backwards -- it should be Moderator is not a user
.– John Gordon
Nov 21 at 5:13
self.assertIsInstance(mod, user, 'Moderator is a user')
The third argument is a message that is displayed when the assertion fails. You've got it backwards -- it should be Moderator is not a user
.– John Gordon
Nov 21 at 5:13
Your code cannot be python-3.x and python-2.7 at the same time. Please remove one of the tags.
– tripleee
Nov 21 at 5:19
Your code cannot be python-3.x and python-2.7 at the same time. Please remove one of the tags.
– tripleee
Nov 21 at 5:19
@Rarblack , thank you. Am working on that
– muzz-art
Nov 21 at 5:51
@Rarblack , thank you. Am working on that
– muzz-art
Nov 21 at 5:51
1
1
I'm not sure I understand the errors you're getting from your unit tests, but I do see some obvious issues in your code. To start with, you're very often using the same name for instance variables and for methods at the same time. That is very unlikely to work as you want it to. You're also defining multiple methods with different signatures, but the same name. That kind of name overloading is allowed in some other languages (like C++), but it doesn't work as you probably intend it to in Python.
– Blckknght
Nov 21 at 5:53
I'm not sure I understand the errors you're getting from your unit tests, but I do see some obvious issues in your code. To start with, you're very often using the same name for instance variables and for methods at the same time. That is very unlikely to work as you want it to. You're also defining multiple methods with different signatures, but the same name. That kind of name overloading is allowed in some other languages (like C++), but it doesn't work as you probably intend it to in Python.
– Blckknght
Nov 21 at 5:53
|
show 1 more comment
1 Answer
1
active
oldest
votes
Let's start with the first error:
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
ITsays you are passing datetime instance. Let's check:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 11, 21, 10, 28, 26, 996940) # this is datetime instance
what you can do is convert it to string and pass it:
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2018-11-21 06:51:22'
Like:
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
For the second error:
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
You are not setting lastloggedIn:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = lastloggedIn
and same here you are passing an instance:
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 21, 6, 46, 25, 248409)
change it to return the string instead of an instance:
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405512%2fassertionerror-bound-method-comment-created-at-of-solution-comment-object-at%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let's start with the first error:
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
ITsays you are passing datetime instance. Let's check:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 11, 21, 10, 28, 26, 996940) # this is datetime instance
what you can do is convert it to string and pass it:
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2018-11-21 06:51:22'
Like:
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
For the second error:
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
You are not setting lastloggedIn:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = lastloggedIn
and same here you are passing an instance:
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 21, 6, 46, 25, 248409)
change it to return the string instead of an instance:
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
add a comment |
Let's start with the first error:
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
ITsays you are passing datetime instance. Let's check:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 11, 21, 10, 28, 26, 996940) # this is datetime instance
what you can do is convert it to string and pass it:
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2018-11-21 06:51:22'
Like:
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
For the second error:
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
You are not setting lastloggedIn:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = lastloggedIn
and same here you are passing an instance:
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 21, 6, 46, 25, 248409)
change it to return the string instead of an instance:
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
add a comment |
Let's start with the first error:
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
ITsays you are passing datetime instance. Let's check:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 11, 21, 10, 28, 26, 996940) # this is datetime instance
what you can do is convert it to string and pass it:
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2018-11-21 06:51:22'
Like:
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
For the second error:
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
You are not setting lastloggedIn:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = lastloggedIn
and same here you are passing an instance:
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 21, 6, 46, 25, 248409)
change it to return the string instead of an instance:
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
Let's start with the first error:
AssertionError: <bound method comment.created_at of <solution.comment object at 0x7fd5a21d0668>> is not an instance of <class 'datetime.datetime'>
ITsays you are passing datetime instance. Let's check:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2018, 11, 21, 10, 28, 26, 996940) # this is datetime instance
what you can do is convert it to string and pass it:
>>> datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
'2018-11-21 06:51:22'
Like:
class comment:
def __init__(self, author, message, replied_to = None, createdAt = None):
self.createdAt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
For the second error:
AssertionError: <bound method user.last_logged_in_at of <[35 chars]ba8>> != None : Last logged in date is not set by default
You are not setting lastloggedIn:
def __init__(self, name, lastloggedIn = None):
self.name = name
self.loggedIn = False
self.lastloggedIn = lastloggedIn
and same here you are passing an instance:
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 21, 6, 46, 25, 248409)
change it to return the string instead of an instance:
def log_in(self):
self.loggedIn = True
self.lastloggedIn = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
edited Nov 21 at 7:10
answered Nov 21 at 6:49
Rarblack
2,7163925
2,7163925
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405512%2fassertionerror-bound-method-comment-created-at-of-solution-comment-object-at%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Your question is way too long for SO. Should you read Minimal, Complete, and Verifiable example before asking. Please, edit your question.
– Rarblack
Nov 21 at 5:04
self.assertIsInstance(mod, user, 'Moderator is a user')
The third argument is a message that is displayed when the assertion fails. You've got it backwards -- it should beModerator is not a user
.– John Gordon
Nov 21 at 5:13
Your code cannot be python-3.x and python-2.7 at the same time. Please remove one of the tags.
– tripleee
Nov 21 at 5:19
@Rarblack , thank you. Am working on that
– muzz-art
Nov 21 at 5:51
1
I'm not sure I understand the errors you're getting from your unit tests, but I do see some obvious issues in your code. To start with, you're very often using the same name for instance variables and for methods at the same time. That is very unlikely to work as you want it to. You're also defining multiple methods with different signatures, but the same name. That kind of name overloading is allowed in some other languages (like C++), but it doesn't work as you probably intend it to in Python.
– Blckknght
Nov 21 at 5:53