How to use project method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_views.py

Source:test_views.py Github

copy

Full Screen

...12class ProjectDetailViewTestCase(ViewTestMixin, ProjectBaseTestCase):13 url_name = 'project-detail'14 def setUp(self):15 self.user = self.create_user(data={'password': 'password'})16 self.project = self.create_project(user=self.user)17 # Status is set to DRAFT on first save. Needs to be published for the18 # detail view to display the project.19 self.project.status = CONTENT_STATUS_PUBLISHED20 self.project.save()21 super(ProjectDetailViewTestCase, self).setUp()22 def get_url_args(self):23 return (self.project.slug,)24 def test_draft_hidden_other_user(self):25 other_user = self.create_user(data={'password': 'password'})26 # Project status is draft27 self.project.status = CONTENT_STATUS_DRAFT28 self.project.save()29 self.client.login(username=other_user.username, password='password')30 response = self.client.get(self.url)31 self.assertEqual(response.status_code, 404)32 # Project status is published, but publish_date is in the future33 self.project.status = CONTENT_STATUS_PUBLISHED34 self.project.publish_date = now() + timedelta(minutes=1)35 self.project.save()36 response = self.client.get(self.url)37 self.assertEqual(response.status_code, 404)38 def test_draft_visible_projectuser(self):39 # Project status is draft40 self.project.status = CONTENT_STATUS_DRAFT41 self.project.save()42 self.client.login(username=self.user.username, password='password')43 response = self.client.get(self.url)44 self.assertEqual(response.status_code, 200)45 # Project status is published, but publish_date is in the future46 self.project.status = CONTENT_STATUS_PUBLISHED47 self.project.publish_date = now() + timedelta(minutes=1)48 self.project.save()49 response = self.client.get(self.url)50 self.assertEqual(response.status_code, 200)51 def test_draft_visible_superuser(self):52 super_user = self.create_superuser(data={'password': 'password'})53 # Project status is draft54 self.project.status = CONTENT_STATUS_DRAFT55 self.project.save()56 self.client.login(username=super_user.username, password='password')57 response = self.client.get(self.url)58 self.assertEqual(response.status_code, 200)59 # Project status is published, but publish_date is in the future60 self.project.status = CONTENT_STATUS_PUBLISHED61 self.project.publish_date = now() + timedelta(minutes=1)62 self.project.save()63 response = self.client.get(self.url)64 self.assertEqual(response.status_code, 200)65 def test_bad_slug(self):66 response = self.client.get(reverse(self.url_name, args=['bad-slug']))67 self.assertEqual(response.status_code, 404)68class ProjectListViewTestCase(ViewTestMixin, ProjectBaseTestCase):69 url_name = 'project-list'70 def setUp(self):71 self.user = self.create_user(data={'password': 'password'})72 self.project = self.create_project(73 user=self.user, status=CONTENT_STATUS_PUBLISHED74 )75 super(ProjectListViewTestCase, self).setUp()76 def test_hide_unpublished(self):77 self.client.login(username=self.user.username, password='password')78 self.project.status = CONTENT_STATUS_DRAFT79 self.project.save()80 response = self.client.get(self.url)81 projects = response.context['projects']82 self.assertQuerysetEqual(projects, [])83 def test_show_unpublished_to_superusers(self):84 super_user = self.create_superuser(data={'password': 'password'})85 self.client.login(username=super_user.username, password='password')86 self.project.status = CONTENT_STATUS_DRAFT87 self.project.save()88 response = self.client.get(self.url)89 projects = response.context['projects']90 self.assertEquals(list(projects), [self.project])91class ProjectCreateEditTestCase(AuthViewMixin, ProjectBaseTestCase):92 url_name = 'project-create-edit'93 def setUp(self):94 super(ProjectCreateEditTestCase, self).setUp()95 self.project = self.create_project(96 user=self.user, status=CONTENT_STATUS_PUBLISHED97 )98 def get_edit_url(self, project_slug=''):99 """100 self.url points to using the view for creating a new project. Use101 this helper to create a link to the edit view.102 """103 return reverse(104 self.url_name, args=(project_slug or self.project.slug,)105 )106 def test_other_user_cannot_edit(self):107 other_user = self.create_user(data={'password': 'password'})108 self.client.login(username=other_user.username, password='password')109 url = self.get_edit_url()110 response = self.client.get(url)111 self.assertEqual(response.status_code, 403)112 def test_superuser_can_edit(self):113 super_user = self.create_superuser(data={'password': 'password'})114 self.client.login(username=super_user.username, password='password')115 url = self.get_edit_url()116 response = self.client.get(url)117 self.assertEqual(response.status_code, 200)118 def test_bad_slug(self):119 url = self.get_edit_url('bad-slug')120 response = self.client.get(url)121 self.assertEqual(response.status_code, 404)122 def test_create_valid(self):123 form_data = {124 'title': 'new-project',125 'tldr': self.get_random_string(),126 'categories': [self.create_project_category().id],127 'save': 'value',128 }129 response = self.client.post(self.url, form_data, follow=True)130 new_project = Project.objects.get(slug='new-project')131 url, status_code = response.redirect_chain[0]132 expected_url = reverse(133 'project-detail', args=[new_project.slug]134 )135 self.assertEqual(status_code, 302)136 self.assertTrue(expected_url in url,137 "Didn't redirect to {0}, redirected to {1}".format(expected_url, url)138 )139 def test_create_valid_and_add_steps(self):140 form_data = {141 'title': 'new-project',142 'tldr': self.get_random_string(),143 'categories': [self.create_project_category().id],144 'save-add-step': 'value',145 }146 response = self.client.post(self.url, form_data, follow=True)147 new_project = Project.objects.get(slug='new-project')148 url, status_code = response.redirect_chain[0]149 expected_url = reverse(150 'project-step-create-edit', args=[new_project.slug]151 )152 self.assertEqual(status_code, 302)153 self.assertTrue(expected_url in url,154 "Didn't redirect to {0}, redirected to {1}".format(expected_url, url)155 )156 def test_create_invalid(self):157 response = self.client.post(self.url, {'title': ''})158 project_form = response.context['project_form']159 self.assertEqual(response.status_code, 200)160 self.assertTrue(project_form.errors)161 def test_edit_valid_form(self):162 form_data = {163 'title': 'current-project',164 'tldr': self.get_random_string(),165 'categories': [self.create_project_category().id]166 }167 response = self.client.post(self.get_edit_url(), form_data, follow=True)168 current_project = Project.objects.get(title='current-project')169 url, status_code = response.redirect_chain[0]170 expected_url = reverse('project-detail', args=[current_project.slug])171 self.assertEqual(status_code, 302)172 self.assertTrue(expected_url in url,173 "Didn't redirect to {0}, redirected to {1}".format(expected_url, url)174 )175 def test_edit_invalid_form(self):176 response = self.client.post(self.get_edit_url(), {'title': ''})177 project_form = response.context['project_form']178 self.assertEqual(response.status_code, 200)179 self.assertTrue(project_form.errors)180 def test_edit_form_wrong_user(self):181 other_user = self.create_user(data={'password': 'password'})182 self.client.login(username=other_user.username, password='password')183 form_data = {184 'title': self.get_random_string(),185 'tldr': self.get_random_string(),186 'categories': [self.create_project_category().id]187 }188 response = self.client.post(self.get_edit_url(), form_data)189 self.assertEqual(response.status_code, 403)190class ProjectStepCreateEditTestCase(AuthViewMixin, ProjectBaseTestCase):191 url_name = 'project-step-create-edit'192 def setUp(self):193 self.project = self.create_project(status=CONTENT_STATUS_PUBLISHED)194 super(ProjectStepCreateEditTestCase, self).setUp()195 # AuthViews create and auto-login a user. Set the project to belong to196 # this user197 self.project.user = self.user198 self.project.save()199 def get_url_args(self):200 """ Sets the args for the create project step url set in self.url """201 return (self.project.slug,)202 def get_edit_url(self, project_slug, step_order):203 """204 self.url points to using the view for creating a new step. Use this205 helper to create a link to the edit view.206 """207 return reverse(self.url_name, args=(project_slug, step_order))208 def test_other_user_cannot_edit(self):209 other_user = self.create_user(data={'password': 'password'})210 self.client.login(username=other_user.username, password='password')211 project_step = self.create_project_step(project=self.project)212 url = self.get_edit_url(self.project.slug, project_step._order)213 response = self.client.get(url)214 self.assertEqual(response.status_code, 403)215 def test_superuser_can_edit(self):216 super_user = self.create_superuser(data={'password': 'password'})217 self.client.login(username=super_user.username, password='password')218 project_step = self.create_project_step(project=self.project)219 url = self.get_edit_url(self.project.slug, project_step._order)220 response = self.client.get(url)221 self.assertEqual(response.status_code, 200)222 def test_bad_project_slug(self):223 project_step = self.create_project_step(project=self.project)224 url = self.get_edit_url('bad-slug', project_step._order)225 response = self.client.get(url)226 self.assertEqual(response.status_code, 404)227 def test_bad_order_number(self):228 project_step = self.create_project_step(project=self.project)229 url = self.get_edit_url(self.project.slug, 4)230 response = self.client.get(url)231 self.assertEqual(response.status_code, 404)232 def test_create_valid(self):233 form_data = {234 'title': self.get_random_string(),235 'content': self.get_random_string(),236 }237 response = self.client.post(self.url, form_data)238 self.assertEqual(response.status_code, 302)239 def test_create_invalid(self):240 response = self.client.post(self.url, {241 'title': self.get_random_string(),242 'content': ''243 })244 project_step_form = response.context['project_step_form']245 self.assertEqual(response.status_code, 200)246 self.assertTrue(project_step_form.errors)247 def test_edit_valid_form(self):248 form_data = {249 'title': self.get_random_string(),250 'content': self.get_random_string(),251 }252 project_step = self.create_project_step(project=self.project)253 edit_url = self.get_edit_url(self.project.slug, project_step._order)254 response = self.client.post(edit_url, form_data, follow=True)255 url, status_code = response.redirect_chain[0]256 expected_url = reverse('project-detail', args=[self.project.slug])257 self.assertEqual(status_code, 302)258 self.assertTrue(expected_url in url,259 "Didn't redirect to {0}, redirected to {1}".format(expected_url, url)260 )261 def test_edit_invalid_form(self):262 project_step = self.create_project_step(project=self.project)263 edit_url = self.get_edit_url(self.project.slug, project_step._order)264 response = self.client.post(edit_url, {'content': ''})265 project_step_form = response.context['project_step_form']266 self.assertEqual(response.status_code, 200)267 self.assertTrue(project_step_form.errors)268 def test_edit_form_wrong_user(self):269 other_user = self.create_user(data={'password': 'password'})270 self.client.login(username=other_user.username, password='password')271 form_data = {272 'title': self.get_random_string(),273 'content': self.get_random_string(),274 }275 project_step = self.create_project_step(project=self.project)276 edit_url = self.get_edit_url(self.project.slug, project_step._order)277 response = self.client.post(edit_url, form_data)278 self.assertEqual(response.status_code, 403)279 def test_add_another_redirect(self):280 form_data = {281 'title': self.get_random_string(),282 'content': self.get_random_string(),283 'save-add': 'Anything',284 }285 project_step = self.create_project_step(project=self.project)286 edit_url = self.get_edit_url(self.project.slug, project_step._order)287 response = self.client.post(edit_url, form_data, follow=True)288 url, status_code = response.redirect_chain[0]289 expected_url = reverse(290 'project-step-create-edit', args=[self.project.slug]291 )292 self.assertEqual(status_code, 302)293 self.assertTrue(expected_url in url,294 "Didn't redirect to {0}, redirected to {1}".format(expected_url, url)295 )296 def test_redirect_after_limit(self):297 "Redirect to the Project Detail Page when attempting to add the 21st step"298 [self.create_project_step(project=self.project) for x in range(20)]299 response = self.client.get(self.url, follow=True)300 url, status_code = response.redirect_chain[0]301 expected_url = reverse('project-detail', args=[self.project.slug])302 self.assertEqual(status_code, 302)303 self.assertTrue(expected_url in url,304 "Didn't redirect to {0}, redirected to {1}".format(expected_url, url)305 )306class ProjectPublishViewTestCase(ProjectBaseTestCase):307 url_name = 'publish-project'308 def setUp(self):309 self.user = self.create_user(data={'password': 'password'})310 self.project = self.create_project(user=self.user)311 self.url = reverse('publish-project', args=(self.project.slug,))312 def test_valid_publish(self):313 self.client.login(username=self.user.username, password='password')314 self.assertEqual(self.project.status, CONTENT_STATUS_DRAFT)315 response = self.client.post(self.url, {}, is_ajax=True)316 project = Project.objects.get(slug=self.project.slug)317 self.assertEqual(response.status_code, 200)318 self.assertEqual(project.status, CONTENT_STATUS_PUBLISHED)319 def test_reject_non_project_user(self):320 other_user = self.create_user(data={'password': 'password'})321 self.client.login(username=other_user.username, password='password')322 self.assertEqual(self.project.status, CONTENT_STATUS_DRAFT)323 response = self.client.post(self.url, {}, is_ajax=True)324 project = Project.objects.get(slug=self.project.slug)325 self.assertEqual(response.status_code, 403)326 self.assertEqual(project.status, CONTENT_STATUS_DRAFT)327 def test_superuser_valid(self):328 superuser = self.create_superuser({'password': 'password'})329 self.client.login(username=superuser.username, password='password')330 self.assertEqual(self.project.status, CONTENT_STATUS_DRAFT)331 response = self.client.post(self.url, {}, is_ajax=True)332 project = Project.objects.get(slug=self.project.slug)333 self.assertEqual(response.status_code, 200)334 self.assertEqual(project.status, CONTENT_STATUS_PUBLISHED)335 def test_invalid_slug(self):336 self.client.login(username=self.user.username, password='password')337 self.assertEqual(self.project.status, CONTENT_STATUS_DRAFT)338 url = reverse(self.url_name, args=('bad-project-slug',))339 response = self.client.post(url, {}, is_ajax=True)340 project = Project.objects.get(slug=self.project.slug)341 self.assertEqual(response.status_code, 404)342 self.assertEqual(project.status, CONTENT_STATUS_DRAFT)343class ProjectDeleteViewTestCase(AuthViewMixin, ProjectBaseTestCase):344 url_name = 'project-delete'345 def setUp(self):346 self.project = self.create_project()347 super(ProjectDeleteViewTestCase, self).setUp()348 self.project.user = self.user349 self.project.save()350 def get_url_args(self):351 return (self.project.id,)352 def test_bad_id(self):353 self.client.login(username=self.user.username, password='password')354 url = reverse(self.url_name, args=('999',))355 response = self.client.get(url)356 self.assertEqual(response.status_code, 404)357 self.assertEqual(Project.objects.count(), 1)358 def test_other_user_forbidden(self):359 other_user = self.create_user(data={'password': 'password'})360 self.client.login(username=other_user.username, password='password')361 response = self.client.get(self.url)362 self.assertEqual(response.status_code, 403)363 self.assertEqual(Project.objects.count(), 1)364 def test_superuser_allowed(self):365 superuser = self.create_superuser(data={'password': 'password'})366 self.client.login(username=superuser.username, password='password')367 response = self.client.get(self.url)368 self.assertEqual(response.status_code, 200)369 self.assertEqual(Project.objects.count(), 1)370 def test_delete_post_no_confirm(self):371 response = self.client.post(self.url, {'not_ok': 'not_ok'})372 self.assertEqual(response.status_code, 200)373 self.assertEqual(Project.objects.count(), 1)374 def test_delete_confirm(self):375 response = self.client.post(self.url, {'ok': 'ok'})376 self.assertEqual(response.status_code, 302)377 self.assertEqual(Project.objects.count(), 0)378class ProjectStepDeleteViewTestCase(AuthViewMixin, ProjectBaseTestCase):379 url_name = 'project-step-delete'380 def setUp(self):381 self.project = self.create_project()382 self.project_step = self.create_project_step(project=self.project)383 super(ProjectStepDeleteViewTestCase, self).setUp()384 self.project.user = self.user385 self.project.save()386 def get_url_args(self):387 return (self.project_step.id,)388 def test_bad_id(self):389 self.client.login(username=self.user.username, password='password')390 url = reverse(self.url_name, args=('999',))391 response = self.client.get(url)392 self.assertEqual(response.status_code, 404)393 self.assertEqual(ProjectStep.objects.count(), 1)394 def test_other_user_forbidden(self):395 other_user = self.create_user(data={'password': 'password'})396 self.client.login(username=other_user.username, password='password')397 response = self.client.get(self.url)398 self.assertEqual(response.status_code, 403)399 self.assertEqual(ProjectStep.objects.count(), 1)400 def test_superuser_allowed(self):401 superuser = self.create_superuser(data={'password': 'password'})402 self.client.login(username=superuser.username, password='password')403 response = self.client.get(self.url)404 self.assertEqual(response.status_code, 200)405 self.assertEqual(ProjectStep.objects.count(), 1)406 def test_delete_post_no_confirm(self):407 response = self.client.post(self.url, {'not_ok': 'not_ok'})408 self.assertEqual(response.status_code, 200)409 self.assertEqual(ProjectStep.objects.count(), 1)410 def test_delete_confirm(self):411 response = self.client.post(self.url, {'ok': 'ok'})412 self.assertEqual(response.status_code, 302)413 self.assertEqual(ProjectStep.objects.count(), 0)414class ProjectImageCreateViewTestCase(ProjectBaseTestCase):415 url_name = 'gallery-image-upload'416 def setUp(self):417 self.user = self.create_user(data={'password': 'password'})418 self.client.login(username=self.user.username, password='password')419 self.url = reverse(self.url_name)420 def get_edit_url(self, project_slug, project_step_number):421 return reverse(self.url_name, args=(project_slug, project_step_number))422 def test_login_required(self):423 self.client.logout()424 response = self.client.get(self.url, is_ajax=True)425 self.assertEqual(response.status_code, 302)426 def test_ajax_required(self):427 response = self.client.get(self.url, is_ajax=False)428 self.assertEqual(response.status_code, 400)429 def test_no_data(self):430 response = self.client.post(self.url, {}, is_ajax=True)431 self.assertEqual(response.content, 'false')432 def test_bad_data(self):433 send_data = {434 'filez': self.get_random_string(),435 }436 response = self.client.post(self.url, send_data, is_ajax=True)437 self.assertEqual(response.content, 'false')438 def test_send_file(self):439 filename = self.get_random_string()440 f = self.create_file(filename=filename)441 send_data = {442 'file': f,443 }444 response = self.client.post(self.url, send_data, is_ajax=True)445 response_data = json.loads(response.content)446 response_image_data = response_data['files'][0]447 image = ProjectImage.objects.get(id=response_image_data['id'])448 self.assertEqual(response_image_data, image.get_image_data())449 self.assertEqual(filename, image.get_filename())450 def test_send_file_existing_step(self):451 filename = self.get_random_string()452 f = self.create_file(filename=filename)453 send_data = {454 'file': f,455 }456 project = self.create_project(user=self.user)457 project_step = self.create_project_step(project=project)458 url = self.get_edit_url(project.slug, project_step._order)459 response = self.client.post(url, send_data, is_ajax=True)460 response_data = json.loads(response.content)461 response_image_data = response_data['files'][0]462 image = ProjectImage.objects.get(id=response_image_data['id'])463 self.assertEqual(response_image_data, image.get_image_data())464 self.assertEqual(filename, image.get_filename())465 self.assertEqual(list(project_step.gallery.all()), [image])466 def test_send_file_no_project(self):467 project_step = self.create_project_step()468 url = self.get_edit_url('bad_slug', project_step._order)469 response = self.client.post(url, {}, is_ajax=True)470 self.assertEqual(response.status_code, 404)471 def test_send_file_no_project_step(self):472 project_step = self.create_project_step()473 url = self.get_edit_url(project_step.project.slug, 9999)474 response = self.client.post(url, {}, is_ajax=True)475 self.assertEqual(response.status_code, 404)476 def test_send_file_not_owner(self):477 other_user = self.create_user()478 project = self.create_project(user=other_user)479 project_step = self.create_project_step(project=project)480 url = self.get_edit_url(project.slug, project_step._order)481 response = self.client.post(url, {}, is_ajax=True)482 self.assertEqual(response.status_code, 403)483 def test_superuser_edit(self):484 superuser = self.create_superuser(data={'password': 'password'})485 self.client.login(username=superuser.username, password='password')486 project = self.create_project(user=self.user)487 project_step = self.create_project_step(project=project)488 url = self.get_edit_url(project.slug, project_step._order)489 filename = self.get_random_string()490 f = self.create_file(filename=filename)491 send_data = {492 'file': f,493 }494 response = self.client.post(url, send_data, is_ajax=True)495 response_data = json.loads(response.content)496 response_image_data = response_data['files'][0]497 image = ProjectImage.objects.get(id=response_image_data['id'])498 self.assertEqual(response_image_data, image.get_image_data())499 self.assertEqual(filename, image.get_filename())500class ProjectImageDownloadViewTestCase(ProjectBaseTestCase):501 url_name = 'gallery-image-download'502 def setUp(self):503 self.user = self.create_user(data={'password': 'password'})504 self.client.login(username=self.user.username, password='password')505 self.project = self.create_project()506 self.project_step = self.create_project_step(project=self.project)507 url_args = (508 self.project.slug, self.project_step._order509 )510 self.url = reverse(self.url_name, args=url_args)511 def test_login_required(self):512 self.client.logout()513 response = self.client.get(self.url, is_ajax=True)514 self.assertEqual(response.status_code, 302)515 def test_ajax_required(self):516 response = self.client.get(self.url, is_ajax=False)517 self.assertEqual(response.status_code, 400)518 def test_invalid_project_slug(self):519 url_args = ('bad_slug', self.project_step._order)520 url = reverse(self.url_name, args=url_args)521 response = self.client.get(url, is_ajax=True)522 self.assertEqual(response.status_code, 404)523 def test_invalid_project_step_number(self):524 url_args = (self.project.slug, 999)525 url = reverse(self.url_name, args=url_args)526 response = self.client.get(url, is_ajax=True)527 self.assertEqual(response.status_code, 404)528 def test_empty_images(self):529 response = self.client.get(self.url, is_ajax=True)530 response_data = json.loads(response.content)531 self.assertEqual(response.status_code, 200)532 self.assertEqual(response_data['files'], [])533 def test_other_image(self):534 self.create_project_image()535 response = self.client.get(self.url, is_ajax=True)536 response_data = json.loads(response.content)537 self.assertEqual(response.status_code, 200)538 self.assertEqual(response_data['files'], [],539 'image should not return because it is not associated with this project step'540 )541 def test_one_image(self):542 project_image = self.create_project_image(543 project_step=self.project_step544 )545 response = self.client.get(self.url, is_ajax=True)546 response_data = json.loads(response.content)547 self.assertEqual(response.status_code, 200)548 self.assertEqual(549 response_data['files'], [project_image.get_image_data()],550 'Response should contain the image data for one image'551 )552 def test_multiple_images(self):553 project_image1 = self.create_project_image(554 project_step=self.project_step555 )556 project_image2 = self.create_project_image(557 project_step=self.project_step558 )559 project_image3 = self.create_project_image(560 project_step=self.project_step561 )562 project_images = (project_image1, project_image2, project_image3)563 response = self.client.get(self.url, is_ajax=True)564 response_data = json.loads(response.content)565 self.assertEqual(response.status_code, 200)566 self.assertEqual(response_data, ProjectImage.serialize(project_images),567 'Response should contain the image data for images 1-3'568 )569class ProjectImageDeleteViewTestCase(ProjectBaseTestCase):570 url_name = 'gallery-image-delete'571 def setUp(self):572 self.user = self.create_user(data={'password': 'password'})573 self.client.login(username=self.user.username, password='password')574 self.project_image = self.create_project_image()575 self.url = reverse(self.url_name, args=(self.project_image.id,))576 def test_login_required(self):577 self.client.logout()578 response = self.client.get(self.url, is_ajax=True)579 self.assertEqual(response.status_code, 302)580 def test_ajax_required(self):581 response = self.client.get(self.url, is_ajax=False)582 self.assertEqual(response.status_code, 400)583 def test_wrong_user(self):584 project = self.create_project()585 project_step = self.create_project_step(project=project)586 project_step.gallery.add(self.project_image)587 other_user = self.create_user(data={'password': 'password'})588 self.client.login(username=other_user.username, password='password')589 response = self.client.get(self.url, is_ajax=True)590 self.assertEqual(response.status_code, 403)591 def test_wrong_user_no_project_step(self):592 other_user = self.create_user(data={'password': 'password'})593 self.client.login(username=other_user.username, password='password')594 response = self.client.get(self.url, is_ajax=True)595 self.assertEqual(response.status_code, 200)596 self.assertEqual(response.content, 'true')597 def test_bad_id(self):598 url = reverse(self.url_name, args=(999,))599 response = self.client.get(url, is_ajax=True)600 self.assertEqual(response.status_code, 404)601 def test_no_image(self):602 self.project_image.delete()603 response = self.client.get(self.url, is_ajax=True)604 self.assertEqual(response.status_code, 404)605 def test_has_project_step_other_user(self):606 other_user = self.create_user()607 project = self.create_project(user=other_user)608 project_step = self.create_project_step(project=project)609 project_step.gallery.add(self.project_image)610 response = self.client.get(self.url, is_ajax=True)611 self.assertEqual(response.status_code, 403)612 self.assertEqual(613 list(ProjectImage.objects.all()), [self.project_image]614 )615 def test_has_project_step_current_user(self):616 project = self.create_project(user=self.user)617 project_step = self.create_project_step(project=project)618 project_step.gallery.add(self.project_image)619 response = self.client.get(self.url, is_ajax=True)620 self.assertEqual(response.status_code, 200)621 self.assertEqual(response.content, 'true')622 self.assertEqual(list(project_step.gallery.all()), [])623 self.assertEqual(list(ProjectImage.objects.all()), [])624 def test_no_project_step(self):625 project = self.create_project(user=self.user)626 project_step = self.create_project_step(project=project)627 response = self.client.get(self.url, is_ajax=True)628 self.assertEqual(response.status_code, 200)629 self.assertEqual(response.content, 'true')630 self.assertEqual(list(project_step.gallery.all()), [])631 self.assertEqual(list(ProjectImage.objects.all()), [])632class IndexTestCase(ProjectBaseTestCase):633 url_name = 'home'634 def setUp(self):635 self.user = self.create_user(data={'password': 'password'})636 self.user1 = self.create_user(data={'password': 'password'})637 self.user.actor_actions.add(Action())638 self.user.actor_actions.add(Action())639 self.user1.actor_actions.add(Action())...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1import addProjectForm from "./displayproject"2var projectList = [];3function Project(title, description, dueDate, checkList) {4 this.title = title;5 this.description = description;6 this.dueDate = dueDate;7 this.checkList = checkList;8 this.updateTitle = (newTitle) => {9 this.title = newTitle;10 }11 this.updateDescription = (newDescription) => {12 this.description = newDescription;13 }14 this.updateDueDate = (newDueDate) => {15 this.dueDate = newDueDate;16 }17 this.addToCheckList = (checkListItem) => {18 this.checkList.push(checkListItem);19 }20}21function CheckListItem(value, finished = false) {22 this.value = value;23 this.finished = finished;24 this.invertFinished = () => {25 this.finished = !(this.finished)26 }27 this.getValue = () => {28 return this.value;29 }30 this.isFinished = () => {31 return this.finished;32 }33}34function burgerBtn() {35 const burgerBtn = document.querySelector("#nav-container1")36 burgerBtn.addEventListener("click", () => {37 const projectList = document.querySelector("#project-list");38 if (projectList.style.display) {39 if (projectList.style.display === 'flex') {40 projectList.style.display = 'none';41 } else {42 projectList.style.display = 'flex';43 }44 } else {45 projectList.style.display = 'flex';46 }47 })48}49function addNewProjectBtn() {50 const newProjectBtn = document.querySelector("#add-btn");51 newProjectBtn.addEventListener("click", () => {52 const projectIndex = document.querySelector("#project-list-container").childElementCount;53 deleteProjectContent();54 const newTask = new Project("New Project", "", "", []);55 projectList.push(newTask);56 updateCache();57 addToProjList();58 addProjectForm(projectIndex);59 addFormEventListener();60 });61}62function deleteProjectContent() {63 const projectContent = document.querySelector("#project-detail");64 while (projectContent.firstChild) {65 projectContent.removeChild(projectContent.firstChild);66 }67}68function addFormEventListener() {69 const currIndex = document.querySelector("form").dataset.index;70 const currentProject = projectList[currIndex];71 const projectTitle = document.querySelector("#project-title");72 projectTitle.addEventListener("keyup", (event) => {73 currentProject.updateTitle(projectTitle.value)74 const currProject = document.querySelector("[data-index=" + "\'" + currIndex + "\'" + "]")75 currProject.textContent = projectTitle.value;76 updateCache();77 });78 const duedate = document.querySelector("#duedatecontent");79 duedate.addEventListener("change", () => {80 currentProject.updateDueDate(duedate.value)81 updateCache();82 });83 const description = document.querySelector("#descriptioncontent");84 description.addEventListener("keyup", (event) => {85 currentProject.updateDescription(description.value)86 updateCache();87 });88 const checklist = document.querySelector("#checklistadd");89 checklist.addEventListener("keydown", (event) => {90 if (event.keyCode === 13) {91 const newCheckListItem = new CheckListItem(checklist.value);92 const checklistul = document.querySelector("#checkul");93 const currTaskContainer = document.createElement("div");94 currTaskContainer.classList.add("checklistcontainer");95 const currTaskContent = document.createElement("li");96 currTaskContent.classList.add("checklistitem");97 currTaskContent.textContent = checklist.value;98 const taskIcons = document.createElement("div");99 taskIcons.classList.add("checklisticons");100 const doneIcon = document.createElement("img");101 doneIcon.classList.add("checklisticon");102 doneIcon.src = "./icons/done_outline-white-48dp.svg";103 doneIcon.addEventListener("click", () => {104 currTaskContent.classList.toggle("checklistcomplete");105 newCheckListItem.invertFinished();106 updateCache();107 });108 const trashIcon = document.createElement("img");109 trashIcon.classList.add("checklisticon");110 trashIcon.src = "./icons/delete-white-48dp.svg";111 trashIcon.addEventListener("click", () => {112 const currTaskContainer = trashIcon.parentNode.parentNode;113 var index = Array.prototype.indexOf.call(checklistul.children, currTaskContainer);114 currentProject.checkList.splice(index, 1);115 console.log(projectList);116 updateCache();117 checklistul.removeChild(currTaskContainer);118 })119 taskIcons.appendChild(doneIcon);120 taskIcons.appendChild(trashIcon);121 currTaskContainer.appendChild(currTaskContent);122 currTaskContainer.appendChild(taskIcons);123 checklist.appendChild(currTaskContainer);124 checklistul.appendChild(currTaskContainer);125 currentProject.addToCheckList(newCheckListItem);126 updateCache();127 checklist.value = "";128 }129 });130}131function updateFrontPage() {132 projectList = cacheUp();133 if (projectList.length === 0) {134 const newTask = new Project("New Project", "", "", []);135 projectList.push(newTask);136 addToProjList();137 updateCache();138 } else {139 updateBurger();140 }141 addProjectForm(0, projectList[0]);142 addFormEventListener();143}144function updateBurger() {145 const projectListContainer = document.querySelector("#project-list-container");146 for (const currProjectIndex in projectList) {147 const currProject = projectList[currProjectIndex];148 const newProject = document.createElement("li");149 newProject.textContent = currProject.title;150 newProject.classList.add("project-item");151 newProject.dataset.index = currProjectIndex;152 newProject.addEventListener("click", () => {153 deleteProjectContent();154 addProjectForm(newProject.dataset.index, projectList[newProject.dataset.index]);155 addFormEventListener();156 });157 projectListContainer.appendChild(newProject);158 }159}160function addToProjList() {161 const projectListContainer = document.querySelector("#project-list-container");162 const projectIndex = projectListContainer.childElementCount;163 const newProject = document.createElement("li");164 newProject.textContent = "New Project";165 newProject.classList.add("project-item");166 newProject.dataset.index = projectIndex;167 newProject.addEventListener("click", () => {168 deleteProjectContent();169 addProjectForm(newProject.dataset.index, projectList[newProject.dataset.index]);170 addFormEventListener();171 });172 projectListContainer.appendChild(newProject);173}174function app() {175 updateFrontPage();176 burgerBtn();177 addNewProjectBtn();178 deleteProjectBtn();179}180function cacheUp() {181 if (!localStorage.getItem('projectList')) {182 localStorage['projectList'] = JSON.stringify([]);183 }184 var cacheObj = JSON.parse(localStorage.getItem('projectList'));185 const cachedProjectList = [];186 for (const currObj of cacheObj) {187 const currCheckList = currObj['checkList'];188 const objCheckList = [];189 for (const currList of currCheckList) {190 objCheckList.push(new CheckListItem(currList.value, currList.finished));191 }192 cachedProjectList.push(new Project(currObj["title"], currObj["description"], currObj["dueDate"], objCheckList));193 }194 return cachedProjectList;195}196function updateCache() {197 localStorage['projectList'] = JSON.stringify(projectList);198}199function deleteProjectBtn() {200 const deleteBtn = document.querySelector("#delete-project");201 const modal = document.querySelector("#myModal");202 deleteBtn.addEventListener("click", () => {203 modal.style.display = "block";204 });205 const yesBtn = document.querySelector("#yes-btn");206 yesBtn.addEventListener("click", () => {207 console.log("EUYEYUE");208 const currFormIndex = document.querySelector("form").dataset.index;209 projectList.splice(currFormIndex, 1);210 updateCache();211 const projectListContainer = document.querySelector("#project-list-container");212 while (projectListContainer.firstChild) {213 console.log(projectListContainer.firstChild);214 projectListContainer.removeChild(projectListContainer.firstChild);215 }216 deleteProjectContent();217 updateFrontPage();218 modal.style.display = "none";219 });220 const noBtn = document.querySelector("#no-btn");221 noBtn.addEventListener("click", () => {222 modal.style.display = "none";223 });224 window.addEventListener("click", (event) => {225 if (event.target == modal) {226 modal.style.display = "none";227 }228 })229}230export default updateCache;...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...118 'project_step': project_step,119 })120@login_required121@ajax_only122def publish_project(request, project_slug):123 project = get_object_or_404(Project, slug=project_slug)124 if not project.is_editable(request):125 return HttpResponseForbidden('You are not the owner of this project.')126 else:127 project.status = CONTENT_STATUS_PUBLISHED128 project.save()129 action.send(request.user, verb='published', target=project)130 return AjaxResponse(request, {})131@login_required132@ajax_only133def gallery_image_create(request, project_slug=None, project_step_number=None):134 project_step = None135 if project_slug and project_step_number:136 project = get_object_or_404(Project, slug=project_slug)...

