Repository: fossasia/open-event-server

Issue:
add tax api to dredd testing
parent issue: #3870


Discussion:
Also @shubham-padia could you rename and API fields and DB

- `tax-name` -> `name`
- `tax-rate` -> `rate`
- `is-invoice-sent` -> `should-send-invoice`
Sure, im afk right now, will have a look later

On Fri, Jun 30, 2017, 12:33 AM Niranjan Rajendran <notifications@github.com>
wrote:

> Also @shubham-padia <https://github.com/shubham-padia> could you rename
> and API fields and DB
>
>    - tax-name -> name
>    - tax-rate -> rate
>    - is-invoice-sent -> should-send-invoice
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-orga-server/issues/3899#issuecomment-312069002>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ANRCIZSFofCrshvIGiHaVJF0jZziDuRIks5sI_USgaJpZM4OHoCA>
> .
>

@niranjan94 Can you recheck. All those changes have been already done :) 
@SaptakS @niranjan94 What is the purpose of `tax_id` in the the tax model, I tried but can't seem to find anywhere.
@shubham-padia tax ID is something the government issues for a company. Also called as TIN (Tax identification number). 

Resolving patch:
diff --git a/app/factories/tax.py b/app/factories/tax.py
new file mode 100644
--- /dev/null
+++ b/app/factories/tax.py
@@ -0,0 +1,24 @@
+import factory
+from app.models.tax import db, Tax
+from app.factories.event import EventFactoryBasic
+import app.factories.common as common
+
+
+class TaxFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = Tax
+        sqlalchemy_session = db.session
+
+    event = factory.RelatedFactory(EventFactoryBasic)
+    country = common.country_
+    name = common.string_
+    rate = common.float_
+    tax_id = "123456789"
+    should_send_invoice = False
+    registered_company = common.string_
+    address = common.string_
+    city = common.string_
+    state = common.string_
+    zip = "123456"
+    invoice_footer = common.string_
+    is_tax_included_in_price = False


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -28,6 +28,7 @@
 from app.factories.event_sub_topic import EventSubTopicFactory
 from app.factories.sponsor import SponsorFactory
 from app.factories.speakers_call import SpeakersCallFactory
+from app.factories.tax import TaxFactory
 
 stash = {}
 api_username = "open_event_test_user@fossasia.org"
@@ -710,16 +711,6 @@ def sponsor_delete(transaction):
 
 # ------------------------- Tax -------------------------
 
-@hooks.before("Tax > Tax Collection > List All Tax Records")
-def tax_get_list(transaction):
-    """
-    GET /events/1/tax
-    :param transaction:
-    :return:
-    """
-    transaction['skip'] = True
-
-
 @hooks.before("Tax > Tax Collection > Create Tax")
 def tax_post(transaction):
     """
@@ -727,7 +718,10 @@ def tax_post(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Tax > Tax Details > Tax Details")
@@ -737,7 +731,10 @@ def tax_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        tax = TaxFactory()
+        db.session.add(tax)
+        db.session.commit()
 
 
 @hooks.before("Tax > Tax Details > Update Tax")
@@ -747,7 +744,10 @@ def tax_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        tax = TaxFactory()
+        db.session.add(tax)
+        db.session.commit()
 
 
 @hooks.before("Tax > Tax Details > Delete Tax")
@@ -757,7 +757,10 @@ def tax_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        tax = TaxFactory()
+        db.session.add(tax)
+        db.session.commit()
 
 
 # ------------------------- Tickets -------------------------