Два дня бился головой о стену, пытаясь понять, почему мой тест не проходит. Я обернул их в str (). Многострочная строка. Просто не могу заставить это пройти. Что мне здесь не хватает. Пожалуйста, помогите.
Это мой первый пост. Так что, если я пропустил в своем посте что-то, что я мог бы сделать лучше, дайте мне знать.
Вот моя модель
class MemberAddress(models.Model):
address_type = models.CharField(max_length=100, default='Home')
address_line_one = models.CharField(max_length=100)
address_line_two = models.CharField(max_length=100, default=None)
city = models.CharField(max_length=50)
state = models.CharField(max_length=50)
zipcode = models.CharField(max_length=50)
UserProfile = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
REQUIRED_FIELDS = ['address_type',
'address_line_one',
'city',
'state',
'zipcode'
]
def __str__(self):
address = self.address_line_one + '\n'
if (self.address_line_two is not None):
address += self.address_line_two + '\n'
address += self.city + ' ' + self.state + ' ' + self.zipcode
return address
Вот мой тест:
def test_member_address_is_created(self):
faker = Faker('en_US')
test_address = MemberAddress(
address_type='Home',
address_line_one=faker.street_address(),
address_line_two=faker.secondary_address(),
city=faker.city(),
state=faker.state(),
zipcode=faker.zipcode(),
UserProfile=self.user
)
test_address.save()
queried_address = MemberAddress.objects.get(id=1)
object_string_test = '{}{}{}{}{} {} {}'.format(
test_address.address_line_one, '\n',
test_address.address_line_two, '\n',
test_address.city, test_address.state, test_address.zipcode)
self.assertEqual(test_address.address_type,
queried_address.address_type)
self.assertEqual(test_address.address_line_one,
queried_address.address_line_one)
self.assertEqual(test_address.address_line_two,
queried_address.address_line_two)
self.assertEqual(test_address.city,
queried_address.city)
self.assertEqual(test_address.state,
queried_address.state)
self.assertEqual(test_address.state,
queried_address.state)
self.assertEqual(test_address.zipcode,
queried_address.zipcode)
self.assertEqual(test_address.UserProfile,
queried_address.UserProfile)
self.assertEqual(object_string_test, test_address) # <---- Failing Test ----<<<
Вот моя ошибка:
python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
.....F..
======================================================================
FAIL: test_member_address_is_created (cms.tests.test_models.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/bhwood/code/glidden_app/cms/tests/test_models.py", line 115, in test_member_address_is_created
self.assertEqual(object_string_test, test_address)
AssertionError: '88043 Jason Place\nSuite 703\nWest Markmouth West Virginia 90857' != <MemberAddress: 88043 Jason Place
Suite 703
West Markmouth West Virginia 90857>
----------------------------------------------------------------------
Ran 8 tests in 2.404s
FAILED (failures=1)
Destroying test database for alias 'default'...