How to use project method in stryker-parent

Best JavaScript code snippet using stryker-parent

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

test_models.py

Source:test_models.py Github

copy

Full Screen

...6 CONTENT_STATUS_DRAFT)7from raspberryio.project.tests.base import ProjectBaseTestCase8class ProjectTestCase(ProjectBaseTestCase):9 def setUp(self):10 self.project = self.create_project()11 def test_is_published(self):12 self.project.status = CONTENT_STATUS_PUBLISHED13 self.project.save()14 self.assertTrue(self.project.is_published(),15 'Should return True since the default publish_date is past and the status is "Published"'16 )17 def test_is_published_false(self):18 self.project.publish_date = now() + timedelta(minutes=1)19 self.project.save()20 self.assertFalse(self.project.is_published(),21 'Should return False if publish_date is in the future'22 )23 self.project.publish_date = now() - timedelta(minutes=1)24 self.project.status = CONTENT_STATUS_DRAFT25 self.project.save()26 self.assertFalse(self.project.is_published(),27 'Should return False if status is "Draft"'28 )29 self.project_publish_date = now() + timedelta(minutes=1)30 self.project.save()31 self.assertFalse(self.project.is_published(),32 'Should return False if status is "Draft" and publish_date is in the future'33 )34 def test_default_draft(self):35 self.assertEqual(self.project.status, CONTENT_STATUS_DRAFT)36 def test_video_params(self):37 # first test that garbage input doesn't work38 self.assertEqual(self.project.embed_url, None)39 # now test a real video URL40 video_id = "6BbufUp_HNs"41 video_url = "http://www.youtube.com/watch?v=%s" % video_id42 project = self.create_project(featured_video=video_url)43 self.assertEqual(project.video_id, video_id)44 self.assertEqual(project.embed_url, 'http://www.youtube.com/embed/%s?wmode=transparent' % video_id)45class ProjectStepTestCase(ProjectBaseTestCase):46 def setUp(self):47 self.user = self.create_user()48 self.project = self.create_project(user=self.user)49 self.project_step = self.create_project_step(project=self.project)50 self.request_factory = RequestFactory()51 def test_is_editable_project_user(self):52 request = self.request_factory.get('/')53 request.user = self.project.user54 self.assertTrue(55 self.project_step.is_editable(request),56 'A user should be able to edit the project steps of their own project',57 )58 def test_is_editable_not_project_user(self):59 request = self.request_factory.get('/')60 request.user = self.create_user()61 self.assertFalse(62 self.project_step.is_editable(request),63 "A user should not be able to edit the project steps of another user's project",64 )65 def test_is_editable_superuser(self):66 request = self.request_factory.get('/')67 request.user = self.create_superuser()68 self.assertTrue(69 self.project_step.is_editable(request),70 'Superusers should be able to edit any project step',71 )72 def test_get_steps_count_property(self):73 self.assertEqual(self.project_step.get_steps_count, 1)74 self.create_project_step(project=self.project)75 self.assertEqual(self.project_step.get_steps_count, 2)76 self.create_project_step()77 self.assertEqual(self.project_step.get_steps_count, 2,78 "step count shouldn't change when step is added to a different project"79 )80 def test_order_property(self):81 """Assure the order property provides the _order value"""82 self.assertEqual(self.project_step.order, self.project_step._order)83 project_step2 = self.create_project_step(project=self.project)84 self.assertEqual(project_step2.order, project_step2._order)85 def test_get_order_display(self):86 """Assure the get_order_display method provides the _order value + 1"""87 self.assertEqual(88 self.project_step.get_order_display, self.project_step._order + 189 )90 project_step2 = self.create_project_step(project=self.project)91 self.assertEqual(92 project_step2.get_order_display, project_step2._order + 193 )94 def test_order_number(self):95 """96 Assure the proper order number is assigned to new ProjectSteps. (This97 should happen from built-in Mezzanine functionality as long as98 Meta:order_with_respect_to points to the Project FK)99 """100 project2 = self.create_project(user=self.user)101 # Create two steps in each of the two projects102 project1_step0 = self.project_step103 project2_step0 = self.create_project_step(project=project2)104 project1_step1 = self.create_project_step(project=self.project)105 project2_step1 = self.create_project_step(project=project2)106 # Assure the order numbers for the steps are unique per project107 self.assertEqual(project1_step0._order, 0)108 self.assertEqual(project1_step1._order, 1)109 self.assertEqual(project2_step0._order, 0)110 self.assertEqual(project2_step1._order, 1)111 def test_absolute_url(self):112 self.assertEqual(self.project_step.get_absolute_url(),113 reverse('project-detail', args=[self.project.slug]))114 def test_video_params(self):...

