# Path: suma/core/models/link.py
# class Link(Base, TimestampColumns):
#     hashid = Column(String, index=True, unique=True, nullable=False)
#     _url = Column('url', Unicode, index=True, nullable=False)
#     user_id = Column(BigInteger)
#     _hash = Column('hash', String, index=True, nullable=False)
#     _hash_netloc = Column('hash_netloc', String, nullable=False)
#     _hash_path = Column('hash_path', String, nullable=False)
#     meta = Column(MutableDict.as_mutable(JSONB), default={})
#     __table_args__ = (
#         Index('unique_url_and_user_id', _url, user_id, unique=True,
#               postgresql_where=(user_id != None)),
#         Index('unique_url_and_user_id_is_null', 'url', unique=True,
#               postgresql_where=(user_id == None))
#     )
# 
#     is_banned = column_property(
#         exists().where(
#             or_(
#                 BlockedLink.hash.in_([_hash, _hash_netloc, _hash_path])
#             )
#         )
#     )
# 
#     @property
#     def clicks(self):
#         if self._clicks:
#             return self._clicks.counter
#         return 0
#     
#     @hybrid_property
#     def url(self):
#         return self._url
# 
#     @url.setter
#     def url(self, value):
#         self._url = value
#         self._hash, self._hash_netloc, self._hash_path = create_url_hashes(value)


from suma.core.models import Link


def test_create_link(db_session, link_svc):
    link_svc.create_link('http://google.com/test')
    assert db_session.query(Link).filter(Link.url == 'http://google.com/test').count() == 1


def test_create_link_with_user_id(db_session, link_svc):
    link_svc.create_link('http://google.com/test', 1)
    assert (
        db_session.query(Link).

# Path: suma/core/models/link.py
# class Link(Base, TimestampColumns):
#     hashid = Column(String, index=True, unique=True, nullable=False)
#     _url = Column('url', Unicode, index=True, nullable=False)
#     user_id = Column(BigInteger)
#     _hash = Column('hash', String, index=True, nullable=False)
#     _hash_netloc = Column('hash_netloc', String, nullable=False)
#     _hash_path = Column('hash_path', String, nullable=False)
#     meta = Column(MutableDict.as_mutable(JSONB), default={})
#     __table_args__ = (
#         Index('unique_url_and_user_id', _url, user_id, unique=True,
#               postgresql_where=(user_id != None)),
#         Index('unique_url_and_user_id_is_null', 'url', unique=True,
#               postgresql_where=(user_id == None))
#     )
# 
#     is_banned = column_property(
#         exists().where(
#             or_(
#                 BlockedLink.hash.in_([_hash, _hash_netloc, _hash_path])
#             )
#         )
#     )
# 
#     @property
#     def clicks(self):
#         if self._clicks:
#             return self._clicks.counter
#         return 0
#     
#     @hybrid_property
#     def url(self):
#         return self._url
# 
#     @url.setter
#     def url(self, value):
#         self._url = value
#         self._hash, self._hash_netloc, self._hash_path = create_url_hashes(value)


# Path: tests/core/services/test_link_service.py
from suma.core.models import Link



def test_create_link(db_session, link_svc):
    link_svc.create_link('http://google.com/test')
    assert db_session.query(Link).filter(Link.url == 'http://google.com/test').count() == 1


def test_create_link_with_user_id(db_session, link_svc):
    link_svc.create_link('http://google.com/test', 1)
    assert (
        db_session.query(Link).

        filter(Link.url == 'http://google.com/test', Link.user_id == 1).count() == 1