Beispiel #1
0
def test_bulk_create_and_read(user_fixture, token_fixture):
    CREATE_URL = ActivityApiUrl.ACTIVITIES
    READ_URL = ActivityApiUrl.ACTIVITIES_PAGE % '1?aggregate=1'
    HEADERS = {
        'Authorization': 'Bearer {}'.format(token_fixture.access_token),
        'content-type': 'application/json'
    }

    # Test `bulk` async write
    for i in xrange(200):
        payload = json.dumps(
            dict(user_id=user_fixture.id,
                 type=Activity.MessageIds.CANDIDATE_CREATE_WEB,
                 source_table='test',
                 source_id='1337',
                 params={
                     'lastName': random_word(6),
                     'firstName': random_word(8)
                 }))
        response = requests.post(CREATE_URL, headers=HEADERS, data=payload)
        assert response.status_code == requests.codes.created

    # Test `bulk` async read
    for _ in xrange(5):
        response = requests.get(READ_URL,
                                headers={
                                    'Authorization':
                                    'Bearer {}'.format(
                                        token_fixture.access_token)
                                })
        assert response.status_code == requests.codes.ok
Beispiel #2
0
def candidate_fixture(user_fixture, culture_fixture, candidate_source_fixture,
                      request):
    candidate_attrs = dict(first_name=random_word(4),
                           last_name=random_word(6),
                           formatted_name=random_word(10),
                           is_archived=0,
                           is_mobile_hidden=0,
                           added_time=datetime.today(),
                           user_id=user_fixture.id,
                           domain_can_read=1,
                           domain_can_write=1,
                           source_id=candidate_source_fixture.id,
                           source_product_id=2,
                           objective=random_word(6),
                           culture_id=culture_fixture.id,
                           is_dirty=0)
    candidate, created = get_or_create(db.session,
                                       Candidate,
                                       defaults=None,
                                       **candidate_attrs)
    if created:
        db.session.add(candidate)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(candidate)
        db.session.commit()

    request.addfinalizer(fin)
    return candidate
Beispiel #3
0
def candidate_source_fixture(domain_fixture, request):
    source = CandidateSource(description=random_word(40),
                             notes=random_word(40),
                             domain_id=domain_fixture.id)
    db.session.add(source)
    db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(source)
        db.session.commit()

    request.addfinalizer(fin)
    return source
Beispiel #4
0
def culture_fixture(request):
    culture_attrs = dict(description=random_word(12), code=random_word(5))
    culture, created = get_or_create(db.session,
                                     Culture,
                                     defaults=None,
                                     **culture_attrs)
    if created:
        db.session.add(culture)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(culture)
        db.session.commit()

    request.addfinalizer(fin)
    return culture
Beispiel #5
0
def test_basic_post(user_fixture, token_fixture):
    test_url = ActivityApiUrl.ACTIVITIES
    response = requests.post(
        test_url,
        headers={
            'Authorization': 'Bearer {}'.format(token_fixture.access_token),
            'content-type': 'application/json'
        },
        data=json.dumps(
            dict(user_id=user_fixture.id,
                 type=Activity.MessageIds.CANDIDATE_CREATE_WEB,
                 source_table='test',
                 source_id='1337',
                 params={
                     'lastName': random_word(6),
                     'firstName': random_word(8)
                 })))
    assert response.status_code == requests.codes.created
Beispiel #6
0
def client_fixture(request):
    client_attrs = dict(client_id=random_word(30),
                        client_secret=random_word(12))
    client, created = get_or_create(db.session,
                                    Client,
                                    defaults=None,
                                    **client_attrs)
    if created:
        db.session.add(client)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(client)
        db.session.commit()

    request.addfinalizer(fin)
    return client
Beispiel #7
0
def user_fixture(domain_fixture, request):
    user_attrs = dict(domain_id=domain_fixture.id,
                      first_name='Jamtry',
                      last_name='Jonas',
                      password=random_word(12),
                      email=random_word(7),
                      added_time=datetime(2050, 4, 26))
    user, created = get_or_create(db.session,
                                  User,
                                  defaults=None,
                                  **user_attrs)
    if created:
        db.session.add(user)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(user)
        db.session.commit()

    request.addfinalizer(fin)
    return user
Beispiel #8
0
def token_fixture(client_fixture, user_fixture, request):
    token_attrs = dict(client_id=client_fixture.client_id,
                       user_id=user_fixture.id,
                       token_type='bearer',
                       access_token=random_word(26),
                       refresh_token=random_word(26),
                       expires=datetime(2050, 4, 26))
    token, created = get_or_create(db.session,
                                   Token,
                                   defaults=None,
                                   **token_attrs)
    if created:
        db.session.add(token)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(token)
        db.session.commit()

    request.addfinalizer(fin)
    return token
Beispiel #9
0
def org_fixture(request):
    org_attrs = dict(
        name='Rocket League All Stars - {}'.format(random_word(8)))
    org, created = get_or_create(db.session,
                                 Organization,
                                 defaults=None,
                                 **org_attrs)
    if created:
        db.session.add(org)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(org)
        db.session.commit()

    request.addfinalizer(fin)
    return org
Beispiel #10
0
def test_custom_pagination(access_token_first, user_first):
    CREATE_URL = ActivityApiUrl.ACTIVITIES
    HEADERS = {'Authorization': 'Bearer {}'.format(access_token_first), 'content-type': 'application/json'}

    for i in xrange(25):
        payload = json.dumps(
            dict(
                user_id=user_first.id,
                type=Activity.MessageIds.CANDIDATE_CREATE_WEB,
                source_table='test',
                source_id='1337',
                params={'formatted_name': random_word(6)}))
        requests.post(CREATE_URL, headers=HEADERS, data=payload)

    read_url = 'http://127.0.0.1:8002/v2/activities/{}/user/{}?qty=25'.format(1, user_first.id)
    response = requests.get(read_url, headers={'Authorization': 'Bearer {}'.format(access_token_first)})
    print response.content
    assert len(json.loads(response.content)['items']) == 25
    assert response.status_code == requests.codes.ok
Beispiel #11
0
def domain_fixture(org_fixture, culture_fixture, request):
    domain_attrs = dict(name=random_word(10).format(),
                        usage_limitation=-1,
                        added_time=datetime.today(),
                        organization_id=org_fixture.id,
                        is_fair_check_on=0,
                        is_active=1,
                        default_culture_id=culture_fixture.id,
                        expiration=datetime.utcnow().replace(year=2015))
    domain, created = get_or_create(db.session,
                                    Domain,
                                    defaults=None,
                                    **domain_attrs)
    if created:
        db.session.add(domain)
        db.session.commit()

    @require_integrity(database_object=db)
    def fin():
        db.session.delete(domain)
        db.session.commit()

    request.addfinalizer(fin)
    return domain