Exemplo n.º 1
0
    def setUp(self):
        # Getting all permissions codenames
        all_perms = Permission.objects.all()
        perms_codenames = list()
        for perm in all_perms:
            perms_codenames.append(perm.codename)

        self.test_cases = 10

        # Create group Administrator (Allowed: Create, Update, Delete)
        self.user = UserFactory.build()
        self.user.username = "******"
        self.user.set_password("password")
        self.user_permissions = perms_codenames  # Give all permissions to user
        self.user.save()

        self.login_url = reverse("api:login")
        self.extdatas_url = reverse("api:sources-externaldata_list")

        # Create token for user authentication
        self.auth_token = Token.objects.create(user=self.user)
        self.auth_url = "Token " + self.auth_token.key

        self.extdatas = list()
        for i in range(self.test_cases):
            self.new_extdata = ExternalDataFactory.build()
            self.new_extdata.save()
            self.extdatas.append(self.new_extdata)
            i = i + 1
Exemplo n.º 2
0
    def step_user_exists(self, username):
        r'user "([^"]+)" exists'

        user = UserFactory.build(username=username)
        user.is_staff = True
        user.set_password(username)
        user.save()
Exemplo n.º 3
0
    def test_should_return_not_valid_if_too_many_tasks(self):
        # Arrange
        author = UserFactory.build()
        owner = UserFactory.build()
        tasks_manager = Mock(Task.objects)
        tasks_manager.get_for_owner_by_author.return_value.count.return_value = TASKS_LIMIT + 1
        form = RestrictedAddTaskForm(
            self._data, author=author, owner=owner,
            tasks_manager=tasks_manager)

        # Act
        result = form.is_valid()

        # Assert
        self.assertFalse(result)
        msg = 'You have added to many tasks for %s' % owner.username
        self.assertTrue(msg in form.errors['__all__'])
Exemplo n.º 4
0
    def test_should_ignore_priority_if_passed(self):
        # Arrange
        author = UserFactory.build()
        owner = UserFactory.build()
        tasks_manager = Mock(Task.objects)
        tasks_manager.get_for_owner_by_author.return_value.count.return_value = 0
        form = RestrictedAddTaskForm(
            self._data, author=author, owner=owner,
            tasks_manager=tasks_manager)

        # Act
        result = form.is_valid()

        # Assert
        self.assertTrue(result)
        self.assertEqual(form.cleaned_data['title'], self._title)
        self.assertTrue('priority' not in form.cleaned_data)
Exemplo n.º 5
0
    def test_should_return_not_valid_if_too_many_tasks(self):
        # Arrange
        author = UserFactory.build()
        owner = UserFactory.build()
        tasks_manager = Mock(Task.objects)
        tasks_manager.get_for_owner_by_author.return_value.count.return_value = TASKS_LIMIT + 1
        form = RestrictedAddTaskForm(self._data,
                                     author=author,
                                     owner=owner,
                                     tasks_manager=tasks_manager)

        # Act
        result = form.is_valid()

        # Assert
        self.assertFalse(result)
        msg = 'You have added to many tasks for %s' % owner.username
        self.assertTrue(msg in form.errors['__all__'])
Exemplo n.º 6
0
    def test_should_ignore_priority_if_passed(self):
        # Arrange
        author = UserFactory.build()
        owner = UserFactory.build()
        tasks_manager = Mock(Task.objects)
        tasks_manager.get_for_owner_by_author.return_value.count.return_value = 0
        form = RestrictedAddTaskForm(self._data,
                                     author=author,
                                     owner=owner,
                                     tasks_manager=tasks_manager)

        # Act
        result = form.is_valid()

        # Assert
        self.assertTrue(result)
        self.assertEqual(form.cleaned_data['title'], self._title)
        self.assertTrue('priority' not in form.cleaned_data)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def test_should_validate_input(self):
        # Arrange
        owner = UserFactory.build()
        form = AddTaskForm(self._data, author=owner, owner=owner)

        # Act
        result = form.is_valid()

        # Assert
        self.assertTrue(result)
        self.assertEqual(form.cleaned_data['title'], self._title)
        self.assertEqual(form.cleaned_data['priority'], self._priority)
Exemplo n.º 11
0
    def test_should_validate_input(self):
        # Arrange
        owner = UserFactory.build()
        form = AddTaskForm(self._data, author=owner, owner=owner)

        # Act
        result = form.is_valid()

        # Assert
        self.assertTrue(result)
        self.assertEqual(form.cleaned_data['title'], self._title)
        self.assertEqual(form.cleaned_data['priority'], self._priority)