33
33
34
34
from tests .integration import PROTOCOL_VERSION , CASSANDRA_VERSION , greaterthanorequalcass30 , greaterthanorequalcass3_11
35
35
from tests .integration .cqlengine .base import BaseCassEngTestCase
36
+ import pytest
36
37
37
38
38
39
class TestDatetime (BaseCassEngTestCase ):
@@ -90,7 +91,7 @@ def test_datetime_none(self):
90
91
91
92
def test_datetime_invalid (self ):
92
93
dt_value = 'INVALID'
93
- with self . assertRaises (TypeError ):
94
+ with pytest . raises (TypeError ):
94
95
self .DatetimeTest .objects .create (test_id = 4 , created_at = dt_value )
95
96
96
97
def test_datetime_timestamp (self ):
@@ -185,7 +186,7 @@ def test_varint_io(self):
185
186
int2 = self .VarIntTest .objects (test_id = 0 ).first ()
186
187
assert int1 .bignum == int2 .bignum
187
188
188
- with self . assertRaises (ValidationError ):
189
+ with pytest . raises (ValidationError ):
189
190
self .VarIntTest .objects .create (test_id = 0 , bignum = "not_a_number" )
190
191
191
192
@@ -541,22 +542,22 @@ def test_min_length(self):
541
542
Ascii (min_length = 5 ).validate ('kevin' )
542
543
Ascii (min_length = 5 ).validate ('kevintastic' )
543
544
544
- with self . assertRaises (ValidationError ):
545
+ with pytest . raises (ValidationError ):
545
546
Ascii (min_length = 1 ).validate ('' )
546
547
547
- with self . assertRaises (ValidationError ):
548
+ with pytest . raises (ValidationError ):
548
549
Ascii (min_length = 1 ).validate (None )
549
550
550
- with self . assertRaises (ValidationError ):
551
+ with pytest . raises (ValidationError ):
551
552
Ascii (min_length = 6 ).validate ('' )
552
553
553
- with self . assertRaises (ValidationError ):
554
+ with pytest . raises (ValidationError ):
554
555
Ascii (min_length = 6 ).validate (None )
555
556
556
- with self . assertRaises (ValidationError ):
557
+ with pytest . raises (ValidationError ):
557
558
Ascii (min_length = 6 ).validate ('kevin' )
558
559
559
- with self . assertRaises (ValueError ):
560
+ with pytest . raises (ValueError ):
560
561
Ascii (min_length = - 1 )
561
562
562
563
def test_max_length (self ):
@@ -573,13 +574,13 @@ def test_max_length(self):
573
574
Ascii (max_length = 5 ).validate ('b' )
574
575
Ascii (max_length = 5 ).validate ('blake' )
575
576
576
- with self . assertRaises (ValidationError ):
577
+ with pytest . raises (ValidationError ):
577
578
Ascii (max_length = 0 ).validate ('b' )
578
579
579
- with self . assertRaises (ValidationError ):
580
+ with pytest . raises (ValidationError ):
580
581
Ascii (max_length = 5 ).validate ('blaketastic' )
581
582
582
- with self . assertRaises (ValueError ):
583
+ with pytest . raises (ValueError ):
583
584
Ascii (max_length = - 1 )
584
585
585
586
def test_length_range (self ):
@@ -588,30 +589,30 @@ def test_length_range(self):
588
589
Ascii (min_length = 10 , max_length = 10 )
589
590
Ascii (min_length = 10 , max_length = 11 )
590
591
591
- with self . assertRaises (ValueError ):
592
+ with pytest . raises (ValueError ):
592
593
Ascii (min_length = 10 , max_length = 9 )
593
594
594
- with self . assertRaises (ValueError ):
595
+ with pytest . raises (ValueError ):
595
596
Ascii (min_length = 1 , max_length = 0 )
596
597
597
598
def test_type_checking (self ):
598
599
Ascii ().validate ('string' )
599
600
Ascii ().validate (u'unicode' )
600
601
Ascii ().validate (bytearray ('bytearray' , encoding = 'ascii' ))
601
602
602
- with self . assertRaises (ValidationError ):
603
+ with pytest . raises (ValidationError ):
603
604
Ascii ().validate (5 )
604
605
605
- with self . assertRaises (ValidationError ):
606
+ with pytest . raises (ValidationError ):
606
607
Ascii ().validate (True )
607
608
608
609
Ascii ().validate ("!#$%&\' ()*+,-./" )
609
610
610
- with self . assertRaises (ValidationError ):
611
+ with pytest . raises (ValidationError ):
611
612
Ascii ().validate ('Beyonc' + chr (233 ))
612
613
613
614
if sys .version_info < (3 , 1 ):
614
- with self . assertRaises (ValidationError ):
615
+ with pytest . raises (ValidationError ):
615
616
Ascii ().validate (u'Beyonc' + unichr (233 ))
616
617
617
618
def test_unaltering_validation (self ):
@@ -629,26 +630,26 @@ def test_required_validation(self):
629
630
""" Tests that validation raise on none and blank values if value required. """
630
631
Ascii (required = True ).validate ('k' )
631
632
632
- with self . assertRaises (ValidationError ):
633
+ with pytest . raises (ValidationError ):
633
634
Ascii (required = True ).validate ('' )
634
635
635
- with self . assertRaises (ValidationError ):
636
+ with pytest . raises (ValidationError ):
636
637
Ascii (required = True ).validate (None )
637
638
638
639
# With min_length set.
639
640
Ascii (required = True , min_length = 0 ).validate ('k' )
640
641
Ascii (required = True , min_length = 1 ).validate ('k' )
641
642
642
- with self . assertRaises (ValidationError ):
643
+ with pytest . raises (ValidationError ):
643
644
Ascii (required = True , min_length = 2 ).validate ('k' )
644
645
645
646
# With max_length set.
646
647
Ascii (required = True , max_length = 1 ).validate ('k' )
647
648
648
- with self . assertRaises (ValidationError ):
649
+ with pytest . raises (ValidationError ):
649
650
Ascii (required = True , max_length = 2 ).validate ('kevin' )
650
651
651
- with self . assertRaises (ValueError ):
652
+ with pytest . raises (ValueError ):
652
653
Ascii (required = True , max_length = 0 )
653
654
654
655
@@ -668,22 +669,22 @@ def test_min_length(self):
668
669
Text (min_length = 5 ).validate ('blake' )
669
670
Text (min_length = 5 ).validate ('blaketastic' )
670
671
671
- with self . assertRaises (ValidationError ):
672
+ with pytest . raises (ValidationError ):
672
673
Text (min_length = 1 ).validate ('' )
673
674
674
- with self . assertRaises (ValidationError ):
675
+ with pytest . raises (ValidationError ):
675
676
Text (min_length = 1 ).validate (None )
676
677
677
- with self . assertRaises (ValidationError ):
678
+ with pytest . raises (ValidationError ):
678
679
Text (min_length = 6 ).validate ('' )
679
680
680
- with self . assertRaises (ValidationError ):
681
+ with pytest . raises (ValidationError ):
681
682
Text (min_length = 6 ).validate (None )
682
683
683
- with self . assertRaises (ValidationError ):
684
+ with pytest . raises (ValidationError ):
684
685
Text (min_length = 6 ).validate ('blake' )
685
686
686
- with self . assertRaises (ValueError ):
687
+ with pytest . raises (ValueError ):
687
688
Text (min_length = - 1 )
688
689
689
690
def test_max_length (self ):
@@ -700,13 +701,13 @@ def test_max_length(self):
700
701
Text (max_length = 5 ).validate ('b' )
701
702
Text (max_length = 5 ).validate ('blake' )
702
703
703
- with self . assertRaises (ValidationError ):
704
+ with pytest . raises (ValidationError ):
704
705
Text (max_length = 0 ).validate ('b' )
705
706
706
- with self . assertRaises (ValidationError ):
707
+ with pytest . raises (ValidationError ):
707
708
Text (max_length = 5 ).validate ('blaketastic' )
708
709
709
- with self . assertRaises (ValueError ):
710
+ with pytest . raises (ValueError ):
710
711
Text (max_length = - 1 )
711
712
712
713
def test_length_range (self ):
@@ -715,21 +716,21 @@ def test_length_range(self):
715
716
Text (min_length = 10 , max_length = 10 )
716
717
Text (min_length = 10 , max_length = 11 )
717
718
718
- with self . assertRaises (ValueError ):
719
+ with pytest . raises (ValueError ):
719
720
Text (min_length = 10 , max_length = 9 )
720
721
721
- with self . assertRaises (ValueError ):
722
+ with pytest . raises (ValueError ):
722
723
Text (min_length = 1 , max_length = 0 )
723
724
724
725
def test_type_checking (self ):
725
726
Text ().validate ('string' )
726
727
Text ().validate (u'unicode' )
727
728
Text ().validate (bytearray ('bytearray' , encoding = 'ascii' ))
728
729
729
- with self . assertRaises (ValidationError ):
730
+ with pytest . raises (ValidationError ):
730
731
Text ().validate (5 )
731
732
732
- with self . assertRaises (ValidationError ):
733
+ with pytest . raises (ValidationError ):
733
734
Text ().validate (True )
734
735
735
736
Text ().validate ("!#$%&\' ()*+,-./" )
@@ -752,26 +753,26 @@ def test_required_validation(self):
752
753
""" Tests that validation raise on none and blank values if value required. """
753
754
Text (required = True ).validate ('b' )
754
755
755
- with self . assertRaises (ValidationError ):
756
+ with pytest . raises (ValidationError ):
756
757
Text (required = True ).validate ('' )
757
758
758
- with self . assertRaises (ValidationError ):
759
+ with pytest . raises (ValidationError ):
759
760
Text (required = True ).validate (None )
760
761
761
762
# With min_length set.
762
763
Text (required = True , min_length = 0 ).validate ('b' )
763
764
Text (required = True , min_length = 1 ).validate ('b' )
764
765
765
- with self . assertRaises (ValidationError ):
766
+ with pytest . raises (ValidationError ):
766
767
Text (required = True , min_length = 2 ).validate ('b' )
767
768
768
769
# With max_length set.
769
770
Text (required = True , max_length = 1 ).validate ('b' )
770
771
771
- with self . assertRaises (ValidationError ):
772
+ with pytest . raises (ValidationError ):
772
773
Text (required = True , max_length = 2 ).validate ('blake' )
773
774
774
- with self . assertRaises (ValueError ):
775
+ with pytest . raises (ValueError ):
775
776
Text (required = True , max_length = 0 )
776
777
777
778
@@ -781,7 +782,7 @@ class TestModel(Model):
781
782
id = UUID (primary_key = True , default = uuid4 )
782
783
783
784
def test_extra_field (self ):
784
- with self . assertRaises (ValidationError ):
785
+ with pytest . raises (ValidationError ):
785
786
self .TestModel .create (bacon = 5000 )
786
787
787
788
@@ -834,5 +835,5 @@ def test_inet_saves(self):
834
835
835
836
def test_non_address_fails (self ):
836
837
# TODO: presently this only tests that the server blows it up. Is there supposed to be local validation?
837
- with self . assertRaises (InvalidRequest ):
838
+ with pytest . raises (InvalidRequest ):
838
839
self .InetTestModel .create (address = "what is going on here?" )
0 commit comments