Full Screen

Full Screen

project.js

Source:project.js Github

copy

Full Screen

1import axios from 'axios';2import variable from '../../constants/variable';3import {htmlFilter} from '../../common';4// Actions5const FETCH_PROJECT_LIST = 'yapi/project/FETCH_PROJECT_LIST';6const PROJECT_ADD = 'yapi/project/PROJECT_ADD';7const PROJECT_DEL = 'yapi/project/PROJECT_DEL';8// const CHANGE_TABLE_LOADING = 'yapi/project/CHANGE_TABLE_LOADING';9const PROJECT_UPDATE = 'yapi/project/PROJECT_UPDATE';10const PROJECT_UPDATE_ENV = 'yapi/project/PROJECT_UPDATE_ENV';11const PROJECT_UPSET = 'yapi/project/PROJECT_UPSET';12const GET_CURR_PROJECT = 'yapi/project/GET_CURR_PROJECT';13const GET_PEOJECT_MEMBER = 'yapi/project/GET_PEOJECT_MEMBER';14const ADD_PROJECT_MEMBER = 'yapi/project/ADD_PROJECT_MEMBER';15const DEL_PROJECT_MEMBER = 'yapi/project/DEL_PROJECT_MEMBER';16const CHANGE_PROJECT_MEMBER = 'yapi/project/CHANGE_PROJECT_MEMBER';17const GET_TOKEN = 'yapi/project/GET_TOKEN';18const UPDATE_TOKEN = 'yapi/project/UPDATE_TOKEN';19const CHECK_PROJECT_NAME = 'yapi/project/CHECK_PROJECT_NAME';20const COPY_PROJECT_MSG = 'yapi/project/COPY_PROJECT_MSG';21const PROJECT_GET_ENV = 'yapi/project/PROJECT_GET_ENV';22const CHANGE_MEMBER_EMAIL_NOTICE = 'yapi/project/CHANGE_MEMBER_EMAIL_NOTICE';23const GET_SWAGGER_URL_DATA = 'yapi/project/GET_SWAGGER_URL_DATA'24// Reducer25const initialState = {26 isUpdateModalShow: false,27 handleUpdateIndex: -1,28 projectList: [],29 projectMsg: {},30 userInfo: {},31 tableLoading: true,32 total: 0,33 currPage: 1,34 token: '',35 currProject: {},36 projectEnv: {37 env: [38 {39 header: []40 }41 ]42 },43 swaggerUrlData: ''44};45export default (state = initialState, action) => {46 switch (action.type) {47 case GET_CURR_PROJECT: {48 return {49 ...state,50 currProject: action.payload.data.data51 };52 }53 case FETCH_PROJECT_LIST: {54 return {55 ...state,56 projectList: action.payload.data.data.list,57 total: action.payload.data.data.total,58 userInfo: action.payload.data.data.userinfo59 };60 }61 case PROJECT_ADD: {62 return state;63 }64 case PROJECT_DEL: {65 return state;66 }67 case GET_TOKEN: {68 return {69 ...state,70 token: action.payload.data.data71 };72 }73 case PROJECT_GET_ENV: {74 return {75 ...state,76 projectEnv: action.payload.data.data77 };78 }79 case UPDATE_TOKEN: {80 return {81 ...state,82 token: action.payload.data.data.token83 };84 }85 case CHECK_PROJECT_NAME: {86 return {87 ...state88 };89 }90 case COPY_PROJECT_MSG: {91 return {92 ...state93 };94 }95 case GET_SWAGGER_URL_DATA: {96 return {97 ...state,98 swaggerUrlData: action.payload.data.data99 }100 }101 default:102 return state;103 }104};105// 获取某分组下的项目列表106export function fetchProjectList(id, pageNum) {107 return {108 type: FETCH_PROJECT_LIST,109 payload: axios.get('/api/project/list', {110 params: {111 group_id: id,112 page: pageNum || 1,113 limit: variable.PAGE_LIMIT114 }115 })116 };117}118// 复制项目119export function copyProjectMsg(params) {120 return {121 type: COPY_PROJECT_MSG,122 payload: axios.post('/api/project/copy', params)123 };124}125// 添加项目成员126export function addMember(param) {127 return {128 type: ADD_PROJECT_MEMBER,129 payload: axios.post('/api/project/add_member', param)130 };131}132// 删除项目成员133export function delMember(param) {134 return {135 type: DEL_PROJECT_MEMBER,136 payload: axios.post('/api/project/del_member', param)137 };138}139// 修改项目成员权限140export function changeMemberRole(param) {141 return {142 type: CHANGE_PROJECT_MEMBER,143 payload: axios.post('/api/project/change_member_role', param)144 };145}146// 修改项目成员是否收到邮件通知147export function changeMemberEmailNotice(param) {148 return {149 type: CHANGE_MEMBER_EMAIL_NOTICE,150 payload: axios.post('/api/project/change_member_email_notice', param)151 };152}153// 获取项目成员列表154export function getProjectMemberList(id) {155 return {156 type: GET_PEOJECT_MEMBER,157 payload: axios.get('/api/project/get_member_list', {158 params: { id }159 })160 };161}162// export function changeTableLoading(data) {163// return {164// type: CHANGE_TABLE_LOADING,165// payload: data166// };167// }168export function addProject(data) {169 let {170 name,171 prd_host,172 basepath,173 desc,174 group_id,175 group_name,176 protocol,177 icon,178 color,179 project_type180 } = data;181 // 过滤项目名称中有html标签存在的情况182 name = htmlFilter(name);183 const param = {184 name,185 prd_host,186 protocol,187 basepath,188 desc,189 group_id,190 group_name,191 icon,192 color,193 project_type194 };195 return {196 type: PROJECT_ADD,197 payload: axios.post('/api/project/add', param)198 };199}200// 修改项目201export function updateProject(data) {202 let { name, project_type, basepath, desc, _id, env, group_id, switch_notice, strice, is_json5, tag } = data;203 204 // 过滤项目名称中有html标签存在的情况205 name = htmlFilter(name);206 const param = {207 name,208 project_type,209 basepath,210 switch_notice,211 desc,212 id: _id,213 env,214 group_id,215 strice,216 is_json5,217 tag218 };219 return {220 type: PROJECT_UPDATE,221 payload: axios.post('/api/project/up', param)222 };223}224// 修改项目脚本225export function updateProjectScript(data) {226 return {227 type: PROJECT_UPDATE,228 payload: axios.post('/api/project/up', data)229 };230}231// 修改全局mock232export function updateProjectMock(data) {233 return {234 type: PROJECT_UPDATE,235 payload: axios.post('/api/project/up', data)236 };237}238// 修改项目环境配置239export function updateEnv(data) {240 const { env, _id } = data;241 const param = {242 id: _id,243 env244 };245 return {246 type: PROJECT_UPDATE_ENV,247 payload: axios.post('/api/project/up_env', param)248 };249}250// 获取项目环境配置251export function getEnv(project_id) {252 return {253 type: PROJECT_GET_ENV,254 payload: axios.get('/api/project/get_env', { params: { project_id } })255 };256}257// 修改项目头像258export function upsetProject(param) {259 return {260 type: PROJECT_UPSET,261 payload: axios.post('/api/project/upset', param)262 };263}264// 删除项目265export function delProject(id) {266 const param = { id };267 return {268 type: PROJECT_DEL,269 payload: axios.post('/api/project/del', param)270 };271}272export async function getProject(id) {273 let result = await axios.get('/api/project/get?id=' + id);274 return {275 type: GET_CURR_PROJECT,276 payload: result277 };278}279export async function getToken(project_id) {280 return {281 type: GET_TOKEN,282 payload: axios.get('/api/project/token', {283 params: { project_id }284 })285 };286}287export async function updateToken(project_id) {288 return {289 type: UPDATE_TOKEN,290 payload: axios.get('/api/project/update_token', {291 params: { project_id }292 })293 };294}295export async function checkProjectName(name, group_id) {296 return {297 type: CHECK_PROJECT_NAME,298 payload: axios.get('/api/project/check_project_name', {299 params: { name, group_id }300 })301 };302}303export async function handleSwaggerUrlData(url) {304 return {305 type: GET_SWAGGER_URL_DATA,306 payload: axios.get('/api/project/swagger_url?url='+url)307 };...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful