class HeadphonesCommentTest(TestCase):
    def setUp(self):
        self.comment = HeadphonesCommentFactory()

    def test_updated_at(self):
        then = timezone.now()
        # Upon saving, updated_at field is updated
        self.comment.save()
        assert_true(self.comment.updated_at > then)

    def test_device_updated_at(self):
        then = timezone.now()
        self.comment.save()
        assert_true(self.comment.device.updated_at > then)
class HeadphonesCommentTest(TestCase):
    def setUp(self):
        self.comment = HeadphonesCommentFactory()

    def test_updated_at(self):
        then = timezone.now()
        # Upon saving, updated_at field is updated
        self.comment.save()
        assert_true(self.comment.updated_at > then)

    def test_device_updated_at(self):
        then = timezone.now()
        self.comment.save()
        assert_true(self.comment.device.updated_at > then)
 def test_can_edit_headphones_comment(self):
     # a device is created
     device = HeadphonesFactory()
     # it has a comment
     comment = HeadphonesCommentFactory(device=device,
                                     user=self.experimenter.user)
     # goes to detail page
     res = self.app.get('/devices/headphones/{pk}/'.format(pk=device.pk),
                                                 user=self.experimenter.user)
     # can see the comment
     assert_in(comment.text, res)
     # clicks the edit link
     res = res.click('Edit')
     # sees a form
     assert_in('Edit comment', res)
     form = res.forms['id-edit_comment_form']
     # changes the comment text
     form['text'] = 'new text'
     # submits the form
     res = form.submit().follow()
     # back at the detail page
     assert_equal(res.request.path, 
                 '/devices/headphones/{pk}/'.format(pk=device.pk))
     # sees the new comment text
     assert_in('new text', res)
 def test_can_delete_headphones_comment(self):
     device = HeadphonesFactory()
     comment = HeadphonesCommentFactory(device=device, 
                                 user=self.experimenter.user)
     self._test_delete_comment(device, comment,
                 detail_url='/devices/headphones/{pk}/'.format(pk=device.pk),
                 delete_url=reverse('comments:headphones_delete',
                                 args=(device.pk, comment.pk))
     )
 def setUp(self):
     self.comment = HeadphonesCommentFactory()
 def setUp(self):
     self.comment = HeadphonesCommentFactory()