예제 #1
0
def test_invoice_get_rates_inconsistent_scorelog_rates(member, store0):
    USER_RATE_ONE = 0.5
    USER_RATE_TWO = 0.2

    # Set some rate
    member.rate = USER_RATE_ONE
    member.review_rate = USER_RATE_ONE
    member.save()

    month = timezone.datetime(2014, 04, 01)

    submission_kwargs = {
        'store': store0,
        'unit': store0.units[0],
        'field': SubmissionFields.TARGET,
        'type': SubmissionTypes.NORMAL,
        'old_value': 'foo',
        'new_value': 'bar',
        'submitter': member,
        'translation_project': store0.translation_project,
        'creation_time': month,
    }
    scorelog_kwargs = {
        'wordcount': 1,
        'similarity': 0,
        'action_code': TranslationActionCodes.NEW,
        'creation_time': month,
        'user': member,
        'submission': SubmissionFactory(**submission_kwargs),
    }

    ScoreLogFactory(**scorelog_kwargs)

    # Alter rates, producing an inconsistent state when recording the ScoreLog
    member.rate = USER_RATE_TWO
    member.review_rate = USER_RATE_TWO
    member.save()

    submission_kwargs['unit'] = store0.units[1]
    scorelog_kwargs['submission'] = SubmissionFactory(**submission_kwargs)

    ScoreLogFactory(**scorelog_kwargs)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    with pytest.raises(ValueError) as e:
        invoice.get_rates()

    assert (
        'Multiple rate values recorded for user %s' % (member.username, )
        in e.value.message
    )
예제 #2
0
def test_invoice_get_rates_inconsistent_paidtask_rates(member, task_type,
                                                       task_type_name,
                                                       user_rate_attr_name,
                                                       store0):
    USER_RATE = 0.5
    PAID_TASK_RATE = 0.2

    # Set some user rate
    setattr(member, user_rate_attr_name, USER_RATE)
    member.save()

    month = timezone.datetime(2014, 04, 01)

    submission_kwargs = {
        'store': store0,
        'unit': store0.units[0],
        'field': SubmissionFields.TARGET,
        'type': SubmissionTypes.NORMAL,
        'old_value': 'foo',
        'new_value': 'bar',
        'submitter': member,
        'translation_project': store0.translation_project,
        'creation_time': month,
    }
    scorelog_kwargs = {
        'wordcount': 1,
        'similarity': 0,
        'action_code': TranslationActionCodes.NEW,
        'creation_time': month,
        'user': member,
        'submission': SubmissionFactory(**submission_kwargs),
    }
    paid_task_kwargs = {
        'rate': PAID_TASK_RATE,  # Note how this doesn't match user's rate
        'datetime': month,
        'user': member,
        'task_type': task_type,
    }

    ScoreLogFactory(**scorelog_kwargs)
    PaidTaskFactory(**paid_task_kwargs)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    with pytest.raises(ValueError) as e:
        invoice.get_rates()

    assert (
        'Multiple %s rate values for user %s' % (task_type_name,
                                                 member.username)
        in e.value.message
    )
예제 #3
0
def test_invoice_get_rates_inconsistent_paidtask_rates(member, task_type,
                                                       task_type_name,
                                                       user_rate_attr_name,
                                                       store0):
    USER_RATE = 0.5
    PAID_TASK_RATE = 0.2

    # Set some user rate
    setattr(member, user_rate_attr_name, USER_RATE)
    member.save()

    month = timezone.make_aware(timezone.datetime(2014, 4, 1))

    submission_kwargs = {
        "store": store0,
        "unit": store0.units[0],
        "field": SubmissionFields.TARGET,
        "type": SubmissionTypes.NORMAL,
        "old_value": "foo",
        "new_value": "bar",
        "submitter": member,
        "translation_project": store0.translation_project,
        "creation_time": month,
    }
    scorelog_kwargs = {
        "wordcount": 1,
        "similarity": 0,
        "action_code": TranslationActionCodes.NEW,
        "creation_time": month,
        "user": member,
        "submission": SubmissionFactory(**submission_kwargs),
    }
    paid_task_kwargs = {
        "rate": PAID_TASK_RATE,  # Note how this doesn't match user's rate
        "datetime": month,
        "user": member,
        "task_type": task_type,
    }

    ScoreLogFactory(**scorelog_kwargs)
    PaidTaskFactory(**paid_task_kwargs)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    with pytest.raises(ValueError) as e:
        invoice.get_rates()

    assert "Multiple %s rate values for user %s" % (
        task_type_name,
        member.username,
    ) in str(e.value)
