示例#1
0
    def test_suggestion_project_link(self):
        SuggestionFactory.create(title="Adoptable",
                                 destination="Amsterdam",
                                 status="accepted",
                                 project=None,
                                 token='x',
                                 org_name='Acme Inc.',
                                 org_email='*****@*****.**',
                                 org_website='http://example.com',
                                 org_phone='123123123',
                                 org_contactname='John Doe',
                                 pitch='Eat more cheese',
                                 language='en')
        response = self.client.get(self.suggestion_list_url, {
            'destination': "Amsterdam",
            status: "accepted"
        },
                                   HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)[0]
        project = ProjectFactory.create(title="Adopting project")

        data['project'] = project.slug

        self.client.put(reverse('suggestion_detail', kwargs={'pk':
                                                             data['id']}),
                        HTTP_AUTHORIZATION=self.user_1_token,
                        data=data)

        suggestion = Suggestion.objects.get(pk=data['id'])
        self.assertEquals(Project.objects.get(pk=project.pk),
                          suggestion.project)
示例#2
0
    def test_suggestion_project_link(self):
        SuggestionFactory.create(title="Adoptable",
                                 destination="Amsterdam",
                                 status="accepted",
                                 project=None,
                                 token='x',
                                 org_name='Acme Inc.',
                                 org_email='*****@*****.**',
                                 org_website='http://example.com',
                                 org_phone='123123123',
                                 org_contactname='John Doe',
                                 pitch='Eat more cheese'
                                 )
        response = self.client.get(self.suggestion_list_url,
                      {'destination': "Amsterdam", status: "accepted"},
                      HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)[0]
        project = ProjectFactory.create(title="Adopting project")

        data['project'] = project.slug

        r = self.client.put(reverse('suggestion_detail',
                                    kwargs={'pk':data['id']}),
                            HTTP_AUTHORIZATION=self.user_1_token,
                            data=data)

        suggestion = Suggestion.objects.get(pk=data['id'])
        self.assertEquals(Project.objects.get(pk=project.pk), suggestion.project)
