Пример #1
0
    def test_should_return_own_tasks(self):
        # Arrange
        TaskFactory.create_batch(self._num, owner=self._owner, author=self._owner)

        # Act
        result = Task.objects.get_for_owner_by_author(self._owner, self._owner)

        # Assert - should validate
        self.assertEqual(len(result), self._num)
        for task in result:
            self.assertEqual(task.owner, self._owner)
            self.assertEqual(task.author, self._owner)
Пример #2
0
    def test_should_return_own_tasks(self):
        # Arrange
        TaskFactory.create_batch(
            self._num,
            owner=self._owner,
            author=self._owner)

        # Act
        result = Task.objects.get_for_owner_by_author(self._owner, self._owner)

        # Assert - should validate
        self.assertEqual(len(result), self._num)
        for task in result:
            self.assertEqual(task.owner, self._owner)
            self.assertEqual(task.author, self._owner)
Пример #3
0
    def test_should_return_task_absolute_url(self):
        # Arrange
        owner = UserFactory.build(pk=1)
        task = TaskFactory.build(owner=owner, author=owner)

        # Act
        url = task.get_absolute_url()

        # Assert
        self.assertEqual(url, '/%s/' % owner.username)
Пример #4
0
    def test_should_show_only_author_tasks_on_foreign_profile(self):
        # Arrange
        template_name = 'tasks/show_current_tasks.html'
        owner = UserFactory.build()
        wife = UserFactory.build()
        bread = "buy bread"
        milk = "buy milk"
        tasks = [
            TaskFactory.build(title=bread, owner=owner, author=owner),
            TaskFactory.build(title=milk, owner=owner, author=wife),
        ]
        context = {
            'tasks': tasks,
            'user': wife,
        }
        # Act
        result = render_to_string(template_name, context)

        # Assert
        self.assertFalse("buy bread" in result)
        self.assertTrue("buy milk" in result)
Пример #5
0
    def test_should_show_only_author_tasks_on_foreign_profile(self):
        # Arrange
        template_name = 'tasks/show_current_tasks.html'
        owner = UserFactory.build()
        wife = UserFactory.build()
        bread = "buy bread"
        milk = "buy milk"
        tasks = [
            TaskFactory.build(title=bread, owner=owner, author=owner),
            TaskFactory.build(title=milk, owner=owner, author=wife),
        ]
        context = {
            'tasks': tasks,
            'user': wife,
        }
        # Act
        result = render_to_string(template_name, context)

        # Assert
        self.assertFalse("buy bread" in result)
        self.assertTrue("buy milk" in result)