예제 #4
0
def test_invoice_get_rates_inconsistent_scorelog_rates(member, store0):
    USER_RATE_ONE = 0.5
    USER_RATE_TWO = 0.2

    # Set some rate
    member.rate = USER_RATE_ONE
    member.review_rate = USER_RATE_ONE
    member.save()

    month = timezone.make_aware(timezone.datetime(2014, 4, 1))

    submission_kwargs = {
        "store": store0,
        "unit": store0.units[0],
        "field": SubmissionFields.TARGET,
        "type": SubmissionTypes.NORMAL,
        "old_value": "foo",
        "new_value": "bar",
        "submitter": member,
        "translation_project": store0.translation_project,
        "creation_time": month,
    }
    scorelog_kwargs = {
        "wordcount": 1,
        "similarity": 0,
        "action_code": TranslationActionCodes.NEW,
        "creation_time": month,
        "user": member,
        "submission": SubmissionFactory(**submission_kwargs),
    }

    ScoreLogFactory(**scorelog_kwargs)

    # Alter rates, producing an inconsistent state when recording the ScoreLog
    member.rate = USER_RATE_TWO
    member.review_rate = USER_RATE_TWO
    member.save()

    submission_kwargs["unit"] = store0.units[1]
    scorelog_kwargs["submission"] = SubmissionFactory(**submission_kwargs)

    ScoreLogFactory(**scorelog_kwargs)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    with pytest.raises(ValueError) as e:
        invoice.get_rates()

    assert "Multiple rate values recorded for user %s" % (
        member.username, ) in str(e.value)
예제 #5
0
def test_invoice_get_rates_paidtask_rates(member):
    """Tests that `Invoice.get_rates()` returns the rates set for users in their
    `PaidTask` entries.
    """
    USER_RATE_ONE = 0.5
    USER_RATE_TWO = 0.2

    # Set some user rate
    member.hourly_rate = USER_RATE_ONE
    member.save()

    month = timezone.datetime(2014, 04, 01)

    paid_task_kwargs = {
        'rate': USER_RATE_ONE,
        'datetime': month,
        'user': member,
        'task_type': PaidTaskTypes.HOURLY_WORK,
    }
    PaidTaskFactory(**paid_task_kwargs)

    invoice = Invoice(member, FAKE_CONFIG, month=month)

    # Set user rate to something else to ensure we get the recorded rates
    member.hourly_rate = USER_RATE_TWO
    member.save()

    rate, review_rate, hourly_rate = invoice.get_rates()
    assert hourly_rate == USER_RATE_ONE
예제 #6
0
def test_invoice_get_rates_inconsistent_hourly_paidtask_rates(member):
    PAID_TASK_RATE_ONE = 0.5
    PAID_TASK_RATE_TWO = 0.2

    month = timezone.datetime(2014, 04, 01)

    paid_task_kwargs = {
        'rate': PAID_TASK_RATE_ONE,  # Note how this doesn't match user's rate
        'datetime': month,
        'user': member,
        'task_type': PaidTaskTypes.HOURLY_WORK,
    }

    PaidTaskFactory(**paid_task_kwargs)
    PaidTaskFactory(**dict(paid_task_kwargs, rate=PAID_TASK_RATE_TWO))
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    with pytest.raises(ValueError) as e:
        invoice.get_rates()

    assert ('Multiple HOURLY_WORK rate values for user %s' % (member.username)
            in e.value.message)
