Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Santos
34,969 PointsI do not get this
I am trying to make this method for this test but I don't understand what I need to do with the mailto() method in models.py. @Kenneth Love Here is my tests.py
from django.test import TestCase
from .models import Writer
class WriterModelTestCase(TestCase):
'''Tests for the Writer model'''
def test_create_writer(self):
writer = Create.objects.create(
name = "Daniel Santos",
email = "dsantosp12@gmail.com",
bio = "This is my bio!"
)
ema = mailto()
self.assertIn(writer.email, ema)
from django.db import models
class Article(models.Model):
headline = models.CharField(max_length=255)
publish_date = models.DateTimeField()
content = models.TextField()
writer = models.ForeignKey('Writer')
def __str__(self):
return self.headline
class Writer(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField()
bio = models.TextField()
def __str__(self):
return self.name
def mailto(self):
return '{} <{}>'.format(self.name, self.email)
2 Answers
Ken Alger
Treehouse TeacherDaniel;
Here is your test code:
class WriterModelTestCase(TestCase):
'''Tests for the Writer model'''
def test_create_writer(self):
writer = Create.objects.create(
name = "Daniel Santos",
email = "dsantosp12@gmail.com",
bio = "This is my bio!"
)
ema = mailto()
self.assertIn(writer.email, ema)
One other thing I missed previously, sorry, is that when you are defining writer
we want it to create a Writer
object, correct? I'm not sure what you are referencing with a Create
object.
For the actual test, assertIn()
follows the convention of assertIn(a, b)
and will test if a
is in b
. Therefore, we need to check if writer.email
is contained in the results of the mailto()
function. Take another look at models.py
and see if you can see how we can access that information inside the Writer
model.
Post back if you are still stuck,
Ken
Daniel Santos
34,969 PointsI am sorry but I don't know. I am so upset. I fixed the the Create object, it was supposed to be Writer.objects.create, but I am stuck after that.
Daniel Santos
34,969 PointsAfter reading careful your answer, and looking at the docs for asserts I finally got it! Thanks a lot.
Here is the answer if anyone need it later.
from django.test import TestCase
from .models import Writer
class WriterModelTestCase(TestCase):
'''Tests for the Writer model'''
def test_create_writer(self):
writer = Writer.objects.create(
name="Daniel",
email="dsantosp12@me.com",
bio="This is a bio"
)
self.assertIn(writer.email, writer.mailto())
Ken Alger
Treehouse TeacherNice work, way to stick with it.
Ken
Ken Alger
Treehouse TeacherDaniel;
You are assigning ema
to a method call, but not telling it on which object it is associated. Also, try putting that info directly into the assertIn
test without assigning it to a variable.
Post back if you are still stuck.
Ken
Daniel Santos
34,969 PointsI am still stuck >:( I might have to check Python Test course again.
Daniel Santos
34,969 PointsKen Alger can you give me another hint?
Daniel Santos
34,969 PointsDaniel Santos
34,969 PointsKenneth Love ?