def test_get_by_url_explicit_re(db_connection):
    logo1 = create_logo('1', link='https://abc.example.com', link_re=r'abc\.example\.com|moo\.example\.com')
    logo2 = create_logo('2', link='https://xyz.example.com', link_re=r'xyz\.example\.com|utm_medium')

    assert Logo.get_by_url('https://abc.example.com/something/') == logo1
    assert Logo.get_by_url('https://moo.example.com/everything/?v=123') == logo1
    assert Logo.get_by_url('https://xyz.example.com/moo/') == logo2
    assert Logo.get_by_url('https://example.com/moo/?utm_medium=foo') == logo2
def test_listing_sort_by_starts_at(db_connection):
    t = date.today()
    logo1 = create_logo('1', months=12, starts_at=t - timedelta(days=6))
    logo2 = create_logo('2', months=12, starts_at=t - timedelta(days=1))
    logo3 = create_logo('3', months=12, starts_at=t - timedelta(days=3))

    assert Logo.listing() == [logo1, logo3, logo2]
Exemple #3
0
def generate_messages(today):
    logos = Logo.messages_listing()

    template_path = Path(__file__).parent / 'templates' / 'logo_metrics.html'
    template = Template(template_path.read_text())

    return (create_message(logo, template, today) for logo in logos)
def test_listing_only_active(db_connection):
    t = date.today()
    logo1 = create_logo('1', starts_at=t, expires_at=t + timedelta(days=30))
    logo2 = create_logo('2', starts_at=t - timedelta(days=30), expires_at=t)
    create_logo('3', starts_at=t - timedelta(days=30), expires_at=t - timedelta(days=1))
    create_logo('4', starts_at=t + timedelta(days=1), expires_at=t + timedelta(days=30))
    logo5 = create_logo('5', starts_at=t - timedelta(days=30), expires_at=t + timedelta(days=30))

    assert set(Logo.listing(today=t)) == {logo1, logo2, logo5}
Exemple #5
0
def club():
    with db:
        members = Member.avatars_listing()
        members_total_count = Member.count()
        logos = Logo.listing()
    return render_template(
        'club.html',
        nav_active='club',
        logos=logos,
        members=members,
        members_total_count=members_total_count,
        thumbnail=thumbnail(title='Klub, který tě nastartuje'))
Exemple #6
0
def club():
    with db:
        members = ClubUser.avatars_listing()
        members_total_count = ClubUser.members_count()
        logos = Logo.listing()
    return render_template(
        'club.html',
        nav_active='club',
        subnav_tabs=CLUB_SUBNAV_TABS,
        subnav_active='club',
        logos=logos,
        members=members,
        members_total_count=members_total_count,
        thumbnail=thumbnail(title='Klub, který tě nastartuje'))
def test_from_values_per_date():
    logo = Logo(**prepare_logo_data('1',
                                    starts_at=date(2020, 9, 1),
                                    expires_at=date(2020, 10, 1)))
    metric = LogoMetric.from_values_per_date(logo, 'users', {
        date(2020, 8, 15): 1000,
        date(2020, 9, 1): 10,
        date(2020, 9, 15): 20,
        date(2020, 10, 1): 30,
        date(2020, 10, 15): 1000,
    })

    assert metric.logo == logo
    assert metric.name == 'users'
    assert metric.value == 10 + 20 + 30
Exemple #8
0
def main():
    doc_key = '1TO5Yzk0-4V_RzRK5Jr9I_pF5knZsEZrNn2HKTXrHgls'
    records = google_sheets.download(google_sheets.get(doc_key, 'logos'))

    with db:
        Logo.drop_table()
        Logo.create_table()

        for record in records:
            Logo.create(**coerce_record(record))
Exemple #9
0
def candidate_handbook():
    with db:
        jobs = Job.listing()
        jobs_remote = Job.remote_listing()
        jobs_internship = Job.internship_listing()
        jobs_volunteering = Job.volunteering_listing()
        supporters_count = Supporter.count()
        last_modified = LastModified.get_value_by_path('candidate_handbook.html')
        logos = Logo.listing()
    return render_template('candidate_handbook.html',
                           nav_active='motivation',
                           subnav_tabs=HANDBOOK_SUBNAV_TABS,
                           subnav_active='candidate_handbook',
                           jobs=jobs,
                           jobs_remote=jobs_remote,
                           jobs_internship=jobs_internship,
                           jobs_volunteering=jobs_volunteering,
                           supporters_count=supporters_count,
                           last_modified=last_modified,
                           logos=logos,
                           thumbnail=thumbnail(title='Příručka o\u00a0hledání první práce v\u00a0IT'))
def test_days_since_started():
    logo = Logo(**prepare_logo_data('1', starts_at=date(1987, 8, 30)))

    assert logo.days_since_started(today=date(1987, 9, 8)) == 9
