Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(33)  |  Call(33)  |  Derive(0)  |  Import(0)

src/d/j/django-bfm-HEAD/django_bfm/tests/actions.py   django-bfm(Download)
    def test_not_authorized(self):
        r = self.client.post(reverse('bfm_upload'), {'doesnt_matter': 'what'})
        # We should be redirected to login...
        self.assertEqual(r.status_code, 302)
 
        # Sending request without file should fail.
        r = self.client.post(reverse('bfm_upload'), {})
        self.assertEqual(r.status_code, 400)
 
        # Upload file.
        with open(self.uploadable, 'r') as f:
            r = self.client.post("{}?directory=".format(reverse('bfm_upload')),
                                                                {'file': f})
        # Test: 1) Response JSON correctness; 2) Correct file saving;
        self.assertEqual(r.status_code, 200)
        parsed = simplejson.loads(r.content)
        file_path = os.path.join(temp_directory, parsed['filename'])
        self.assertEqual(open(file_path).read(), self.upl_content)
        self.assertEqual(self.got_pre['upload'], 1)
        self.assertEqual(self.got_post['upload'], 1)