Full Screen

Full Screen

test_forms.py

Source:test_forms.py Github

copy

Full Screen

...3from raspberryio.project.forms import ProjectImageForm, ProjectStepForm4class ProjectFormTestCase(ProjectBaseTestCase):5 def setUp(self):6 self.request_factory = RequestFactory()7 self.project = self.create_project()8 def test_placeholder_labels(self):9 request = self.request_factory.get('/')10 form = ProjectStepForm()11 # first assert that label is shown12 self.assertEqual(form.fields['title'].label, 'Title')13 form.Meta.remove_labels = True14 form = ProjectStepForm(request.GET, instance=self.project)15 # now assert that Meta attribute removes it16 self.assertEqual(form.fields['title'].label, '')17class ProjectStepFormTestCase(ProjectBaseTestCase):18 def setUp(self):19 self.request_factory = RequestFactory()20 self.project = self.create_project()21 self.project_step = self.create_project_step(project=self.project)22 def test_no_content(self):23 request = self.request_factory.post('/', {})24 form = ProjectStepForm(request.POST, instance=self.project_step)25 self.assertFalse(form.is_valid())26 self.assertEqual(form.errors['content'], ['This field is required.'])27 def test_images_empty(self):28 post_data = {29 'title': self.get_random_string(),30 'content': self.get_random_string(),31 'images': []32 }33 request = self.request_factory.post('/', post_data)34 form = ProjectStepForm(request.POST, instance=self.project_step)35 if form.is_valid():36 project_step = form.save()37 self.assertEqual(project_step.gallery.count(), 0)38 else:39 self.fail('Form should be valid')40 def test_images_bad_format(self):41 self.create_project_image()42 post_data = {43 'title': self.get_random_string(),44 'content': self.get_random_string(),45 'images': ['not']46 }47 request = self.request_factory.post('/', post_data)48 form = ProjectStepForm(request.POST, instance=self.project_step)49 if form.is_valid():50 project_step = form.save()51 self.assertEqual(list(project_step.gallery.all()), [])52 else:53 self.fail('Form should be valid')54 def test_images_bad_ids(self):55 self.create_project_image()56 post_data = {57 'title': self.get_random_string(),58 'content': self.get_random_string(),59 'images': ['99,100']60 }61 request = self.request_factory.post('/', post_data)62 form = ProjectStepForm(request.POST, instance=self.project_step)63 if form.is_valid():64 project_step = form.save()65 self.assertEqual(list(project_step.gallery.all()), [])66 else:67 self.fail('Form should be valid')68 def test_images_valid(self):69 project_image = self.create_project_image()70 post_data = {71 'title': self.get_random_string(),72 'content': self.get_random_string(),73 'images': [str(project_image.id)]74 }75 request = self.request_factory.post('/', post_data)76 form = ProjectStepForm(request.POST, instance=self.project_step)77 if form.is_valid():78 project_step = form.save()79 self.assertEqual(list(project_step.gallery.all()), [project_image])80 else:81 self.fail('Form should be valid')82 def test_multiple_images_valid(self):83 project_image1 = self.create_project_image()84 project_image2 = self.create_project_image()85 project_images = (project_image1, project_image2)86 post_data = {87 'title': self.get_random_string(),88 'content': self.get_random_string(),89 'images': ','.join([str(image.id) for image in project_images])90 }91 request = self.request_factory.post('/', post_data)92 form = ProjectStepForm(request.POST, instance=self.project_step)93 if form.is_valid():94 project_step = form.save()95 self.assertEqual(tuple(project_step.gallery.all()), project_images)96 else:97 self.fail('Form should be valid')98 def test_bad_video_url(self):99 post_data = {100 'title': self.get_random_string(),101 'content': self.get_random_string(),102 'video': 'http://example.com/badurl',103 }104 request = self.request_factory.post('/', post_data)105 form = ProjectStepForm(request.POST, instance=self.project_step)106 self.assertFalse(form.is_valid())107class ProjectImageFormTestCase(ProjectBaseTestCase):108 def setUp(self):109 self.request_factory = RequestFactory()110 self.project = self.create_project()111 def test_valid_file_upload(self):112 filename = self.get_random_string()113 f = self.create_file(filename=filename)114 request = self.request_factory.post('/', {'file': f})115 request.is_ajax = True116 form = ProjectImageForm(request.POST, request.FILES)117 if form.is_valid():118 instance = form.save()119 self.assertEqual(instance.get_filename(), filename)120 else:121 self.fail('Form should be valid')122 def test_invalid_upload(self):123 request = self.request_factory.post('/', {'filez': self.create_file()})124 request.is_ajax = True...

