Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

78

79

80

81

82

83

84

import csv 

import logging 

 

import django 

from django.test import TestCase 

 

from .csv_parser import TransactionReader 

from .models import Transaction 

 

django.setup() 

 

logging.getLogger(__name__) 

logging.getLogger().setLevel(logging.DEBUG) 

 

 

def line_from_csv(line): 

with open('import_app/tests.csv') as f: 

csvin = csv.reader(f, delimiter=';') 

csvin = list(csvin) 

return csvin[line] 

 

 

def make_transaction_reader(line): 

line_split = line_from_csv(line) 

tr = TransactionReader(line_split) 

return tr 

 

 

def make_transaction(line): 

tr = make_transaction_reader(line) 

transaction = Transaction() 

transaction.add_transaction(tr) 

return transaction 

 

 

class TransactionReaderTest(TestCase): 

def test_chaos_nr_regex(self): # these should match on regex(s) for chaos number/mitgliedsbeitrag w/ high confidence 

for i in range(3): 

tr = make_transaction_reader(i) 

self.assertLess(tr.rating, 8) 

 

def test_number_mashing(self): 

transaction = make_transaction(4) 

self.assertIn(transaction.chaos_number, [15, 16]) 

self.assertEqual(transaction.status, transaction.STATUS_UNKNOWN_CHAOS_NR) 

 

def test_year_split_year5(self): # wz: Mitgliedsbeitraege: 8001 (2014, 201 5) 

transaction = make_transaction(5) 

self.assertEqual(transaction.chaos_number, 8001) 

self.assertEqual(transaction.status, Transaction.STATUS_MATCHED_CHAOS_NR) 

 

def test_year_split_year6(self): # mitgliedschaftsbeitrag 2014+2015 f. chaosnr. 5003 

transaction = make_transaction(6) 

self.assertEqual(transaction.chaos_number, 5003) 

self.assertEqual(transaction.status, Transaction.STATUS_MATCHED_CHAOS_NR) 

 

def test_year_split_year7(self): # Mitgliedsbeitraege (2014, 201 5) 

transaction = make_transaction(7) 

self.assertIn(transaction.chaos_number, [201, 5]) 

self.assertEqual(transaction.status, Transaction.STATUS_UNKNOWN_CHAOS_NR) 

 

def test_donation(self): 

transaction = make_transaction(11) 

self.assertEqual(transaction.status, Transaction.STATUS_IGNOREFOREVER) 

 

def test_year_after_chaos_key(self): 

transaction = make_transaction(12) 

self.assertEqual(transaction.status, Transaction.STATUS_UNKNOWN_CHAOS_NR) # erring with no false positives 

self.assertEqual(transaction.chaos_number, 2015) 

 

def test_skip_year(self): 

transaction = make_transaction(13) # corresponds to line number in csv, add lines only to end of csv!! 

self.assertEqual(transaction.status, Transaction.STATUS_UNKNOWN_CHAOS_NR) 

self.assertEqual(transaction.chaos_number, 2014) 

 

def test_multi_numbers(self): 

transaction = make_transaction(14) # Verwendungszweck 2014 3000 .. 

self.assertEqual(transaction.status, Transaction.STATUS_MATCHED_CHAOS_NR) 

self.assertEqual(transaction.chaos_number, 3000) 

 

def test_multi_numbers_chaosnr(self): 

transaction = make_transaction(15) # Verwendungszweck 2014 chaosnr 3000 .. 

self.assertEqual(transaction.status, Transaction.STATUS_MATCHED_CHAOS_NR) 

self.assertEqual(transaction.chaos_number, 3000)