Пример #1
0
    def test_annotated_company_bug(self):
        """ sometimes annotate causes query to return duplicates """
        profile = ProfileFactory()
        profile_2 = ProfileFactory()
        company = factories.CompanyFactory()
        _ = factories.CompanyFactory()

        services.company_clap(company=company, profile=profile)
        services.company_clap(company=company, profile=profile_2)

        n_annotated = annotations.annotate_comment_claps(
            selectors.get_companies(), profile_id=profile.id).count()
        n_companies = selectors.get_companies().count()
        assert n_annotated == n_companies
Пример #2
0
    def test_annotated_comments_annotated(self):
        """ sometimes annotate causes query to return duplicates """
        profile = ProfileFactory()
        profile_2 = ProfileFactory()
        thread = factories.ThreadFactory(comments=None)
        comment = factories.CommentFactory(thread=thread)
        comment_2 = factories.CommentFactory(thread=thread)

        services.comment_clap(comment=comment, profile=profile)
        services.comment_clap(comment=comment_2, profile=profile_2)

        n_annotated = annotations.annotate_comment_claps(
            selectors.get_thread_comments(thread_id=thread.id),
            profile_id=profile.id).count()
        n_comments = selectors.get_thread_comments(thread_id=thread.id).count()
        assert n_annotated == n_comments
Пример #3
0
    def test_can_create_company(self):
        user = UserFactory(groups=["editors"])
        profile = ProfileFactory(user=user)

        assert services.can_create_company(profile)

        user2 = UserFactory(groups=[])
        profile2 = ProfileFactory(user=user2)

        assert services.can_create_company(profile2)

        for _ in range(services.MAX_UNMODERATED_CHANGES):
            factories.CompanyFactory(
                created_by=profile2, status=choices.ModerationStatus.UNMODERATED.name
            )
        assert not services.can_create_company(profile2)
Пример #4
0
    def test_oauth_login(
        self,
        m_get_user_data_from_code,
        m_create_or_update_user,
        m_update_profile,
        client,
    ):
        """ Test github/login/view """
        user = ProfileFactory().user
        user_data = UserData(name="Fake Name",
                             provider=UserProviderChoices.GITHUB.name)
        profile_data = ProfileData()
        m_get_user_data_from_code.return_value = (user.email, user_data,
                                                  profile_data)
        m_create_or_update_user.return_value = user

        resp = client.post(
            "/users/login/github/?code=fakecode&redirect_uri=fakeuri")

        assert resp.status_code == 200

        m_get_user_data_from_code.assert_called_once_with(
            "fakecode", "fakeuri")
        m_create_or_update_user.assert_called_once_with(email=user.email,
                                                        user_data=user_data)
        m_update_profile.assert_called_once_with(user=user,
                                                 profile_data=profile_data)
Пример #5
0
 def test_create_revision(self):
     profile = ProfileFactory()
     company = factories.CompanyFactory()
     revision = services.create_revision(
         company=company, created_by=profile, name="X"
     )
     assert revision.company == company
     assert revision.name == "X"
Пример #6
0
def test_create_image_asset():
    data_uri = """data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAYAAAD37n+BAAAMZGlDQ1BJQ0MgUHJvZmlsZQAASImVVwdck0cbv3dkkrACEZAR9hJFZgAZIawIAjIFUQlJIGHEmBBUXIiWKli3iOKoaFVAwToAqQMR6yyK2zqKA5VKLVZxofJdSEBrv/H7nt/v3vu/zz33f0bu8t4BoNPJl8lyUV0A8qT58rjwYNaklFQW6REgAhRogzHAmC9QyDixsVEAylD/d3l9HSCq/oqLiuuf4/9V9IUihQAAJA3iDKFCkAdxCwB4sUAmzweAGAL11jPzZSoshthADgOEeK4KZ6nxShXOUOMdgzYJcVyImwAg0/h8eRYA2m1QzyoQZEEe7UcQu0qFEikAOgYQBwjEfCHECRCPysubrsJFEDtAexnEuyFmZ3zBmfU3/oxhfj4/axir8xoUcohEIcvlz/4/S/O/JS9XOeTDDjaaWB4Rp8of1vBmzvRIFaZB3CPNiI5R1RritxKhuu4AoFSxMiJRbY+aChRcWD/AhNhVyA+JhNgU4jBpbnSURp+RKQnjQQxXCzpLks9L0MxdIlKExms4N8mnx8UM4Uw5l6OZW8eXD/pV2bcpcxI5Gv6bYhFviP9VoTghGWIqABi1QJIUDbE2xAaKnPhItQ1mVSjmRg/ZyJVxqvhtIGaLpOHBan4sLVMeFqexl+UphvLFSsQSXrQGV+SLEyLU9cFqBPzB+I0gbhBJOYlDPCLFpKihXISikFB17li7SJqoyRe7J8sPjtPM7ZXlxmrscbIoN1ylt4LYRFEQr5mLj8uHi1PNj0fJ8mMT1HHi6dn88bHqePACEAW4IASwgBK2DDAdZANJe09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AwAAAAMAAABf7W7m4QAAACtJREFUKBVivJ+W/5+BBMBIrAZGBkaG/wz/GAhr+A9UBIQM/1kY/jH/YAAAAAD//8+H4R0AAAA9SURBVH2NwRGAMBACl0yMVurXki3EM0gDBp4soPu8zK+EmEmDeOPtD1oVTIsndmF1vI91geDKuqm8NGocfCg6J0aY6R75AAAAAElFTkSuQmCC"""
    img_file = create_image_file_from_data_uri(data_uri)
    profile = ProfileFactory()
    img = create_image_asset(img_file=img_file, width=1, height=1, profile=profile)

    assert img.created_by == profile
    assert img.width == img.height == 1
