Ejemplo n.º 1
0
    def test_examples(self):
        example_foo = factories.ExampleFactory(definition=self.definition,
                                               value='foo')
        example_bar = factories.ExampleFactory(definition=self.definition,
                                               value='bar')
        factories.ExampleFactory(value='qux')

        queryset = models.Example.objects.filter(
            pk__in=[example_foo.pk, example_bar.pk])
        self.assertQuerysetEqual(self.definition.examples,
                                 queryset,
                                 ordered=False,
                                 transform=lambda x: x)
Ejemplo n.º 2
0
    def test_update_definition__remove_example(self):
        self.assertEqual(models.Definition.objects.count(), 1)

        foo_example = factories.ExampleFactory(value="foo",
                                               definition=self.definition)
        bar_example = factories.ExampleFactory(value="bar",
                                               definition=self.definition)

        self.assertEqual(models.Example.objects.count(), 2)
        self.assertEqual(models.Example.all_objects.count(), 2)

        self._login()

        form_data = {
            'term': self.definition.term.value,
            'value': 'updated fake definition',
        }
        management_data = {
            "example_set-TOTAL_FORMS": "4",
            "example_set-INITIAL_FORMS": "2",
            "example_set-MIN_NUM_FORMS": "0",
            "example_set-MAX_NUM_FORMS": "5",
            "example_set-0-value": "foo",
            "example_set-0-id": "{}".format(foo_example.pk),
            "example_set-0-definition": "{}".format(self.definition.pk),
            "example_set-0-DELETE": "on",
            "example_set-1-value": "bar",
            "example_set-1-id": "{}".format(bar_example.pk),
            "example_set-1-definition": "{}".format(self.definition.pk),
            "example_set-2-value": "",
            "example_set-2-id": "",
            "example_set-2-definition": "{}".format(self.definition.pk),
            "example_set-3-value": "",
            "example_set-3-id": "",
            "example_set-3-definition": "{}".format(self.definition.pk),
        }
        form_data.update(management_data)

        response = self.client.post(self.url, form_data, follow=True)

        self.assertEqual(response.status_code, 200)

        self.assertEqual(models.Definition.objects.count(), 1)
        self.assertEqual(models.Example.objects.count(), 1)
        self.assertEqual(models.Example.all_objects.count(), 2)

        example = models.Example.objects.first()

        self.assertEqual(example.value, 'bar')
        self.assertEqual(example.definition, self.definition)
Ejemplo n.º 3
0
 def setUp(self):
     definition = factories.DefinitionFactory(
         uuid='13bf0f68-eeb2-4777-a739-6ee5be30bacc',
         value='fake_definition',
     )
     factories.ExampleFactory(definition=definition)
     self.client = test.Client()
     self.url = reverse('index')
Ejemplo n.º 4
0
    def test_has_examples(self):
        response = self.client.get(self.url)

        self.assertNotContains(response, 'fake example')

        factories.ExampleFactory(definition=self.definition_foo,
                                 value='fake example')

        response = self.client.get(self.url)

        self.assertContains(response, 'fake example')
Ejemplo n.º 5
0
    def test_inactive_examples_does_not_appear(self):
        response = self.client.get(self.url)

        factories.ExampleFactory(definition=self.definition,
                                 value='fake example')

        response = self.client.get(self.url)

        self.assertContains(response, 'fake example')

        self.assertEqual(models.Example.objects.count(), 1)
        example = models.Example.objects.first()

        example.active = False
        example.save()

        response = self.client.get(self.url)

        self.assertNotContains(response, 'fake example')
Ejemplo n.º 6
0
    def test_has_examples(self):
        self.assertFalse(self.definition.has_examples)

        factories.ExampleFactory(definition=self.definition)

        self.assertTrue(self.definition.has_examples)
Ejemplo n.º 7
0
 def setUpTestData(cls):
     cls.example = factories.ExampleFactory(value='my fake example')
Ejemplo n.º 8
0
 def setUp(self):
     self.example = factories.ExampleFactory(value='my fake example')