forked from CenterForOpenScience/osf.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_registration_bulk_upload_row.py
77 lines (59 loc) · 2.97 KB
/
test_registration_bulk_upload_row.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import hashlib
import pytest
from django.db.utils import IntegrityError
from api.base.settings import BULK_SETTINGS
from osf.models import RegistrationBulkUploadRow
from osf_tests.factories import RegistrationBulkUploadJobFactory
from osf.utils.fields import ensure_bytes
@pytest.mark.django_db
class TestRegistrationBulkUploadRow:
@pytest.fixture()
def upload_job(self):
return RegistrationBulkUploadJobFactory()
@pytest.fixture()
def csv_raw_1(self):
return 'a' * BULK_SETTINGS['DEFAULT_BULK_LIMIT'] * 1
@pytest.fixture()
def csv_raw_2(self):
return 'b' * BULK_SETTINGS['DEFAULT_BULK_LIMIT'] * 1
@pytest.fixture()
def row_hash_1(self, csv_raw_1):
return hashlib.md5(ensure_bytes(csv_raw_1)).hexdigest()
@pytest.fixture()
def row_hash_2(self, csv_raw_2):
return hashlib.md5(ensure_bytes(csv_raw_2)).hexdigest()
@pytest.fixture()
def csv_parsed_1(self):
return {'key_1': 'val_1', 'key_2': 'val_2'}
@pytest.fixture()
def csv_parsed_2(self):
return {'key_2': 'val_2', 'key_3': 'val_3'}
def test_row_creation(self, upload_job, csv_raw_1, csv_parsed_1, row_hash_1):
registration_row = RegistrationBulkUploadRow.create(upload_job, csv_raw_1, csv_parsed_1)
registration_row.save()
registration_row.reload()
assert registration_row.draft_registration is None
assert registration_row.is_completed is False
assert registration_row.is_picked_up is False
assert registration_row.row_hash == row_hash_1
assert registration_row.upload == upload_job
assert registration_row.csv_raw == csv_raw_1
assert registration_row.csv_parsed == csv_parsed_1
def test_row_object_hash(self, upload_job, csv_raw_2, csv_parsed_2, row_hash_2):
registration_row = RegistrationBulkUploadRow.create(upload_job, csv_raw_2, csv_parsed_2)
assert registration_row.__hash__() == hash(row_hash_2)
registration_row.save()
registration_row.reload()
assert registration_row.__hash__() == hash(registration_row.pk)
def test_row_object_eq(self, upload_job, csv_raw_1, csv_raw_2, csv_parsed_1, csv_parsed_2):
registration_row_1 = RegistrationBulkUploadRow.create(upload_job, csv_raw_1, csv_parsed_1)
registration_row_2 = RegistrationBulkUploadRow.create(upload_job, csv_raw_2, csv_parsed_2)
registration_row_3 = RegistrationBulkUploadRow.create(upload_job, csv_raw_2, csv_parsed_2)
assert registration_row_1 != registration_row_2
assert registration_row_2 == registration_row_3
def test_row_uniqueness(self, upload_job, csv_raw_1, csv_raw_2, csv_parsed_1, csv_parsed_2):
registration_row_1 = RegistrationBulkUploadRow.create(upload_job, csv_raw_1, csv_parsed_1)
registration_row_1.save()
registration_row_2 = RegistrationBulkUploadRow.create(upload_job, csv_raw_1, csv_parsed_2)
with pytest.raises(IntegrityError):
registration_row_2.save()