示例#3
0
    def test_retrieve_suggestion_list_all_items(self):
        """
        Test if all suggestions are retrieved that have a deadline today or later
        """
        suggestion_2 = SuggestionFactory.create(deadline=date.today())
        suggestion_3 = SuggestionFactory.create(deadline=date.today())

        response = self.client.get(self.suggestion_list_url, HTTP_AUTHORIZATION=self.user_1_token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        data = json.loads(response.content)
        self.assertEqual(len(data), Suggestion.objects.count())
示例#4
0
    def test_retrieve_suggestion_list_all_items(self):
        """
        Test if all suggestions are retrieved that have a deadline today or later
        """
        SuggestionFactory.create(deadline=date.today())
        SuggestionFactory.create(deadline=date.today())

        response = self.client.get(self.suggestion_list_url,
                                   HTTP_AUTHORIZATION=self.user_1_token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        data = json.loads(response.content)
        self.assertEqual(len(data), Suggestion.objects.count())
示例#5
0
    def test_retrieve_suggestion_list_expired_deadlines(self):
        """
        Test that no suggestions are returned if there deadline is 'lower' than today
        """
        suggestion_2 = SuggestionFactory.create(deadline=date.today() - timedelta(1))
        suggestion_3 = SuggestionFactory.create(deadline=date.today() - timedelta(1))

        response = self.client.get(self.suggestion_list_url, HTTP_AUTHORIZATION=self.user_1_token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        data = json.loads(response.content)
        # We still have the original initialized Suggestion, so 1 instead of 0
        self.assertEqual(len(data), 1)
示例#6
0
    def test_retrieve_no_suggestions_with_fake_project_slug(self):
        """
        Test the project slug filter on the API endpoint. Shouldn't return any suggestions
        """
        project = ProjectFactory.create()
        SuggestionFactory.create(project=project)

        response = self.client.get(self.suggestion_list_url,
                                   {'project_slug': "non-existing-slug"},
                                   HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 0)
示例#7
0
    def test_suggestions_states(self):
        """ verify all other states / cases are counted properly """

        states = ("unconfirmed", "draft", "accepted", "rejected")

        for state in states:
            SuggestionFactory.create(title="Suggestion with state " + state,
                                     deadline=self.future,
                                     status=state)

        suggestion_metrics = self.metrics.calculate_suggestion_metrics()

        for state in states:
            self.assertEqual(suggestion_metrics[state], 1)
示例#8
0
    def test_retrieve_suggestion_list_expired_deadlines(self):
        """
        Test that no suggestions are returned if there deadline is 'lower' than today
        """
        SuggestionFactory.create(deadline=date.today() - timedelta(1))
        SuggestionFactory.create(deadline=date.today() - timedelta(1))

        response = self.client.get(self.suggestion_list_url,
                                   HTTP_AUTHORIZATION=self.user_1_token)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        data = json.loads(response.content)
        # We still have the original initialized Suggestion, so 1 instead of 0
        self.assertEqual(len(data), 1)
示例#9
0
    def test_retrieve_only_suggestions_with_project_slug(self):
        """
        Test the project slug filter on the API endpoint. Should return one suggestion
        """
        project = ProjectFactory.create()
        SuggestionFactory.create(project=project)

        response = self.client.get(self.suggestion_list_url,
                                   {'project_slug': project.slug},
                                   HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 1)

        self.assertEqual(data[0]['project'].lower(), project.slug)
示例#10
0
    def setUp(self):
        super(SuggestionsListIntegrationTest, self).setUp()
        self.user_1 = BlueBottleUserFactory.create()
        self.user_1_token = "JWT {0}".format(self.user_1.get_jwt_token())

        self.init_projects()
        self.suggestion = SuggestionFactory.create()
        self.suggestion_list_url = "/api/suggestions/"
示例#11
0
    def test_retrieve_only_suggestions_with_destination(self):
        """
        Test the destination filter on the API endpoint.
        """
        destination = 'amsterdam'

        suggestion_amsterdam_1 = SuggestionFactory.create(destination="Amsterdam")
        suggestion_amsterdam_2 = SuggestionFactory.create(destination="amsterdam")

        response = self.client.get(self.suggestion_list_url, {'destination': destination},
                                    HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 2)

        self.assertEqual(data[0]['destination'].lower(), destination)
        self.assertEqual(data[1]['destination'].lower(), destination)
示例#12
0
    def setUp(self):
        super(SuggestionsListIntegrationTest, self).setUp()
        self.user_1 = BlueBottleUserFactory.create()
        self.user_1_token = "JWT {0}".format(self.user_1.get_jwt_token())

        self.init_projects()
        self.suggestion = SuggestionFactory.create()
        self.suggestion_list_url = "/api/suggestions/"
示例#13
0
    def test_retrieve_only_suggestions_with_status(self):
        """
        Test the status filter on the API endpoint.
        """
        status = 'accepted'

        suggestion_accepted_1 = SuggestionFactory.create(status=status)
        suggestion_accepted_2 = SuggestionFactory.create(status=status)
        suggestion_other = SuggestionFactory.create(status='other')

        response = self.client.get(self.suggestion_list_url, {'status': status},
                                   HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 2)

        self.assertEqual(data[0]['status'].lower(), status)
        self.assertEqual(data[1]['status'].lower(), status)
示例#14
0
    def test_retrieve_only_suggestions_with_destination(self):
        """
        Test the destination filter on the API endpoint.
        """
        destination = 'amsterdam'

        SuggestionFactory.create(destination="Amsterdam")
        SuggestionFactory.create(destination="amsterdam")

        response = self.client.get(self.suggestion_list_url,
                                   {'destination': destination},
                                   HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 2)

        self.assertEqual(data[0]['destination'].lower(), destination)
        self.assertEqual(data[1]['destination'].lower(), destination)
示例#15
0
    def test_suggestions_expired(self):
        """ verify suggestions past the deadline are expired """
        yesterday = datetime.today() - timedelta(days=1)

        not1 = SuggestionFactory.create(title="expired suggestion",
                                        deadline=yesterday,
                                        status="submitted")

        suggestion_metrics = self.metrics.calculate_suggestion_metrics()
        self.assertEqual(suggestion_metrics['expired'], 1)
示例#16
0
    def test_suggestions_today_not_expired(self):
        """ if the deadline is today, there's still time """
        today = datetime.today()

        not1 = SuggestionFactory.create(title="expired suggestion",
                                        deadline=today,
                                        status="submitted")

        suggestion_metrics = self.metrics.calculate_suggestion_metrics()
        self.assertEqual(suggestion_metrics['expired'], 0)
示例#17
0
    def test_suggestions_adopted(self):
        """ a submitted suggestion with project is adopted, all others aren't """
        p = ProjectFactory()

        not1 = SuggestionFactory.create(title="wrong state",
                                        deadline=self.future,
                                        project=p,
                                        status="in_progress")
        not2 = SuggestionFactory.create(title="no project",
                                        project=None,
                                        deadline=self.future,
                                        status="submitted")
        adopt = SuggestionFactory.create(title="adopted",
                                         deadline=self.future,
                                         project=p,
                                         status="submitted")

        suggestion_metrics = self.metrics.calculate_suggestion_metrics()
        self.assertEqual(suggestion_metrics['adopted'], 1)
示例#18
0
    def test_retrieve_no_suggestions_with_fake_project_slug(self):
        """
        Test the project slug filter on the API endpoint. Shouldn't return any suggestions
        """
        project = ProjectFactory.create()
        suggestion_accepted_1 = SuggestionFactory.create(project=project)

        response = self.client.get(self.suggestion_list_url, {'project_slug': "non-existing-slug"},
                                    HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 0)
示例#19
0
    def test_token_validate_unauthorized(self):
        """ validate a suggesting by its token (authorized) """
        token = str(uuid.uuid4())
        suggestion = SuggestionFactory.create(token=token, status='unconfirmed')

        response = self.client.put(
            reverse('suggestion_token_validate', kwargs={'token':token}))

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        suggestion = Suggestion.objects.get(pk=suggestion.pk)

        self.assertEquals(suggestion.status, 'unconfirmed')
示例#20
0
    def test_token_validate_already_validated(self):
        """ validate a suggesting by its token (authorized) """
        token = str(uuid.uuid4())
        suggestion = SuggestionFactory.create(token=token, status='draft')

        response = self.client.put(
            reverse('suggestion_token_validate', kwargs={'token':token}),
            HTTP_AUTHORIZATION=self.user_1_token)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        suggestion = Suggestion.objects.get(pk=suggestion.pk)

        self.assertEquals(suggestion.status, 'draft')
示例#21
0
    def test_retrieve_only_suggestions_with_project_slug(self):
        """
        Test the project slug filter on the API endpoint. Should return one suggestion
        """
        project = ProjectFactory.create()
        suggestion_accepted_1 = SuggestionFactory.create(project=project)

        response = self.client.get(self.suggestion_list_url, {'project_slug': project.slug},
                                    HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 1)

        self.assertEqual(data[0]['project'].lower(), project.slug)
示例#22
0
    def test_token_validate_already_validated(self):
        """ validate a suggesting by its token (authorized) """
        token = str(uuid.uuid4())
        suggestion = SuggestionFactory.create(token=token, status='draft')

        response = self.client.put(reverse('suggestion_token_validate',
                                           kwargs={'token': token}),
                                   HTTP_AUTHORIZATION=self.user_1_token)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        suggestion = Suggestion.objects.get(pk=suggestion.pk)

        self.assertEquals(suggestion.status, 'draft')
示例#23
0
    def test_project_submitted_suggestion_submitted(self):
        """
        Test that suggestion has status submitted if a project status
        changes to submitted
        """
        project = ProjectFactory.create(status=self.new)
        suggestion = SuggestionFactory.create(project=project,
                                              token='xxx',
                                              status='in_progress')

        project.status = self.submitted
        project.save()

        suggestion = Suggestion.objects.get(project=project)

        self.assertEquals(suggestion.status, 'submitted')
示例#24
0
    def test_project_submitted_suggestion_submitted(self):
        """
        Test that suggestion has status submitted if a project status
        changes to submitted
        """
        project = ProjectFactory.create(status=self.new)
        suggestion = SuggestionFactory.create(project=project,
                                              token='xxx',
                                              status='in_progress')

        project.status = self.submitted
        project.save()

        suggestion = Suggestion.objects.get(project=project)

        self.assertEquals(suggestion.status, 'submitted')
示例#25
0
    def test_project_needs_work_suggestion_in_progress(self):
        """
        Test that suggestion has status in-progress if a project status
        changes to needs-work
        """
        project = ProjectFactory.create(status=self.submitted)
        suggestion = SuggestionFactory.create(project=project,
                                              token='xxx',
                                              status='submitted')

        project.status = self.needs_work
        project.save()

        suggestion = Suggestion.objects.get(project=project)

        self.assertEquals(suggestion.status, 'in_progress')
示例#26
0
    def test_project_needs_work_suggestion_in_progress(self):
        """
        Test that suggestion has status in-progress if a project status
        changes to needs-work
        """
        project = ProjectFactory.create(status=self.submitted)
        suggestion = SuggestionFactory.create(project=project,
                                              token='xxx',
                                              status='submitted')

        project.status = self.needs_work
        project.save()

        suggestion = Suggestion.objects.get(project=project)

        self.assertEquals(suggestion.status, 'in_progress')
示例#27
0
    def test_retrieve_only_suggestions_with_status(self):
        """
        Test the status filter on the API endpoint.
        """
        accepted = 'accepted'

        SuggestionFactory.create(status=accepted)
        SuggestionFactory.create(status=accepted)
        SuggestionFactory.create(status='other')

        response = self.client.get(self.suggestion_list_url,
                                   {'status': accepted},
                                   HTTP_AUTHORIZATION=self.user_1_token)

        data = json.loads(response.content)
        self.assertEqual(len(data), 2)

        self.assertEqual(data[0]['status'].lower(), accepted)
        self.assertEqual(data[1]['status'].lower(), accepted)