Hi Alex,
When I do that I get a 404 instead of a 302. I also tried changing urls.py
to have a trailing slash but that also gives me a 404. Byt the way, one of
the variables I get in response.context is:
{'request_path': u'/myflow/experiment/1/'}
Thanks for the reply,
Paulo
On Tue, Aug 4, 2009 at 5:31 PM, Alex Gaynor <[email protected]> wrote:
>
> On Tue, Aug 4, 2009 at 11:26 AM, palmeida<[email protected]>
> wrote:
> >
> > Hi,
> >
> > I'm running a test that fails when using Django's TestCase class, but
> > not when running TestCase from unittest. This is my test class:
> >
> > class LoggedInUser(TestCase):
> > fixtures = ['myflow']
> > def setUp(self):
> > self.client = Client()
> > try:
> > User.objects.create_user('user', '[email protected]', 'user')
> > except IntegrityError:
> > pass
> > self.client.login(username='user', password='user')
> >
> > def test_experiment_view(self):
> > response = self.client.get('/myflow/experiment/1')
> > print response.context
> > self.failUnlessEqual(response.status_code, 200)
> >
> > It fails with:
> >
> > AssertionError: 302 != 200
> >
> > when using Django's TestCase class, but everything is fine when using
> > unittest. Also, when it fails everything in response seems fine except
> > for response.context (and response.content, of course).
> > response.context gets lots of variables, like MEDIA_URL, LANGUAGES and
> > others. I have no idea where that is coming from.
> >
> > This is the relevant line from urls.py:
> >
> > (r'^experiment/(?P<experiment_id>\d+)$',
> > 'bioinformatics.myflow.views.view_experiment'),
> >
> > And this is the view:
> >
> > def view_experiment(request, experiment_id):
> > contact = request.user.id
> > # Filtering on contact and pk to ensure users can only see their
> > own data
> > exp = get_object_or_404(Experiment.objects.filter
> > (exp_contact=contact),
> > pk=experiment_id)
> >
> > list = generate_list()
> >
> > files = exp.fcs_set.exclude(name__startswith='myflow_meta')
> > num_files = len(files)
> > files = files.order_by('btim')
> > fcs_list = paginate(files,'fcs_per_page',request)
> > # Create variable to include (or not) subset column in fcs file
> > list
> > if len(subsets) > 1:
> > subset_header = True
> > else:
> > subset_header = False
> > return render_to_response('myflow/view_experiment.html',
> > {'experiment': exp,
> > 'subsets': subsets,
> > 'parameters': list,
> > 'num_files': num_files,
> > 'fcs_list': fcs_list,
> > 'subset_header': subset_header
> > }
> > )
> >
> > Thanks for any help. I'm not sure what I can do next to find out what
> > is going on.
> > Paulo Almeida
> >
> > >
> >
>
> It looks like you have teh APPEND_SLASH setting set to True (the
> default), so Django adds a / to the end of that URL. Try righting the
> test to that URL with a trailing slash and see if it works.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---