Repository: fossasia/open-event-server

Issue:
Remove redundant validation methods from TicketSchema
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
A few validation methods are present in both the TicketSchemaPublic as well as TicketSchema. Since TicketSchema inherits from the TicketSchemaPublic, it doesn't make sense to have two methods.

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
Remove them.


Discussion:

Resolving patch:
diff --git a/app/api/schema/tickets.py b/app/api/schema/tickets.py
--- a/app/api/schema/tickets.py
+++ b/app/api/schema/tickets.py
@@ -10,6 +10,7 @@
 from app.models.ticket import Ticket
 from utils.common import use_defaults
 
+
 @use_defaults()
 class TicketSchemaPublic(SoftDeletionSchema):
     class Meta:
@@ -45,6 +46,11 @@ def validate_quantity(self, data):
                 raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
                                           "quantity should be greater than min-order")
 
+        if 'quantity' in data and 'max_order' in data:
+            if data['quantity'] < data['max_order']:
+                raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
+                                          "quantity should be lesser than max-order")
+
     @validates_schema(pass_original=True)
     def validate_discount_code(self, data, original_data):
         if 'relationships' in original_data and 'discount-codes' in original_data['data']['relationships']:
@@ -107,38 +113,6 @@ class Meta:
         self_view_kwargs = {'id': '<id>'}
         inflect = dasherize
 
-    @validates_schema(pass_original=True)
-    def validate_date(self, data, original_data):
-        if 'id' in original_data['data']:
-            ticket = Ticket.query.filter_by(id=original_data['data']['id']).one()
-
-            if 'sales_starts_at' not in data:
-                data['sales_starts_at'] = ticket.sales_starts_at
-
-            if 'sales_ends_at' not in data:
-                data['sales_ends_at'] = ticket.sales_ends_at
-
-        if data['sales_starts_at'] >= data['sales_ends_at']:
-            raise UnprocessableEntity({'pointer': '/data/attributes/sales-ends-at'},
-                                      "sales-ends-at should be after sales-starts-at")
-
-    @validates_schema
-    def validate_quantity(self, data):
-        if 'max_order' in data and 'min_order' in data:
-            if data['max_order'] < data['min_order']:
-                raise UnprocessableEntity({'pointer': '/data/attributes/max-order'},
-                                          "max-order should be greater than min-order")
-
-        if 'quantity' in data and 'min_order' in data:
-            if data['quantity'] < data['min_order']:
-                raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
-                                          "quantity should be greater than min-order")
-
-        if 'quantity' in data and 'max_order' in data:
-            if data['quantity'] < data['max_order']:
-                raise UnprocessableEntity({'pointer': '/data/attributes/quantity'},
-                                          "quantity should be lesser than max-order")
-
     access_codes = Relationship(attribute='access_codes',
                                 self_view='v1.ticket_access_code',
                                 self_view_kwargs={'id': '<id>'},


Test patch: