<commit_before>from django.test import TestCase
from django.test.client import Client
from django.shortcuts import resolve_url as r
from django.contrib.auth.models import User

from myideas.core.models import Idea


class DetailsTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.username = 'diego'
        self.email = '<EMAIL>'
        self.password = '<PASSWORD>'
        user = User.objects.create_user(
            self.username, self.email, self.password
        )

        self.idea = Idea.objects.create(
            user=user, title='test app', tags='django'
        )
        self.response = self.client.get(r(self.idea.get_absolute_url()))

    def api_signin_and_get(self):
        self.login = self.client.login(
            username=self.username, password=<PASSWORD>
        )

    def test_get(self):
        """GET 'Idea Details' must return status code 200"""
        self.assertEqual(200, self.response.status_code)

    def test_template(self):
        """'Idea Details' must use template ideas_details.html and base.html"""
        self.assertTemplateUsed(self.response, 'ideas_details.html')
        self.assertTemplateUsed(self.response, 'base.html')

    def test_update_and_delete_link(self):
        """Details contains update/delete links"""
        self.api_signin_and_get()
        response = self.client.get(r(self.idea.get_absolute_url()))
        contents = [
            f'href="{r("update", self.idea.slug)}"',
            f'href="{r("delete", self.idea.slug)}"',
        ]
        for expected in contents:
            with self.subTest():
                self.assertContains(response, expected)

    def test_html(self):
        self.assertContains(self.response, self.idea.user)
        self.assertContains(self.response, self.idea.title)
        self.assertContains(self.response, self.idea.slug)

    def test_links(self):
        """Details contains tags/twitter/fb and disqus thread links"""
        contents = [
            f'href="{r("by_tags", self.idea.tags)}"',
            f'href="{r("https://twitter.com/share")}"',
            'fb-share-button',
            'disqus_thread'
        ]
        for expected in contents:
            with self.subTest():
                self.assertContains(self.response, expected)

    def test_context(self):
        """Idea must be in context"""
        ideas = self.response.context['ideas']
        self.assertIsInstance(ideas, Idea)

    def not_found(self):
        self.resp = self.client.get(r(
            'idea_details', slug='not-found')
        )

    def test_page_not_found(self):
        """GET page not found must return status code 404"""
        self.not_found()
        self.assertEqual(404, self.resp.status_code)

    def test_template_not_found(self):
        """'page not found' must use template 404.html and base.html"""
        self.not_found()
        self.assertTemplateUsed(self.resp, '404.html')
        self.assertTemplateUsed(self.resp, 'base.html')<commit_msg>refactor test, change format to fstrings<commit_after>from django.test import TestCase
from django.test.client import Client
from django.shortcuts import resolve_url as r
from django.contrib.auth.models import User

from myideas.core.models import Idea


class DetailsTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.username = 'diego'
        self.email = '<EMAIL>'
        self.password = '<PASSWORD>'
        user = User.objects.create_user(
            self.username, self.email, self.password
        )

        self.idea = Idea.objects.create(
            user=user, title='test app', tags='django'
        )
        self.response = self.client.get(r(self.idea.get_absolute_url()))

    def api_signin_and_get(self):
        self.login = self.client.login(
            username=self.username, password=self.password
        )

    def test_get(self):
        """GET 'Idea Details' must return status code 200"""
        self.assertEqual(200, self.response.status_code)

    def test_template(self):
        """'Idea Details' must use template ideas_details.html and base.html"""
        self.assertTemplateUsed(self.response, 'ideas_details.html')
        self.assertTemplateUsed(self.response, 'base.html')

    def test_update_and_delete_link(self):
        """Details contains update/delete links"""
        self.api_signin_and_get()
        response = self.client.get(r(self.idea.get_absolute_url()))
        contents = (
            f'href="{r("update", self.idea.slug)}"',
            f'href="{r("delete", self.idea.slug)}"',
        )
        for expected in contents:
            with self.subTest():
                self.assertContains(response, expected)

    def test_html(self):
        self.assertContains(self.response, self.idea.user)
        self.assertContains(self.response, self.idea.title)
        self.assertContains(self.response, self.idea.slug)

    def test_links(self):
        """Details contains tags/twitter/fb and disqus thread links"""
        contents = (
            f'href="{r("by_tags", self.idea.tags)}"',
            f'href="{r("https://twitter.com/share")}"',
            'fb-share-button',
            'disqus_thread'
        )
        for expected in contents:
            with self.subTest():
                self.assertContains(self.response, expected)

    def test_context(self):
        """Idea must be in context"""
        ideas = self.response.context['ideas']
        self.assertIsInstance(ideas, Idea)

    def not_found(self):
        self.resp = self.client.get(r(
            'idea_details', slug='not-found')
        )

    def test_page_not_found(self):
        """GET page not found must return status code 404"""
        self.not_found()
        self.assertEqual(404, self.resp.status_code)

    def test_template_not_found(self):
        """'page not found' must use template 404.html and base.html"""
        self.not_found()
        self.assertTemplateUsed(self.resp, '404.html')
        self.assertTemplateUsed(self.resp, 'base.html')
{'fraction_non_alphanumeric': 0.12491716368455931, 'fraction_numerical': 0.005964214711729622, 'mean_word_length': 2.499710144927536, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7307385', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1743, 'n_words': 362}