예제 #7
0
def test_invoice_get_rates_inconsistent_hourly_paidtask_rates(member):
    PAID_TASK_RATE_ONE = 0.5
    PAID_TASK_RATE_TWO = 0.2

    month = timezone.make_aware(timezone.datetime(2014, 4, 1))

    paid_task_kwargs = {
        "rate": PAID_TASK_RATE_ONE,  # Note how this doesn't match user's rate
        "datetime": month,
        "user": member,
        "task_type": PaidTaskTypes.HOURLY_WORK,
    }

    PaidTaskFactory(**paid_task_kwargs)
    PaidTaskFactory(**dict(paid_task_kwargs, rate=PAID_TASK_RATE_TWO))
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    with pytest.raises(ValueError) as e:
        invoice.get_rates()

    assert "Multiple HOURLY_WORK rate values for user %s" % (
        member.username) in str(e.value)
예제 #8
0
def test_invoice_get_rates_user(member):
    """Tests that `Invoice.get_rates()` returns the rates set for users in their
    user model.
    """
    USER_RATE = 0.5

    # Set some user rate
    member.rate = USER_RATE
    member.review_rate = USER_RATE
    member.hourly_rate = USER_RATE
    member.save()

    month = timezone.datetime(2014, 04, 01)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    rate, review_rate, hourly_rate = invoice.get_rates()
    assert rate == USER_RATE
    assert review_rate == USER_RATE
    assert hourly_rate == USER_RATE
예제 #9
0
def test_invoice_get_rates_scorelog_rates(member, task_type, task_type_name,
                                          user_rate_attr_name, store0):
    """Tests that `Invoice.get_rates()` returns the rates set for users in their
    `ScoreLog` entries.
    """
    USER_RATE_ONE = 0.5
    USER_RATE_TWO = 0.2

    # Set some user rate
    setattr(member, user_rate_attr_name, USER_RATE_ONE)
    member.save()

    month = timezone.datetime(2014, 04, 01)

    submission_kwargs = {
        'store': store0,
        'unit': store0.units[0],
        'field': SubmissionFields.TARGET,
        'type': SubmissionTypes.NORMAL,
        'old_value': 'foo',
        'new_value': 'bar',
        'submitter': member,
        'translation_project': store0.translation_project,
        'creation_time': month,
    }
    scorelog_kwargs = {
        'wordcount': 1,
        'similarity': 0,
        'action_code': TranslationActionCodes.NEW,
        'creation_time': month,
        'user': member,
        'submission': SubmissionFactory(**submission_kwargs),
    }

    ScoreLogFactory(**scorelog_kwargs)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    # Set user rate to something else to ensure we get the recorded rates
    setattr(member, user_rate_attr_name, USER_RATE_TWO)
    member.save()

    rate, review_rate, hourly_rate = invoice.get_rates()
    assert locals()[user_rate_attr_name] == USER_RATE_ONE
예제 #10
0
def test_invoice_get_rates_scorelog_rates(member, task_type, task_type_name,
                                          user_rate_attr_name, store0):
    """Tests that `Invoice.get_rates()` returns the rates set for users in their
    `ScoreLog` entries.
    """
    USER_RATE_ONE = 0.5
    USER_RATE_TWO = 0.2

    # Set some user rate
    setattr(member, user_rate_attr_name, USER_RATE_ONE)
    member.save()

    month = timezone.make_aware(timezone.datetime(2014, 4, 1))

    submission_kwargs = {
        "store": store0,
        "unit": store0.units[0],
        "field": SubmissionFields.TARGET,
        "type": SubmissionTypes.NORMAL,
        "old_value": "foo",
        "new_value": "bar",
        "submitter": member,
        "translation_project": store0.translation_project,
        "creation_time": month,
    }
    scorelog_kwargs = {
        "wordcount": 1,
        "similarity": 0,
        "action_code": TranslationActionCodes.NEW,
        "creation_time": month,
        "user": member,
        "submission": SubmissionFactory(**submission_kwargs),
    }

    ScoreLogFactory(**scorelog_kwargs)
    invoice = Invoice(member, FAKE_CONFIG, month=month)

    # Set user rate to something else to ensure we get the recorded rates
    setattr(member, user_rate_attr_name, USER_RATE_TWO)
    member.save()

    rate, review_rate, hourly_rate = invoice.get_rates()
    assert locals()[user_rate_attr_name] == USER_RATE_ONE