Full Screen

Full Screen

case_114_backup_restore_project.js

Source:case_114_backup_restore_project.js Github

copy

Full Screen

1// Copyright (C) 2022 Intel Corporation2//3// SPDX-License-Identifier: MIT4/// <reference types="cypress" />5const caseId = '114';6let projectID = '';7let projectBackupArchiveFullName;8function getProjectID() {9 cy.url().then((url) => {10 projectID = Number(url.split('/').slice(-1)[0].split('?')[0]);11 });12}13const project = {14 name: `Case ${caseId}`,15 label: 'Tree',16 attrName: 'Kind',17 attrVaue: 'Oak',18};19const task = {20 name: `Case ${caseId}`,21 multiAttrParams: false,22 advancedConfigurationParams: false,23 forProject: true,24 attachToProject: false,25};26context('Backup, restore a project.', { browser: '!firefox' }, () => {27 const imagesCount = 1;28 const imageFileName = `image_${task.name.replace(' ', '_').toLowerCase()}`;29 const width = 800;30 const height = 800;31 const posX = 10;32 const posY = 10;33 const color = 'gray';34 const archiveName = `${imageFileName}.zip`;35 const archivePath = `cypress/fixtures/${archiveName}`;36 const imagesFolder = `cypress/fixtures/${imageFileName}`;37 const directoryToArchive = imagesFolder;38 const createRectangleShape2Points = {39 points: 'By 2 Points',40 type: 'Shape',41 labelName: project.label,42 firstX: 250,43 firstY: 350,44 secondX: 350,45 secondY: 450,46 };47 before(() => {48 cy.visit('/');49 cy.login();50 cy.imageGenerator(imagesFolder, imageFileName, width, height, color, posX, posY, project.label, imagesCount);51 cy.createZipArchive(directoryToArchive, archivePath);52 cy.goToProjectsList();53 cy.createProjects(project.name, project.label, project.attrName, project.attrVaue);54 cy.openProject(project.name);55 getProjectID();56 cy.createAnnotationTask(57 task.name,58 task.label,59 task.attrName,60 task.attrValue,61 archiveName,62 task.multiAttrParams,63 task.advancedConfigurationParams,64 task.forProject,65 task.attachToProject,66 project.name,67 );68 cy.openProject(project.name);69 cy.openTaskJob(task.name);70 cy.createRectangle(createRectangleShape2Points);71 cy.saveJob();72 cy.goToProjectsList();73 });74 after(() => {75 cy.goToProjectsList();76 cy.deleteProject(project.name, projectID);77 });78 describe(`Testing "${caseId}"`, () => {79 it('Export the project.', () => {80 cy.backupProject(project.name);81 cy.getDownloadFileName().then((file) => {82 projectBackupArchiveFullName = file;83 cy.verifyDownload(projectBackupArchiveFullName);84 });85 });86 it('Remove and restore the project from backup.', () => {87 cy.deleteProject(project.name, projectID);88 cy.restoreProject(projectBackupArchiveFullName);89 });90 it('Checking the availability of a project, task, shape.', () => {91 cy.contains('.cvat-projects-project-item-title', project.name).should('exist');92 cy.openProject(project.name);93 getProjectID();94 cy.contains('.cvat-constructor-viewer-item', project.label).should('exist');95 cy.get('.cvat-tasks-list-item').should('have.length', 1);96 cy.openTaskJob(task.name, 0, false);97 cy.get('#cvat_canvas_shape_1').should('exist');98 });99 });100});101context('Backup, restore a project with a 3D task.', { browser: '!firefox' }, () => {102 const archiveName3d = '../../cypress/integration/canvas3d_functionality/assets/test_canvas3d.zip';103 const cuboidCreationParams = {104 labelName: project.label,105 x: 480,106 y: 160,107 };108 before(() => {109 cy.goToProjectsList();110 cy.createProjects(project.name, project.label, project.attrName, project.attrVaue);111 cy.openProject(project.name);112 getProjectID();113 cy.createAnnotationTask(114 task.name,115 task.label,116 task.attrName,117 task.attrValue,118 archiveName3d,119 task.multiAttrParams,120 task.advancedConfigurationParams,121 task.forProject,122 task.attachToProject,123 project.name,124 );125 cy.openProject(project.name);126 cy.openTaskJob(task.name);127 cy.create3DCuboid(cuboidCreationParams);128 cy.saveJob();129 cy.goToProjectsList();130 });131 after(() => {132 cy.goToProjectsList();133 cy.deleteProject(project.name, projectID);134 });135 describe(`Testing "${caseId}"`, () => {136 it('Export the project.', () => {137 cy.backupProject(project.name);138 cy.getDownloadFileName().then((file) => {139 projectBackupArchiveFullName = file;140 cy.verifyDownload(projectBackupArchiveFullName);141 });142 });143 it('Remove and restore the project from backup.', () => {144 cy.deleteProject(project.name, projectID);145 cy.restoreProject(projectBackupArchiveFullName);146 });147 it('Checking the availability of a project, task, shape.', () => {148 cy.contains('.cvat-projects-project-item-title', project.name).should('exist');149 cy.openProject(project.name);150 getProjectID();151 cy.contains('.cvat-constructor-viewer-item', project.label).should('exist');152 cy.get('.cvat-tasks-list-item').should('have.length', 1);153 cy.openTaskJob(task.name, 0, false);154 cy.get('#cvat-objects-sidebar-state-item-1').should('exist');155 });156 });...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.conf.urls import patterns, url2urlpatterns = patterns('raspberryio.project.views',3 # Project list4 url(r'^$', 'project_list', name='project-list'),5 # Project detail6 url(7 r'^view/(?P<project_slug>[\w-]+)/$',8 'project_detail', name='project-detail'9 ),10 # Create project11 url(r'^add/$', 'project_create_edit', name='project-create-edit'),12 # Edit project13 url(14 r'^edit/(?P<project_slug>[\w-]+)/$', 'project_create_edit',15 name='project-create-edit'16 ),17 # Create project step18 url(19 r'^add-step/(?P<project_slug>[\w-]+)/$', 'project_step_create_edit',20 name='project-step-create-edit'21 ),22 # Edit project step23 url(24 r'^edit-step/(?P<project_slug>[\w-]+)/(?P<project_step_number>[\d]+)/$',25 'project_step_create_edit',26 name='project-step-create-edit'27 ),28 # Delete project29 url(30 r'^delete/(?P<project_pk>[\d]+)/$', 'project_delete',31 name='project-delete'32 ),33 # Delete project step34 url(35 r'^delete-step/(?P<project_step_pk>[\d]+)/$', 'project_step_delete',36 name='project-step-delete'37 ),38 # --- Ajax views39 # Publish a project40 url(41 r'^publish/(?P<project_slug>[\w-]+)/$', 'publish_project',42 name='publish-project'43 ),44 # Upload, download, or delete Gallery Images45 url(46 r'^add-image/' + \47 '(?:(?P<project_slug>[\w-]+)/)?/(?:(?P<project_step_number>[\d]+)/)?$',48 'gallery_image_create', name='gallery-image-upload',49 ),50 url(51 r'^image/(?P<project_slug>[\w-]+)/(?P<project_step_number>[\d]+)/$',52 'gallery_image_download', name='gallery-image-download',53 ),54 url(55 r'^delete-image/(?P<project_image_id>\d+)/$',56 'gallery_image_delete', name='gallery-image-delete',57 ),...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Stryker } = require('stryker-parent');2const stryker = new Stryker({3 mochaOptions: {4 }5});6stryker.runMutationTest().then(() => {7 console.log('Done!');8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Project } = require('stryker-parent');2const project = new Project();3const { Project } = require('stryker-parent');4const project = new Project();5const { Project } = require('stryker-parent');6const project = new Project();7const { Project } = require('stryker-parent');8const project = new Project();9const { Project } = require('stryker-parent');10const project = new Project();11const { Project } = require('stryker-parent');12const project = new Project();13const { Project } = require('stryker-parent');14const project = new Project();15const { Project } = require('stryker-parent');16const project = new Project();17const { Project } = require('stryker-parent');18const project = new Project();19const { Project } = require('stryker-parent');20const project = new Project();21const { Project } = require('stryker-parent');22const project = new Project();23const { Project } = require('stryker-parent');24const project = new Project();25const { Project } = require('stryker-parent');26const project = new Project();27const { Project } = require('stryker-parent');28const project = new Project();29const { Project } = require('stryker-parent');30const project = new Project();31const { Project } = require('stryker-parent');32const project = new Project();

