コード例 #1
0
ファイル: test_utils.py プロジェクト: providenz/phase
    def test_invalid_data_unknown_user(self):
        """Can only create lists with known users."""
        qs = DistributionList.objects.all()
        self.assertEqual(qs.count(), 0)

        xls_file = os.path.join(
            os.path.dirname(__file__),
            'fixtures',
            'distrib_list_unknown_user.xlsx')
        import_lists(xls_file, self.category)

        self.assertEqual(qs.count(), 1)
コード例 #2
0
ファイル: test_utils.py プロジェクト: providenz/phase
    def test_invalid_data_invalid_category(self):
        """Users have to belong to the category."""
        qs = DistributionList.objects.all()
        self.assertEqual(qs.count(), 0)

        xls_file = os.path.join(
            os.path.dirname(__file__),
            'fixtures',
            'distrib_list_wrong_category.xlsx')
        import_lists(xls_file, self.category)

        self.assertEqual(qs.count(), 1)
コード例 #3
0
ファイル: test_utils.py プロジェクト: providenz/phase
    def test_invalid_data_no_leader(self):
        """Cannot import lists without a leader."""
        qs = DistributionList.objects.all()
        self.assertEqual(qs.count(), 0)

        xls_file = os.path.join(
            os.path.dirname(__file__),
            'fixtures',
            'distrib_list_missing_leader.xlsx')
        import_lists(xls_file, self.category)

        self.assertEqual(qs.count(), 1)
コード例 #4
0
ファイル: test_utils.py プロジェクト: providenz/phase
    def test_importing_twice_with_different_categories(self):
        qs = DistributionList.objects.all()
        self.assertEqual(qs.count(), 0)

        xls_file = os.path.join(
            os.path.dirname(__file__),
            'fixtures',
            'valid_distrib_list.xlsx')
        import_lists(xls_file, self.category)
        import_lists(xls_file, self.other_category)

        self.assertEqual(qs.count(), 5)
        self.assertEqual(len(qs[0].categories.all()), 2)
コード例 #5
0
ファイル: test_utils.py プロジェクト: providenz/phase
    def test_successful_import(self):
        """Importing the file creates the distribution lists."""
        qs = DistributionList.objects.all()
        self.assertEqual(qs.count(), 0)

        xls_file = os.path.join(
            os.path.dirname(__file__),
            'fixtures',
            'valid_distrib_list.xlsx')
        import_lists(xls_file, self.category)

        self.assertEqual(qs.count(), 5)

        self.assertEqual(qs[0].name, 'Liste 1')
        self.assertEqual(qs[0].leader.email, '*****@*****.**')
        self.assertEqual(qs[0].approver.email, '*****@*****.**')
        self.assertEqual(qs[0].reviewers.count(), 2)

        self.assertEqual(qs[2].name, 'Liste 3')
        self.assertEqual(qs[2].leader.email, '*****@*****.**')
        self.assertIsNone(qs[2].approver)
コード例 #6
0
    def form_valid(self, form):
        category = form.cleaned_data['category']
        xls_file = form.files['xls_file']

        context = self.get_context_data(form=form)
        try:
            results = import_lists(xls_file, category)
            context.update({'results': results})
        except:  # noqa
            # Any error occurred, file must be inparsable
            error_msg = _(
                "We could'nt parse your file. Is this a valid xlsx file?")
            context.update({'non_form_errors': error_msg})

        return self.render_to_response(context)
コード例 #7
0
ファイル: views.py プロジェクト: providenz/phase
    def form_valid(self, form):
        category = form.cleaned_data['category']
        xls_file = form.files['xls_file']

        context = self.get_context_data(form=form)
        try:
            results = import_lists(xls_file, category)
            context.update({
                'results': results
            })
        except:
            # Any error occurred, file must be inparsable
            error_msg = _("We could'nt parse your file. Is this a valid xlsx file?")
            context.update({
                'non_form_errors': error_msg
            })

        return self.render_to_response(context)
コード例 #8
0
ファイル: test_utils.py プロジェクト: providenz/phase
    def test_import_overrides_existing_content(self):
        """Importing is an idempotent action (PUT, not POST)."""
        qs = DistributionList.objects.all()
        self.assertEqual(qs.count(), 0)

        xls_file = os.path.join(
            os.path.dirname(__file__),
            'fixtures',
            'valid_distrib_list.xlsx')
        import_lists(xls_file, self.category)

        self.assertEqual(qs.count(), 5)

        import_lists(xls_file, self.category)
        self.assertEqual(qs.count(), 5)

        qs[0].delete()
        self.assertEqual(qs.count(), 4)

        import_lists(xls_file, self.category)
        self.assertEqual(qs.count(), 5)