Exemple #11
0
def main():
    google_analytics_metrics = fetch_from_google_analytics()
    mailchimp_metrics = fetch_from_mailchimp()

    with db:
        Metric.drop_table()
        Metric.create_table()

        google_analytics_metric_names = [
            'avg_monthly_users',
            'avg_monthly_pageviews',
            'avg_monthly_handbook_users',
            'avg_monthly_handbook_pageviews',
            'avg_monthly_handbook_logo_clicks',
            'avg_monthly_jobs_users',
        ]
        for name in google_analytics_metric_names:
            Metric.create(name=name, value=google_analytics_metrics[name])
        Metric.create(name='subscribers',
                      value=mailchimp_metrics['subscribers'])

        JobMetric.drop_table()
        JobMetric.create_table()

        for url, value in google_analytics_metrics['users_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='users', value=value)
            except Job.DoesNotExist:
                pass

        for url, value in google_analytics_metrics['pageviews_per_job'].items(
        ):
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='pageviews', value=value)
            except Job.DoesNotExist:
                pass

        for url, value in google_analytics_metrics[
                'applications_per_job'].items():
            try:
                job = Job.get_by_url(url)
                JobMetric.create(job=job, name='applications', value=value)
            except Job.DoesNotExist:
                pass

        users_per_external_url = merge_metric_dicts(
            google_analytics_metrics['users_per_external_job'],
            mailchimp_metrics['users_per_external_url'])
        for url, value in users_per_external_url.items():
            try:
                job = Job.get_by_link(url)
                JobMetric.create(job=job, name='users', value=value)
            except Job.DoesNotExist:
                pass

        pageviews_per_external_url = merge_metric_dicts(
            google_analytics_metrics['pageviews_per_external_job'],
            mailchimp_metrics['pageviews_per_external_url'])
        for url, value in pageviews_per_external_url.items():
            try:
                job = Job.get_by_link(url)
                JobMetric.create(job=job, name='pageviews', value=value)
            except Job.DoesNotExist:
                pass

        LogoMetric.drop_table()
        LogoMetric.create_table()

        for url, value in google_analytics_metrics['clicks_per_logo'].items():
            try:
                logo = Logo.get_by_url(url)
                LogoMetric.create(logo=logo, name='clicks', value=value)
            except Logo.DoesNotExist:
                pass

        for logo in Logo.listing():
            values = google_analytics_metrics['handbook_users_per_date']
            metric = LogoMetric.from_values_per_date(logo, 'users', values)
            metric.save()
            values = google_analytics_metrics['handbook_pageviews_per_date']
            metric = LogoMetric.from_values_per_date(logo, 'pageviews', values)
            metric.save()
def test_expires_soon(today, expected):
    logo = Logo(**prepare_logo_data('1',
                                    starts_at=date(2020, 1, 1),
                                    expires_at=date(2020, 7, 1)))

    assert logo.expires_soon(today=today) is expected
def test_messages_listing(db_connection):
    logo1 = create_logo('1', email_reports=True)
    logo2 = create_logo('2', email_reports=False)  # noqa
    logo3 = create_logo('3', email_reports=True)

    assert set(Logo.messages_listing()) == {logo1, logo3}
def test_listing_sort_by_months(db_connection):
    logo1 = create_logo('1', months=12)
    logo2 = create_logo('2', months=3)
    logo3 = create_logo('3', months=6)

    assert Logo.listing() == [logo1, logo3, logo2]
def test_get_by_url(db_connection):
    logo1 = create_logo('1', link='https://abc.example.com')
    logo2 = create_logo('2', link='https://xyz.example.com')

    assert Logo.get_by_url('https://abc.example.com/something/') == logo1
    assert Logo.get_by_url('https://xyz.example.com/moo/?utm_medium=foo') == logo2
def create_logo(id, **kwargs):
    return Logo.create(**prepare_logo_data(id, **kwargs))
def test_get_by_url_multiple_match(db_connection):
    create_logo('1', link='https://example.com', link_re=r'example\.com')
    create_logo('2', link='https://example.com/something/', link_re=r'example\.com')

    with pytest.raises(Logo.AmbiguousMatch):
        Logo.get_by_url('https://example.com/moo/')
def test_get_by_url_no_match(db_connection):
    create_logo('1', link='https://abc.example.com')
    create_logo('2', link='https://xyz.example.com')

    with pytest.raises(Logo.DoesNotExist):
        Logo.get_by_url('https://example.com/moo/?utm_medium=foo')
def test_days_until_expires():
    logo = Logo(**prepare_logo_data('1', expires_at=date(1987, 9, 8)))

    assert logo.days_until_expires(today=date(1987, 8, 30)) == 9