Full Screen

Using AI Code Generation

copy

Full Screen

1project('stryker-parent', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'pom') {2 project('stryker', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'pom') {3 project('stryker-core', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'jar') {4 project('stryker-api', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'jar') {5 project('stryker-maven-plugin', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'maven-plugin') {6 project('stryker4s', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'jar') {7 project('stryker4s-api', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'jar') {8 project('stryker4s-maven-plugin', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'maven-plugin') {9 project('stryker4s-sbt', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'jar') {10 project('stryker4s-gradle-plugin', 'org.stryker-mutator', '0.0.1-SNAPSHOT', 'jar') {11 project('stryker4s-scala', 'org.stryker-mutator', '0.0.1-SNAPSHOT',

Full Screen

Using AI Code Generation

copy

Full Screen

1const stryker = require('stryker-parent');2console.log(stryker);3module.exports = {4 project: require('./project')5};6module.exports = function project() {7 return 'project';8};9module.exports = {10 project: require('./project')11};12module.exports = function project() {13 return 'project';14};15module.exports = {16 project: require('./project')17};18module.exports = function project() {19 return 'project';20};21module.exports = {22 project: require('./project')23};24module.exports = function project() {25 return 'project';26};27module.exports = {28 project: require('./project')29};30module.exports = function project() {31 return 'project';32};33module.exports = {34 project: require('./project')35};36module.exports = function project() {37 return 'project';38};39module.exports = {40 project: require('./project')41};42module.exports = function project() {43 return 'project';44};

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2stryker.project('test');3var stryker = require('stryker-parent');4stryker.project('test');5var stryker = require('stryker-parent');6stryker.project('test');7var stryker = require('stryker-parent');8stryker.project('test');9var stryker = require('stryker-parent');10stryker.project('test');11var stryker = require('stryker-parent');12stryker.project('test');13var stryker = require('stryker-parent');14stryker.project('test');15var stryker = require('stryker-parent');16stryker.project('test');17var stryker = require('stryker-parent');18stryker.project('test');19var stryker = require('stryker-parent');20stryker.project('test');21var stryker = require('stryker-parent');22stryker.project('test');23var stryker = require('stryker-parent');24stryker.project('test');25var stryker = require('stryker-parent');26stryker.project('test');27var stryker = require('stryker-parent');28stryker.project('test');29var stryker = require('stryker-parent');30stryker.project('test');31var stryker = require('stryker-parent');32stryker.project('test');

Full Screen

Using AI Code Generation

copy

Full Screen

1const parent = require('stryker-parent');2const project = parent.project('stryker');3const packageJson = project.packageJson;4const child = require('stryker-child');5const project = child.project('stryker');6const packageJson = project.packageJson;7const sibling = require('stryker-sibling');8const project = sibling.project('stryker');9const packageJson = project.packageJson;10const sibling2 = require('stryker-sibling2');11const project = sibling2.project('stryker');12const packageJson = project.packageJson;13const sibling3 = require('stryker-sibling3');14const project = sibling3.project('stryker');15const packageJson = project.packageJson;16const sibling4 = require('stryker-sibling4');17const project = sibling4.project('stryker');18const packageJson = project.packageJson;19const sibling5 = require('stryker-sibling5');20const project = sibling5.project('stryker');21const packageJson = project.packageJson;22const sibling6 = require('stryker-sibling6');23const project = sibling6.project('stryker');24const packageJson = project.packageJson;25const sibling7 = require('stryker-sibling7');26const project = sibling7.project('stryker');27const packageJson = project.packageJson;28const sibling8 = require('stryker-sibling8');29const project = sibling8.project('stryker');30const packageJson = project.packageJson;31const sibling9 = require('stryker-sibling9');32const project = sibling9.project('stryker');33const packageJson = project.packageJson;34const sibling10 = require('stryker-sibling10');35const project = sibling10.project('stryker');

Full Screen

Using AI Code Generation

copy

Full Screen

1var project = require('stryker-parent').project;2var config = project('project-name').strykerConfig();3var project = require('stryker-parent').project;4var config = project('project-name').strykerConfig();5var project = require('stryker-parent').project;6var config = project('project-name').strykerConfig();7var project = require('stryker-parent').project;8var config = project('project-name').strykerConfig();9var project = require('stryker-parent').project;10var config = project('project-name').strykerConfig();11var project = require('stryker-parent').project;12var config = project('project-name').strykerConfig();13var project = require('stryker-parent').project;14var config = project('project-name').strykerConfig();15var project = require('stryker-parent').project;16var config = project('project-name').strykerConfig();17var project = require('stryker-parent').project;18var config = project('project-name').strykerConfig();

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 stryker-parent 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