def test_moderate_reject_url(self): ''' There is a url to moderate a message ''' message = Message.objects.create( content='Content 1', author_name='Felipe', author_email="*****@*****.**", subject='Fiera es una perra feroz', public=False, writeitinstance=self.writeitinstance, persons=[self.person1], ) message.recently_confirmated() url = reverse('reject_message', subdomain=message.writeitinstance.slug, kwargs={'pk': message.pk}) self.client.login(username=self.writeitinstance.owner.username, password='******') response = self.client.post(url) message_again = Message.objects.get(id=message.id) self.assertTrue(message_again.moderated) self.assertFalse(message.public) '''Redirecting''' allmessages_url = reverse('messages_per_writeitinstance', subdomain=self.writeitinstance.slug) self.assertRedirects(response, allmessages_url)
def test_url_update(self): url = reverse('mailit-template-update', subdomain=self.writeitinstance.slug) self.assertTrue(url) c = self.client c.login(username="******", password="******") data = { 'subject_template': 'Hello there you have a new mail this is subject', 'content_template': 'hello there this is the content and you got this message', 'content_html_template': '<tag>hello there this is the content and you got this message</tag>', } response = c.post(url, data=data) url = reverse('writeitinstance_template_update', subdomain=self.writeitinstance.slug) self.assertRedirects(response, url) self.assertEquals( self.writeitinstance.mailit_template.subject_template, data['subject_template'], ) self.assertEquals( self.writeitinstance.mailit_template.content_template, data['content_template'], )
def send_moderation_mail(self): plaintext = get_template('nuntium/mails/moderation_mail.txt') htmly = get_template('nuntium/mails/moderation_mail.html') current_site = Site.objects.get_current() current_domain = 'http://'+current_site.domain url_rejected = reverse('moderation_rejected', kwargs={ 'slug': self.moderation.key }) url_accept = reverse('moderation_accept', kwargs={ 'slug': self.moderation.key }) d = Context({ 'message': self, 'url_rejected':url_rejected, 'url_accept':url_accept }) text_content = plaintext.render(d) html_content = htmly.render(d) from_email = self.writeitinstance.slug+"@"+settings.DEFAULT_FROM_DOMAIN msg = EmailMultiAlternatives(_('Moderation required for\ a message in WriteIt'), text_content,#content from_email,#From [self.writeitinstance.owner.email]#To ) msg.attach_alternative(html_content, "text/html") msg.send()
def test_wildcard_reverse(self): # Falls through to settings.ROOT_URLCONF subdomain = 'wildcard' self.assertEqual(reverse('home', subdomain), 'http://%s.%s/' % (subdomain, self.DOMAIN)) self.assertEqual(reverse('view', subdomain), 'http://%s.%s/view/' % (subdomain, self.DOMAIN))
def test_there_is_an_endpoint(self): """There is an endpoint to which posting updates an answer""" reverse( "update_answer", subdomain=self.message.writeitinstance.slug, kwargs={"message_pk": self.answer.message.pk, "pk": self.answer.pk}, )
def get_absolute_url(self): if self.series: return reverse( 'articles:article', args=[self.series.slug, self.slug], subdomain='articles') return reverse( 'articles:article', args=[self.slug], subdomain='articles')
def test_post_to_create_an_instance(self): c = self.client c.login(username=self.user.username, password='******') url = reverse('create_writeit_instance') response = c.post(url, data=self.data) instance = WriteItInstance.objects.get(slug='test-instance-slug', owner=self.user) self.assertRedirects(response, reverse('welcome', subdomain=instance.slug)) self.assertTrue(instance.persons.all())
def list_all(request): """Catch all view that combines results from units and challenges.""" if not request.user.is_authenticated(): return HttpResponse(status=401) group_id = request.GET.get('group', None) if group_id is None: return HttpResponse(status=400) group = get_object_or_404(Group, pk=int(group_id)) login_base = reverse('app_login', subdomain='accounts', scheme=request.scheme) units = [] # TODO: Actually make this list group dependant. for unit in LearningUnit.objects.all(): activity = unit.get_next_activity_for_user(request.user) token = create_token( request.user.pk, group.pk, activity.app.pk).decode('utf-8') units.append({ 'id': unit.pk, 'label': unit.label, 'login': "******" % (login_base, token), 'token': token}) challenges = [] # TODO: Actually make this list group dependant. for challenge in Challenge.objects.all(): app = get_app_by_url(challenge.url) if app is not None: token = create_token( request.user.pk, group.pk, app.pk).decode('utf-8') login_url = "%s?token=%s" % (login_base, token) else: token = None login_url = None challenges.append({ 'id': challenge.pk, 'label': challenge.label, 'url': route_links_in_text(request, challenge.url, group), 'login': login_url, 'token': token, 'details': "%s/?group=%s" % ( reverse("collections_challenge_detail", args=(challenge.pk,), subdomain="api",scheme=request.scheme), group_id), 'body': route_links_in_text(request, challenge.body, group), }) return JsonResponse({'items': {'units': units, 'challenges': challenges}})
def test_there_is_a_url_for_posting_new_webhooks(self): '''There is a url where we can post information for a new webhook''' url = reverse('writeitinstance_create_webhooks', subdomain=self.writeitinstance.slug) self.client.login(username=self.writeitinstance.owner.username, password='******') data = {'url': 'http://new.answers.will.be.posted/here'} response = self.client.post(url, data=data) url_listing_webhooks = reverse('writeitinstance_webhooks', subdomain=self.writeitinstance.slug) self.assertRedirects(response, url_listing_webhooks) webhook = self.writeitinstance.answer_webhooks.first() self.assertEquals(webhook.url, data['url'])
def test_there_is_an_endpoint(self): '''There is an endpoint to which posting updates an answer''' reverse( 'update_answer', subdomain=self.message.writeitinstance.slug, kwargs={ 'message_pk': self.answer.message.pk, 'pk': self.answer.pk }, )
def test_post_to_create_an_instance(self): your_instances_url = reverse('your-instances') c = Client() c.login(username=self.user.username, password='******') url = reverse('create_writeit_instance') self.assertTrue(url) response = c.post(url, data=self.data) self.assertRedirects(response, your_instances_url) instance = WriteItInstance.objects.get(Q(name='instance'), Q(owner=self.user)) self.assertTrue(instance.persons.all())
def test_it_redirects_to_your_instances(self): '''When get to create an instance it redirects to your instances''' url = reverse('create_writeit_instance') c = Client() response = c.get(url) c.login(username=self.user.username, password='******') response = c.get(url) your_instances_url = reverse('your-instances') self.assertRedirects(response, your_instances_url)
def test_insights_about_pulling_popit_even_if_everything_goes_ok(self): '''Return some insights even if everything goes ok''' self.client.login(username="******", password="******") url = reverse('relate-writeit-popit', subdomain=self.writeitinstance.slug) data = self.data response = self.client.post(url, data=data) expected_follow_url = reverse('relate-writeit-popit', subdomain=self.writeitinstance.slug) self.assertRedirects(response, expected_follow_url) response = self.client.get(expected_follow_url) messages = list(response.context['messages']) self.assertTrue(messages) self.assertEquals(messages[0].message, _("We are now getting the people from popit"))
def test_go_straight_to_draft_given_person_id(self): url = reverse('write_message_step', subdomain=self.writeitinstance.slug, kwargs={'step': 'who'}) url2 = reverse('write_message_step', subdomain=self.writeitinstance.slug, kwargs={'step': 'draft'}) response = self.client.get(url, {'person_id': self.person1.popit_id}) self.assertRedirects(response, url2) response = self.client.get(url2) self.assertEquals(response.context['message']['persons'][0].id, self.person1.id)
def test_posting_to_that_url_rejects_the_message(self): """When posting to reject a message it marks it private""" url = reverse("reject_message", subdomain=self.writeitinstance.slug, kwargs={"pk": self.message.pk}) c = self.client c.login(username=self.writeitinstance.owner.username, password="******") response = c.post(url) """It should redirect to the see all messages url""" allmessages_url = reverse("messages_per_writeitinstance", subdomain=self.writeitinstance.slug) self.assertRedirects(response, allmessages_url) message = Message.objects.get(pk=self.message.pk) self.assertFalse(message.public) self.assertTrue(message.moderated)
def test_post_to_url(self): '''When I post to the URL then it deletes the writeitinstance''' url = reverse('delete_an_instance', subdomain=self.writeitinstance.slug) request = self.factory.post(url) request.user = self.writeitinstance.owner response = WriteItDeleteView.as_view()(request) # Now it should be deleted self.assertFalse(WriteItInstance.objects.filter(id=self.writeitinstance.id)) your_instances_url = reverse('your-instances') self.assertTrue(response) self.assertEquals(response.status_code, 302) self.assertEquals(response.url, your_instances_url)
def test_posting_to_that_url_rejects_the_message(self): '''When posting to reject a message it marks it private''' url = reverse('reject_message', subdomain=self.writeitinstance.slug, kwargs={'pk': self.message.pk}) c = self.client c.login(username=self.writeitinstance.owner.username, password='******') response = c.post(url) '''It should redirect to the see all messages url''' allmessages_url = reverse('messages_per_writeitinstance', subdomain=self.writeitinstance.slug) self.assertRedirects(response, allmessages_url) message = Message.objects.get(pk=self.message.pk) self.assertFalse(message.public) self.assertTrue(message.moderated)
def test_post_to_the_url(self): '''It should reject the get to that url''' self.client.login(username="******", password="******") url = reverse('relate-writeit-popit', subdomain=self.writeitinstance.slug) response = self.client.post(url, data=self.data) self.assertEquals(response.status_code, 302) basic_update_url = reverse('relate-writeit-popit', subdomain=self.writeitinstance.slug) self.assertRedirects(response, basic_update_url) records = WriteitInstancePopitInstanceRecord.objects.filter(writeitinstance=self.writeitinstance) self.assertEquals(records.count(), 1) # this means that it has persons related to it self.assertTrue(self.writeitinstance.persons.all())
def test_turning_moderation_on(self): url = reverse('writeitinstance_moderation_update', subdomain=self.writeitinstance.slug) modified_data = {'moderation_needed_in_all_messages': 'on'} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get(id=self.writeitinstance.id) self.assertTrue(writeitinstance.config.moderation_needed_in_all_messages)
def test_rate_limit_cannot_be_negative(self): url = reverse('writeitinstance_ratelimiter_update', subdomain=self.writeitinstance.slug) modified_data = {'rate_limiter': -1} self.client.login(username=self.owner.username, password='******') response = self.client.post(url, data=modified_data, follow=True) self.assertTrue(response.context['form'].errors) self.assertTrue(response.context['form'].errors['rate_limiter'])
def test_access_the_search_url(self): url = reverse('search_messages') url += '/' response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertIsInstance(response.context['form'], MessageSearchForm)
def test_change_rate_limit(self): url = reverse('writeitinstance_ratelimiter_update', subdomain=self.writeitinstance.slug) modified_data = {'rate_limiter': 10} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get(id=self.writeitinstance.id) self.assertEquals(writeitinstance.config.rate_limiter, 10)
def url(context, view, subdomain=UNSET, *args, **kwargs): """ Resolves a URL in a template, using subdomain-based URL resolution. If no subdomain is provided and a ``request`` is in the template context when rendering, the URL will be resolved relative to the current request's subdomain. If no ``request`` is provided, the URL will be resolved relative to current domain with the ``settings.ROOT_URLCONF``. Usage:: {% load subdomainurls %} {% url 'view-name' subdomain='subdomain' %} .. note:: This tag uses the variable URL syntax introduced in Django 1.3 as ``{% load url from future %}`` and was made the standard in Django 1.5. If you are upgrading a legacy application from one of the previous template tag formats, make sure to quote your constant string URL names to avoid :exc:`~django.core.urlresolver.NoReverseMatch` errors during template rendering. """ if subdomain is UNSET: request = context.get("request") if request is not None: subdomain = getattr(request, "subdomain", None) else: subdomain = None elif subdomain is "": subdomain = None return reverse(view, subdomain=subdomain, args=args, kwargs=kwargs)
def test_max_recipients_cannot_rise_more_than_settings(self): url = reverse('writeitinstance_recipients_settings_update', subdomain=self.writeitinstance.slug) modified_data = {'maximum_recipients': 11} self.client.login(username=self.owner.username, password='******') response = self.client.post(url, data=modified_data, follow=True) self.assertTrue(response.context['form'].errors) self.assertTrue(response.context['form'].errors['maximum_recipients'])
def test_create_an_instance_get_not_logged(self): '''Create an instance get''' url = reverse('create_writeit_instance') c = self.client response = c.get(url) self.assertRedirectToLogin(response)
def test_updating_templates_views(self): self.writeitinstance.owner.set_password("feroz") self.writeitinstance.owner.save() c = self.client c.login(username=self.writeitinstance.owner.get_username(), password='******') url = reverse('writeitinstance_template_update', subdomain=self.writeitinstance.slug) response = c.get(url) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, 'base_manager.html') self.assertTemplateUsed(response, 'nuntium/profiles/templates.html') self.assertIsInstance(response.context['new_answer_template_form'], NewAnswerNotificationTemplateForm) self.assertIsInstance(response.context['mailit_template_form'], MailitTemplateForm) confirmation_template_form = response.context['confirmation_template_form'] self.assertIsInstance(confirmation_template_form, ConfirmationTemplateForm) mailit_template_form = response.context['mailit_template_form'] self.assertEquals(mailit_template_form.instance, self.writeitinstance.mailit_template) form = response.context['new_answer_template_form'] self.assertEquals(form.instance, self.writeitinstance.new_answer_notification_template) self.assertEquals(confirmation_template_form.writeitinstance, self.writeitinstance) self.assertEquals(confirmation_template_form.instance, self.writeitinstance.confirmationtemplate) non_user = self.client_class() response2 = non_user.get(url) self.assertRedirectToLogin(response2, next_url=url) # Benito does not own the instance User.objects.create_user(username="******", email="*****@*****.**", password="******") fiera_client = self.client fiera_client.login(username="******", password="******") response = fiera_client.get(url) self.assertEquals(response.status_code, 404)
def test_per_instance_api_docs(self): url = reverse('writeitinstance_api_docs', subdomain=self.writeitinstance.slug) request = self.factory.get(url) request.user = self.writeitinstance.owner response = WriteItInstanceApiDocsView.as_view()(request, pk=self.writeitinstance.pk) self.assertContains(response, 'api/v1/message/?format=json&username=admin&api_key=')
def test_turning_api_autoconfirm_off(self): url = reverse('writeitinstance_api_autoconfirm_update', subdomain=self.writeitinstance.slug) modified_data = {} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get(id=self.writeitinstance.id) self.assertFalse(writeitinstance.config.autoconfirm_api_messages)
def test_turning_web_based_on(self): url = reverse('writeitinstance_webbased_update', subdomain=self.writeitinstance.slug) modified_data = {'allow_messages_using_form': 'on'} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get(id=self.writeitinstance.id) self.assertTrue(writeitinstance.config.allow_messages_using_form)
def test_set_max_recipients_to_1(self): url = reverse('writeitinstance_recipients_settings_update', subdomain=self.writeitinstance.slug) modified_data = {'maximum_recipients': 1} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get(id=self.writeitinstance.id) self.assertEquals(writeitinstance.config.maximum_recipients, 1)
def test_get_the_url(self): url = reverse('message_threads', subdomain=self.writeitinstance.slug) response = self.client.get(url) self.assertEquals(response.status_code, 200) public_messages = Message.public_objects.filter( writeitinstance=self.writeitinstance) self.assertEquals(len(response.context['message_list']), public_messages.count())
def test_get_answers_per_messages_is_not_reachable_by_non_user(self): """ When a user is not logged in he cannot see the answers per message """ url = reverse('message_detail_private', subdomain=self.writeitinstance.slug, kwargs={'pk': self.message.pk}) c = self.client response = c.get(url) self.assertRedirectToLogin(response, next_url=url)
def test_max_recipients_cannot_rise_more_than_settings(self): url = reverse('writeitinstance_maxrecipients_update', subdomain=self.writeitinstance.slug) modified_data = {'maximum_recipients': 11} self.client.login(username=self.owner.username, password='******') response = self.client.post(url, data=modified_data, follow=True) self.assertTrue(response.context['form'].errors) self.assertTrue(response.context['form'].errors['maximum_recipients'])
def test_has_an_url(self): url = reverse('messages_per_person', subdomain=self.writeitinstance.slug, kwargs={ 'pk': self.pedro.id, }) self.assertTrue(url)
def test_confirmation_get_absolute_url(self): confirmation = Confirmation.objects.create(message=self.message) expected_url = reverse( 'confirm', subdomain=self.message.writeitinstance.slug, kwargs={'slug': confirmation.key}, ) self.assertEquals(expected_url, confirmation.get_absolute_url())
def test_get_absolute_url(self): writeitinstance1 = WriteItInstance.objects.get(id=1) expected_url = reverse( 'instance_detail', subdomain=writeitinstance1.slug, ) self.assertEquals(expected_url, writeitinstance1.get_absolute_url())
def test_it_cannot_be_accessed_by_a_non_user(self): '''A non user cannot reject a message''' url = reverse('reject_message', subdomain=self.writeitinstance.slug, kwargs={'pk': self.message.pk}) c = self.client response = c.get(url) self.assertRedirectToLogin(response, next_url=url)
def test_it_does_not_confirm_twice(self): confirmation = Confirmation.objects.create(message=self.message) url = reverse( 'confirm', subdomain=self.message.writeitinstance.slug, kwargs={'slug': confirmation.key}, ) response1 = self.client.get(url) message_thread = reverse( 'thread_read', subdomain=self.message.writeitinstance.slug, kwargs={ 'slug': self.message.slug }) response2 = self.client.get(url) self.assertEquals(response1.status_code, 302) self.assertRedirects(response2, message_thread)
def test_the_messages_url_is_not_reachable_by_non_user(self): """ The messages url is not reachable by someone who is not logged in """ url = reverse('messages_per_writeitinstance', subdomain=self.writeitinstance.slug) c = self.client response = c.get(url) self.assertRedirectToLogin(response, next_url=url)
def test_person_id_param(self): url = reverse('messages_per_person_id', subdomain=self.writeitinstance.slug, kwargs={ 'person_id': self.pedro.popit_id, }) response = self.client.get(url) self.assertEquals(response.context['person'], self.pedro)
def test_if_moderation_needed_moderation_column_displayed(self): self.writeitinstance.config.moderation_needed_in_all_messages = True self.writeitinstance.config.save() url = reverse('messages_per_writeitinstance', subdomain=self.writeitinstance.slug) self.client.login(username=self.writeitinstance.owner.username, password='******') response = self.client.get(url) self.assertContains(response, 'Moderated')
def test_get_url(self): '''Get the url for creating a new instance (it doesn't redrect anywhere)''' url = reverse('create_writeit_instance') request = self.factory.get(url) request.user = self.user response = WriteItInstanceCreateView.as_view()(request) # print response.render() self.assertEquals(response.status_code, 200)
def test_post_to_create_an_answer(self): ''' When posting for the creation of an answer ''' previous_count = Answer.objects.filter(message=self.message).count() data = { 'person': self.message.people.all()[0].pk, 'content': "hello this is an answer", } url = reverse('create_answer', subdomain=self.writeitinstance.slug, kwargs={'pk': self.message.pk}) c = self.client c.login(username=self.writeitinstance.owner.username, password='******') response = c.post(url, data=data) detail_message_url = reverse('message_detail_private', subdomain=self.message.writeitinstance.slug, kwargs={'pk': self.message.pk}) self.assertRedirects(response, detail_message_url) new_count = Answer.objects.filter(message=self.message).count() self.assertEquals(new_count, previous_count + 1)
def get_absolute_url(self): return reverse( 'thread_read', subdomain=self.writeitinstance.slug, kwargs={ 'slug': self.slug, }, )
def test_post_to_the_url(self): '''It should reject the get to that url''' self.client.login(username="******", password="******") url = reverse('relate-writeit-popit', subdomain=self.writeitinstance.slug) response = self.client.post(url, data=self.data) self.assertEquals(response.status_code, 302) basic_update_url = reverse('relate-writeit-popit', subdomain=self.writeitinstance.slug) self.assertRedirects(response, basic_update_url) records = WriteitInstancePopitInstanceRecord.objects.filter( writeitinstance=self.writeitinstance) self.assertEquals(records.count(), 1) # this means that it has persons related to it self.assertTrue(self.writeitinstance.persons.all())
def test_I_can_access_the_docs(self): url = reverse('user_section_documentation') self.assertTrue(url) c = self.client c.login(username=self.writeitinstance.owner.username, password='******') response = c.get(url) self.assertTemplateUsed(response, "nuntium/profiles/docs.html")
def send_confirmation_email(sender, instance, created, **kwargs): confirmation = instance if created: confirmation_url = reverse( 'confirm', subdomain=confirmation.message.writeitinstance.slug, kwargs={'slug': confirmation.key}, ) message_full_url = confirmation.message.get_absolute_url() plaintext = confirmation.message.writeitinstance.confirmationtemplate.get_content_template( ) htmly = confirmation.message.writeitinstance.confirmationtemplate.content_html subject = confirmation.message.writeitinstance.confirmationtemplate.get_subject_template( ) subject = subject.rstrip() context = { 'author_name': confirmation.message.author_name, 'site_name': confirmation.message.writeitinstance.name, 'subject': confirmation.message.subject, 'content': confirmation.message.content, 'recipients': u', '.join([x.name for x in confirmation.message.people]), 'confirmation_url': confirmation_url, 'message_url': message_full_url, } text_content = template_with_wrap(plaintext, context) subject = subject.format(**context) html_content = htmly.format(**escape_dictionary_values(context)) if settings.SEND_ALL_EMAILS_FROM_DEFAULT_FROM_EMAIL: from_email = settings.DEFAULT_FROM_EMAIL else: from_domain = confirmation.message.writeitinstance.config.custom_from_domain\ or settings.DEFAULT_FROM_DOMAIN from_email = "%s@%s" % ( confirmation.message.writeitinstance.slug, from_domain, ) connection = confirmation.message.writeitinstance.config.get_mail_connection( ) msg = EmailMultiAlternatives( subject, text_content, from_email, [confirmation.message.author_email], connection=connection, ) if html_content: msg.attach_alternative(html_content, "text/html") try: msg.send() except: pass
def test_turning_api_autoconfirm_off(self): url = reverse('writeitinstance_api_autoconfirm_update', subdomain=self.writeitinstance.slug) modified_data = {} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get( id=self.writeitinstance.id) self.assertFalse(writeitinstance.config.autoconfirm_api_messages)
def test_post_updated_answer(self): '''Posting updated answer''' url = reverse( 'update_answer', subdomain=self.message.writeitinstance.slug, kwargs={ 'message_pk': self.answer.message.pk, 'pk': self.answer.pk }, ) c = self.client c.login(username=self.writeitinstance.owner.username, password='******') data = {'content': "this is the new content"} response = c.post(url, data=data) detail_message_url = reverse('message_detail_private', subdomain=self.message.writeitinstance.slug, kwargs={'pk': self.message.pk}) self.assertRedirects(response, detail_message_url) answer = Answer.objects.get(id=self.answer.id) self.assertTrue(answer.content, data['content'])
def test_if_theres_a_single_contact_skip_the_first_step(self): '''If theres a single contact skip the first step and select the single person''' url = reverse('write_message_step', subdomain=self.writeitinstance.slug, kwargs={'step': 'who'}) # Deleting Marcel self.writeitinstance.persons.get(id=2).delete() # ok so I've deleted Marcel from the list of people that is in this instance # so when I get this response I'm expecting to take me directly to # the second step . response = self.client.get(url) url2 = reverse('write_message_step', subdomain=self.writeitinstance.slug, kwargs={'step': 'draft'}) self.assertRedirects(response, url2) response2 = self.client.get(url2) self.assertEquals(response2.status_code, 200)
def test_turning_answer_notification_off(self): url = reverse('writeitinstance_answernotification_update', subdomain=self.writeitinstance.slug) modified_data = {} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get( id=self.writeitinstance.id) self.assertFalse(writeitinstance.config.notify_owner_when_new_answer)
def test_get_the_url_brings_the_instance_and_renders_the_template(self): '''When getting the url brings some stats and renders the specific template''' url = reverse('stats', subdomain=self.writeitinstance.slug) self.client.login(username=self.writeitinstance.owner, password="******") response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertIn('writeitinstance', response.context) self.assertTemplateUsed(response, 'nuntium/profiles/stats.html')
def test_list_instances(self): activate('en') instance1 = WriteItInstance.objects.get(id=1) url = reverse("home") response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertTrue(response.context['writeitinstances']) self.assertEquals(response.context['writeitinstances'].count(), 2) self.assertEquals(response.context['writeitinstances'][0], instance1)
def test_change_rate_limit(self): url = reverse('writeitinstance_ratelimiter_update', subdomain=self.writeitinstance.slug) modified_data = {'rate_limiter': 10} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get( id=self.writeitinstance.id) self.assertEquals(writeitinstance.config.rate_limiter, 10)
def test_turning_web_based_on(self): url = reverse('writeitinstance_webbased_update', subdomain=self.writeitinstance.slug) modified_data = {'allow_messages_using_form': 'on'} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get( id=self.writeitinstance.id) self.assertTrue(writeitinstance.config.allow_messages_using_form)
def test_set_max_recipients_to_1(self): url = reverse('writeitinstance_recipients_settings_update', subdomain=self.writeitinstance.slug) modified_data = {'maximum_recipients': 1} self.client.login(username=self.owner.username, password='******') self.client.post(url, data=modified_data, follow=True) writeitinstance = WriteItInstance.objects.get( id=self.writeitinstance.id) self.assertEquals(writeitinstance.config.maximum_recipients, 1)
def test_the_url_exists_and_is_reachable_when_logged(self): c = self.client c.login(username='******', password='******') url = reverse('account') response = c.get(url) self.assertEquals(response.status_code, 200) self.assertTemplateUsed(response, "nuntium/profiles/your-profile.html") self.assertTemplateUsed(response, "base_manager.html")
def register(request): form = UserForm() if request.method == 'POST': form = UserForm(request.POST) if form.is_valid(): school = form.save() return redirect(reverse('school', subdomain=school.username)) return render(request, 'register.html', {'form': form})
def test_get_messages_404(self): '''Gets a 404 if the slug of an instance does not exist''' url = reverse( 'all-messages-from-the-same-author-as', subdomain='non-existing', kwargs={ 'message_slug': self.message.slug, # This slug does not exists }) self.assertEquals(self.client.get(url).status_code, 404)