Пример #7
0
 def test_company_clap(self):
     profile = ProfileFactory()
     company = factories.CompanyFactory()
     assert company.clappers.count() == 0
     rv = services.company_clap(company=company, profile=profile)
     assert rv == 1
     rv2 = services.company_clap(company=company, profile=profile)
     assert rv2 == 1
     assert company.clappers.count() == 1
Пример #8
0
    def test_annotated_company(self):
        profile_1 = ProfileFactory()
        profile_2 = ProfileFactory()
        company_1 = factories.CompanyFactory()
        company_2 = factories.CompanyFactory()
        assert company_1.clappers.count() == company_2.clappers.count() == 0
        assert services.company_clap(company=company_1, profile=profile_1) == 1
        assert services.company_clap(company=company_2, profile=profile_2) == 1

        qs_anno_1 = annotations.annotate_company_claps(
            selectors.get_companies(), profile_id=profile_1.id)

        assert qs_anno_1.get(id=company_1.id).user_did_clap is True
        assert qs_anno_1.get(id=company_2.id).user_did_clap is False

        qs_anno_2 = annotations.annotate_company_claps(
            selectors.get_companies(), profile_id=profile_2.id)
        assert qs_anno_2.get(id=company_1.id).user_did_clap is False
        assert qs_anno_2.get(id=company_2.id).user_did_clap is True
Пример #9
0
 def test_comment_clap(self):
     thread = factories.ThreadFactory(comments=None)
     comment = factories.CommentFactory(thread=thread)
     profile = ProfileFactory()
     assert comment.clappers.count() == 0
     rv = services.comment_clap(comment=comment, profile=profile)
     assert rv == 1
     rv2 = services.comment_clap(comment=comment, profile=profile)
     assert rv2 == 1
     assert comment.clappers.count() == 1
Пример #10
0
    def test_create_comment(self):
        profile = ProfileFactory()
        text = "xxx"
        thread = factories.ThreadFactory(comments=None)
        assert thread.comments.count() == 0

        comment = services.create_comment(profile=profile, text=text, thread=thread)
        assert thread.comments.count() == 1
        assert comment.text == text
        assert comment.profile == profile

        services.create_comment(profile=profile, text=text, thread=thread)
        assert thread.comments.count() == 2
Пример #11
0
    def test_annotated_comments(self):
        thread = factories.ThreadFactory(comments=None)

        profile_1 = ProfileFactory()
        profile_2 = ProfileFactory()
        comment_1 = factories.CommentFactory(thread=thread)
        comment_2 = factories.CommentFactory(thread=thread)
        assert comment_1.clappers.count() == comment_2.clappers.count() == 0
        assert services.comment_clap(comment=comment_1, profile=profile_1) == 1
        assert services.comment_clap(comment=comment_2, profile=profile_2) == 1

        comments_1 = annotations.annotate_comment_claps(
            selectors.get_thread_comments(thread_id=thread.id),
            profile_id=profile_1.id,
        )
        assert comments_1.all()[0].user_did_clap is True
        assert comments_1.all()[1].user_did_clap is False

        comments_2 = annotations.annotate_comment_claps(
            selectors.get_thread_comments(thread_id=thread.id),
            profile_id=profile_2.id)
        assert comments_2.all()[0].user_did_clap is False
        assert comments_2.all()[1].user_did_clap is True
Пример #12
0
    def handle(self, *args, **options):
        profile = ProfileFactory()
        profile_2 = ProfileFactory()
        file = create_image_file_from_url(
            "https://upload.wikimedia.org/wikipedia/commons/4/49/Mosuo_Woman_-_42723465920.jpg"
        )
        profile.avatar = create_image_asset(img_file=file)
        profile.save()

        for (
            name,
            description,
            website,
            location,
            logo_url,
            cover_url,
            hashtag_names,
        ) in seed_data:

            slug = slugify(name)
            company = models.Company.objects.filter(slug=slug).first()
            if company:
                print(f"> Already exists: {slug} - flush or delete to recreate")
                continue
            else:
                print(f"> Created: {slug}")
                revision_kwargs = dict(
                    name=name,
                    description=description,
                    website=website,
                    location=location,
                    twitter="aec_works",
                    crunchbase_id="apple",
                    logo=None,
                    cover=None,
                    hashtags=hashtag_names,
                )
                company = services.create_company(created_by=profile, **revision_kwargs)

            # Logo
            logo_file = create_image_file_from_url(logo_url)
            logo_img = create_image_asset(img_file=logo_file)
            company.current_revision.logo = logo_img

            # Cover
            cover_file = create_image_file_from_url(cover_url)
            cover_img = create_image_asset(img_file=cover_file)
            company.current_revision.cover = cover_img

            company.current_revision.save()
            print(f"    logo: {logo_url}")
            print(f"    cover: {cover_url}")

            comments = [
                f.CommentFactory(profile=profile, thread=company.thread)
                for _ in range(3)
            ]

            services.comment_clap(comment=comments[0], profile=profile)
            services.comment_clap(comment=comments[2], profile=profile_2)

            if name[0] > "g":
                services.company_clap(company=company, profile=profile)

            print("    comments")

            if name == "1Build" and company.articles.count() == 0:
                company.banner = "Hiring"
                company.save()
                services.create_company_article(
                    company=company,
                    url="https://www.archdaily.com/793082/la-serena-house-sebastian-gaviria-gomez?ad_medium=widget&ad_name=selected-buildings-stream",
                    profile=profile,
                )
                services.create_company_article(
                    company=company,
                    url="https://www.archdaily.com/788489/nilo-houses-alberto-burckhard-plus-carolina-echeverri?ad_medium=widget&ad_name=recommendation",
                    profile=profile,
                )
Пример #13
0
 def test_profile_company_claps(self, auth_client):
     profile = ProfileFactory()
     co = f.CompanyFactory(current_revision__name="X")
     services.company_clap(company=co, profile=profile)
     resp = auth_client.get(f"/community/companies/claps/{profile.slug}/")
     assert resp.status_code == 200
Пример #14
0
class TestUserViews:
    @pytest.mark.parametrize(
        "path,param_factory",
        [["profiles/", None], ["profiles/{0}/", lambda: ProfileFactory().slug]
         ],
    )
    def test_get_views_annonymous(self, client, path, param_factory):
        if param_factory:
            path = path.format(param_factory())
        url = f"/users/{path}"
        resp = client.get(url)
        assert resp.status_code == 200

    @mock.patch("api.users.views.services.update_profile")
    @mock.patch("api.users.views.services.create_or_update_user")
    @mock.patch("api.users.views.GithubProvider.get_user_data_from_code")
    def test_oauth_login(
        self,
        m_get_user_data_from_code,
        m_create_or_update_user,
        m_update_profile,
        client,
    ):
        """ Test github/login/view """
        user = ProfileFactory().user
        user_data = UserData(name="Fake Name",
                             provider=UserProviderChoices.GITHUB.name)
        profile_data = ProfileData()
        m_get_user_data_from_code.return_value = (user.email, user_data,
                                                  profile_data)
        m_create_or_update_user.return_value = user

        resp = client.post(
            "/users/login/github/?code=fakecode&redirect_uri=fakeuri")

        assert resp.status_code == 200

        m_get_user_data_from_code.assert_called_once_with(
            "fakecode", "fakeuri")
        m_create_or_update_user.assert_called_once_with(email=user.email,
                                                        user_data=user_data)
        m_update_profile.assert_called_once_with(user=user,
                                                 profile_data=profile_data)

    def test_oauth_missing_code(selfixi, client):
        resp = client.post("/users/login/github/")
        assert resp.status_code == 400

    def test_oauth_bad_provider(self, client):
        resp = client.post("/users/login/facebook/")
        assert resp.status_code == 400

    def test_profile_annon(self, client):
        resp = client.get("/users/profiles/me/")
        assert resp.status_code == 403

    def test_profile(self, django_user_model):
        user = django_user_model.objects.create(email="*****@*****.**", password="******")
        client = APIClient()
        client.force_authenticate(user=user)
        resp = client.get("/users/profiles/me/")
        assert resp.status_code == 200

    def test_login(self, django_user_model):
        name = "x"
        email = "*****@*****.**"
        password = "******"
        user = django_user_model(name=name, email=email)
        user.set_password(password)
        user.save()

        client = APIClient()
        resp = client.post("/users/login/", {
            "email": email,
            "password": password
        })
        assert resp.status_code == 200
        assert resp.json()["name"] == name