Пример #1
0
 def test_get_base_attributes_returns_only_intended_attributes(self):
     entity = Post()
     attrs = get_base_attributes(entity).keys()
     assert set(attrs) == {
         "created_at",
         "guid",
         "handle",
         "location",
         "provider_display_name",
         "public",
         "raw_content",
         "signature",
     }
     entity = Profile()
     attrs = get_base_attributes(entity).keys()
     assert set(attrs) == {
         "created_at",
         "guid",
         "handle",
         "name",
         "email",
         "gender",
         "raw_content",
         "location",
         "public",
         "nsfw",
         "public_key",
         "image_urls",
         "tag_list",
         "signature",
     }
Пример #2
0
def parse_profile_from_hcard(hcard, handle):
    """
    Parse all the fields we can from a hCard document to get a Profile.

    :arg hcard: HTML hcard document (str)
    :arg handle: User handle in [email protected] format
    :returns: ``federation.entities.Profile`` instance
    """
    doc = html.fromstring(hcard)
    profile = Profile(
        name=_get_element_text_or_none(doc, ".fn"),
        image_urls={
            "small":
            _get_element_attr_or_none(doc, ".entity_photo_small .photo",
                                      "src"),
            "medium":
            _get_element_attr_or_none(doc, ".entity_photo_medium .photo",
                                      "src"),
            "large":
            _get_element_attr_or_none(doc, ".entity_photo .photo", "src"),
        },
        public=True
        if _get_element_text_or_none(doc, ".searchable") == "true" else False,
        handle=handle,
        guid=_get_element_text_or_none(doc, ".uid"),
        public_key=_get_element_text_or_none(doc, ".key"),
    )
    return profile
Пример #3
0
def dummy_profile():
    return Profile(
        url=f"https://example.com/profile/1234/",
        atom_url=f"https://example.com/profile/1234/atom.xml",
        id=f"https://example.com/p/1234/",
        handle="*****@*****.**",
        guid="1234",
        name="Bob Bobértson",
    )
Пример #4
0
 def test_validate_children(self):
     post = PostFactory()
     image = Image()
     profile = Profile()
     post._children = [image]
     post._validate_children()
     post._children = [profile]
     with pytest.raises(ValueError):
         post._validate_children()
Пример #5
0
 def test_profile_that_doesnt_validate_returns_none(self, mock_retrieve, mock_parse):
     hcard = generate_hcard(
         "diaspora",
         hostname="https://hostname",
         fullname="fullname",
         firstname="firstname",
         lastname="lastname",
         photo300="photo300",
         photo100="photo100",
         photo50="photo50",
         searchable="true",
         guid="guid",
         public_key="public_key",
         username="******",
     )
     mock_retrieve.return_value = hcard
     mock_parse.return_value = Profile(guid="123")
     profile = retrieve_and_parse_profile("foo@bar")
     assert profile == None
Пример #6
0
def profile():
    return Profile(
        raw_content="foobar",
        name="Bob Bobertson",
        public=True,
        tag_list=["socialfederation", "federation"],
        image_urls={
            "large": "urllarge",
            "medium": "urlmedium",
            "small": "urlsmall"
        },
        id="https://example.com/alice",
        handle="*****@*****.**",
        guid="guid",
        inboxes={
            "private": "https://example.com/bob/private",
            "public": "https://example.com/public",
        },
        public_key=PUBKEY,
    )
Пример #7
0
 def test_calls_retrieve_and_parse_profile(self, mock_retrieve):
     mock_retrieve.return_value = Profile(guid="guidguidguidguid")
     attrs = {"handle": "foo"}
     attrs = DiasporaProfile.fill_extra_attributes(attrs)
     assert attrs == {"handle": "foo", "guid": "guidguidguidguid"}
Пример #8
0
 def test_profile_is_converted_to_diasporaprofile(self, private_key):
     entity = Profile()
     assert isinstance(get_outbound_entity(entity, private_key),
                       DiasporaProfile)
Пример #9
0
 def test_profile_is_converted_to_diasporaprofile(self, private_key):
     entity = Profile(handle="*****@*****.**", guid="1234")
     assert isinstance(get_outbound_entity(entity, private_key),
                       DiasporaProfile)
Пример #10
0
 def test_instance_creation_validates_email_value(self):
     with pytest.raises(ValueError):
         entity = Profile(handle="*****@*****.**",
                          raw_content="foobar",
                          email="foobar")
         entity.validate()
Пример #11
0
 def test_instance_creation(self):
     entity = Profile(handle="*****@*****.**", raw_content="foobar")
     assert entity
Пример #12
0
 def test_guid_is_mandatory(self):
     entity = Profile(handle="*****@*****.**", raw_content="foobar")
     with pytest.raises(ValueError):
         entity.validate()
Пример #13
0
 def test_guid_is_mandatory(self):
     entity = Profile(handle="*****@*****.**", raw_content="foobar")
     with pytest.raises(ValueError):
         entity.validate()
Пример #14
0
 def test_instance_creation_validates_email_value(self):
     with pytest.raises(ValueError):
         entity = Profile(handle="*****@*****.**", raw_content="foobar", email="foobar")
         entity.validate()
Пример #15
0
 def test_profile_is_converted_to_activitypubprofile(self, private_key):
     entity = Profile()
     assert isinstance(get_outbound_entity(entity, private_key), ActivitypubProfile)
Пример #16
0
 def test_guid_is_not_mandatory(self):
     entity = Profile(handle="*****@*****.**", raw_content="foobar")
     entity.validate()