Hi Karen,

You're right, I had some unnecessary lines that I used only for unittest. I
commented them out now. Printing response['location'] gives me this:

http://testserver/myflow/experiment/1/

You're also right that there is no Redirect in my view, so I don't know
where that is coming from. I guess I'll have to figure it out, because it
seems to be the key to the problem.

Thanks for the reply,
Paulo Almeida

On Tue, Aug 4, 2009 at 6:18 PM, Karen Tracey <kmtra...@gmail.com> wrote:

> On Tue, Aug 4, 2009 at 12:26 PM, palmeida <igcbioinformat...@gmail.com>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']
>
>
> Note fixtures will not be loaded when you run this as a unittest.TestCase.
>
>
>>
>>    def setUp(self):
>>        self.client = Client()
>>        try:
>>            User.objects.create_user('user', 'm...@nowhere.com', 'user')
>>        except IntegrityError:
>>            pass
>>        self.client.login(username='user', password='user')
>>
>
> Is there a reason, other than to allow this to run as a unittest.TestCase,
> why are you setting client yourself in setUp()?  That's done for you by
> Django's TestCase.  If you are going to be using fixtures and the test
> Client, this really should be a django.test.TestCase.  I am not sure that
> going down the road of seeing if you can't get it to run as a
> unittest.TestCase by manually doing in the test things that
> django.test.TestCase also does is the best way of debugging whatever issue
> the test is having when running as a django.test.TestCase.  I would back up
> and take out anything you have added that allows this to run as a
> unittest.TestCase and start over with trying to debug the real issue
> directly.
>
>
>>
>>    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.
>
>
> 302 is a redirect.  It would be useful to know where it's trying to
> redirect to.  For that, you could put a:
>
> print response['location']
>
> into the test.
>
>
>> 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.
>>
>
> Since your view below, from a quick scan, doesn't ever return a redirect
> your GET is apparently being routed to some other view entirely.  I'd guess
> that view is including all of this other stuff in its context.
>
>
>>
>> This is the relevant line from urls.py:
>>
>> (r'^experiment/(?P<experiment_id>\d+)$',
>>     'bioinformatics.myflow.views.view_experiment'),
>>
>
> I cannot recreate what you are seeing based on just this information.  I
> suspect there is more to your urls.py, or something, that is coming into
> play.  Finding out where you are getting redirected to would be a first step
> in figuring out what is going wrong.
>
> Karen
>
>
>> 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
>>
>>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to