def test_does_not_count_duplicates(self):
        project = factories.ProjectFactory()
        factories.URLFactory.create_batch(
            5,
            url_project=project,
            url_nominator__nominator_institution='UNT'
        )
        results = views.get_look_ahead(project)

        assert len(json.loads(results)) == 1
    def test_returns_all_nominator_institutions(self):
        project = factories.ProjectFactory()
        expected = [
            url.url_nominator.nominator_institution
            for url in factories.URLFactory.create_batch(10, url_project=project)
        ]
        # Should not affect the institution list since these URLs are not
        # associated with the project.
        factories.URLFactory.create_batch(5)
        results = views.get_look_ahead(project)

        assert json.loads(results) == sorted(expected)
    def test_context_url_not_found(self, client):
        entity = "http://www.example.com"
        project = factories.ProjectFactory()
        response = client.get(reverse("url_listing", args=[project.project_slug, entity]))
        expected_context = {
            "project": project,
            "form": views.URLForm({"url_value": entity}),
            "url_not_found": True,
            "metadata_vals": views.get_metadata(project),
            "form_errors": None,
            "summary_list": None,
            "json_data": None,
            "form_types": None,
            "institutions": views.get_look_ahead(project),
            "url_entity": entity,
        }

        for key in expected_context:
            assert str(response.context[key]) == str(expected_context[key])
    def test_base_context_values(self, client):
        entity = u"http://www.example.com"
        entity_surt = u"http://(com,example,www,)"
        project = factories.ProjectFactory()
        project_metadata = factories.ProjectMetadataFactory(project=project)
        url = factories.URLFactory(url_project=project, entity=entity)
        factories.SURTFactory(url_project=project, entity=entity, value=entity_surt)
        related_urls = factories.SURTFactory.create_batch(
            1, url_project=project, entity=u"{0}/main/page".format(entity), value=u"{0}/main/page".format(entity_surt)
        )
        expected_context = {
            "project": project,
            "url_data": views.create_url_list(project, related_urls + [url]),
            "related_url_list": related_urls,
            "metadata_vals": views.get_metadata(project),
            "institutions": views.get_look_ahead(project),
            "form_types": json.dumps({project_metadata.metadata.name: project_metadata.form_type}),
        }
        response = client.get(reverse("url_listing", args=[project.project_slug, entity]))

        for key in expected_context:
            assert str(response.context[key]) == str(expected_context[key])