{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/comments/47354091","id":47354091,"diff_hunk":"@@ -0,0 +1,284 @@\n+from __future__ import unicode_literals\n+\n+import datetime\n+import json\n+\n+from django.core.urlresolvers import reverse\n+from django.db.utils import IntegrityError\n+from django.test import RequestFactory\n+from oscar.core.loading import get_model\n+\n+from ecommerce.core.models import Client\n+from ecommerce.extensions.api.constants import APIConstants as AC\n+from ecommerce.extensions.api.v2.views.coupons import CouponOrderCreateView\n+from ecommerce.tests.factories import SiteFactory, SiteConfigurationFactory\n+from ecommerce.tests.testcases import TestCase\n+\n+Basket = get_model('basket', 'Basket')\n+Benefit = get_model('offer', 'Benefit')\n+Catalog = get_model('catalogue', 'Catalog')\n+Course = get_model('courses', 'Course')\n+Order = get_model('order', 'Order')\n+Product = get_model('catalogue', 'Product')\n+ProductClass = get_model('catalogue', 'ProductClass')\n+StockRecord = get_model('partner', 'StockRecord')\n+Voucher = get_model('voucher', 'Voucher')\n+\n+COUPONS_LINK = reverse('api:v2:coupons-list')\n+\n+\n+class CouponOrderCreateViewTest(TestCase):\n+    \"\"\"Unit tests for creating coupon order.\"\"\"\n+\n+    def setUp(self):\n+        super(CouponOrderCreateViewTest, self).setUp()\n+        self.user = self.create_user(is_staff=True)\n+        self.client.login(username=self.user.username, password=self.password)\n+\n+        course_id = 'edx/Demo_Course/DemoX'\n+        course = Course.objects.create(id=course_id)\n+        course.create_or_update_seat('verified', True, 50, self.partner)\n+\n+        self.catalog = Catalog.objects.create(partner=self.partner)\n+        self.product_class, __ = ProductClass.objects.get_or_create(name='Coupon')\n+\n+    def create_coupon(self, title, price, data=None):\n+        \"\"\"Helper method for creating a coupon.\"\"\"\n+        if data is None:\n+            # Use default values\n+            data = {\n+                'partner': self.partner,\n+                'benefit_type': Benefit.PERCENTAGE,\n+                'benefit_value': 100,\n+                'catalog': self.catalog,\n+                'end_date': datetime.date(2020, 1, 1),\n+                'code': '',\n+                'quantity': 5,\n+                'start_date': datetime.date(2015, 1, 1),\n+                'voucher_type': Voucher.SINGLE_USE\n+            }\n+\n+        coupon = CouponOrderCreateView().create_coupon_product(\n+            title=title,\n+            price=price,\n+            data=data\n+        )\n+        return coupon\n+\n+    def test_list_coupons(self):\n+        \"\"\"Test coupon API endpoint list.\"\"\"\n+        self.create_coupon(title='Test coupon', price=100)\n+\n+        response = self.client.get(COUPONS_LINK)\n+        self.assertEqual(response.status_code, 200)\n+        result = json.loads(response.content)['results']\n+        self.assertEqual(len(result), 1)\n+        self.assertEqual(result[0]['price'], '100.00')\n+        self.assertEqual(len(result[0]['vouchers']), 5)\n+\n+        # If there are no products it returns an empty response.\n+        Product.objects.all().delete()\n+        response = self.client.get(COUPONS_LINK)\n+        self.assertDictEqual(\n+            json.loads(response.content),\n+            {'count': 0, 'next': None, 'previous': None, 'results': []}\n+        )\n+\n+    def test_create(self):\n+        \"\"\"Test the create method.\"\"\"\n+        site_configuration = SiteConfigurationFactory(partner__name='TestX')\n+        site = SiteFactory()\n+        site.siteconfiguration = site_configuration\n+        data = {\n+            'title': 'Test coupon',\n+            'client_username': 'Client',\n+            'stock_record_ids': [1],\n+            'start_date': '2015-1-1',\n+            'end_date': '2020-1-1',\n+            'code': '',\n+            'benefit_type': Benefit.PERCENTAGE,\n+            'benefit_value': 100,\n+            'voucher_type': Voucher.SINGLE_USE,\n+            'quantity': 1,\n+            'price': 100\n+        }\n+        request = RequestFactory()\n+        request.data = data\n+        request.site = site\n+\n+        response = CouponOrderCreateView().create(request)","path":"ecommerce/extensions/api/v2/tests/views/test_coupons.py","position":109,"original_position":109,"commit_id":"15082d30be6b230da175b53f9494746317c28e0d","original_commit_id":"15082d30be6b230da175b53f9494746317c28e0d","user":{"login":"clintonb","id":910510,"avatar_url":"https://avatars.githubusercontent.com/u/910510?v=3","gravatar_id":"","url":"https://api.github.com/users/clintonb","html_url":"https://github.com/clintonb","followers_url":"https://api.github.com/users/clintonb/followers","following_url":"https://api.github.com/users/clintonb/following{/other_user}","gists_url":"https://api.github.com/users/clintonb/gists{/gist_id}","starred_url":"https://api.github.com/users/clintonb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clintonb/subscriptions","organizations_url":"https://api.github.com/users/clintonb/orgs","repos_url":"https://api.github.com/users/clintonb/repos","events_url":"https://api.github.com/users/clintonb/events{/privacy}","received_events_url":"https://api.github.com/users/clintonb/received_events","type":"User","site_admin":false},"body":"I see what you're doing. You're actually separating unit/functional tests. That's fine. We generally start at the functional level.","created_at":"2015-12-11T13:24:47Z","updated_at":"2015-12-11T13:24:47Z","html_url":"https://github.com/edx/ecommerce/pull/453#discussion_r47354091","pull_request_url":"https://api.github.com/repos/edx/ecommerce/pulls/453","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments/47354091"},"html":{"href":"https://github.com/edx/ecommerce/pull/453#discussion_r47354091"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/453"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/453","id":52669640,"html_url":"https://github.com/edx/ecommerce/pull/453","diff_url":"https://github.com/edx/ecommerce/pull/453.diff","patch_url":"https://github.com/edx/ecommerce/pull/453.patch","issue_url":"https://api.github.com/repos/edx/ecommerce/issues/453","number":453,"state":"open","locked":false,"title":"Created API endpoint for creating Coupon orders.","user":{"login":"vkaracic","id":2808092,"avatar_url":"https://avatars.githubusercontent.com/u/2808092?v=3","gravatar_id":"","url":"https://api.github.com/users/vkaracic","html_url":"https://github.com/vkaracic","followers_url":"https://api.github.com/users/vkaracic/followers","following_url":"https://api.github.com/users/vkaracic/following{/other_user}","gists_url":"https://api.github.com/users/vkaracic/gists{/gist_id}","starred_url":"https://api.github.com/users/vkaracic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkaracic/subscriptions","organizations_url":"https://api.github.com/users/vkaracic/orgs","repos_url":"https://api.github.com/users/vkaracic/repos","events_url":"https://api.github.com/users/vkaracic/events{/privacy}","received_events_url":"https://api.github.com/users/vkaracic/received_events","type":"User","site_admin":false},"body":"This PR contains the API endpoint for coupon products, creating coupons, adding them to the basket, handling the order, fulfilling the order, with accompanying tests. (the test for the fulfillment module is not yet finished).\r\n\r\n@clintonb can you please take a look at the code? Also note that #450 is a prerequisite for this so there is code that calls some models and methods from that PR, Travis will probably fail because of that too. But for now let's just fix any code issues that there might be. Thanks!\r\n\r\n@mjfrey @marjev @dsego  ","created_at":"2015-12-04T13:36:28Z","updated_at":"2015-12-11T13:24:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f261b80d5cb9a778e7c551d1b3a7258f2e5f3f8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce/pulls/453/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce/pulls/453/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce/issues/453/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/15082d30be6b230da175b53f9494746317c28e0d","head":{"label":"vkaracic:vkaracic/SOL-1354","ref":"vkaracic/SOL-1354","sha":"15082d30be6b230da175b53f9494746317c28e0d","user":{"login":"vkaracic","id":2808092,"avatar_url":"https://avatars.githubusercontent.com/u/2808092?v=3","gravatar_id":"","url":"https://api.github.com/users/vkaracic","html_url":"https://github.com/vkaracic","followers_url":"https://api.github.com/users/vkaracic/followers","following_url":"https://api.github.com/users/vkaracic/following{/other_user}","gists_url":"https://api.github.com/users/vkaracic/gists{/gist_id}","starred_url":"https://api.github.com/users/vkaracic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkaracic/subscriptions","organizations_url":"https://api.github.com/users/vkaracic/orgs","repos_url":"https://api.github.com/users/vkaracic/repos","events_url":"https://api.github.com/users/vkaracic/events{/privacy}","received_events_url":"https://api.github.com/users/vkaracic/received_events","type":"User","site_admin":false},"repo":{"id":44113047,"name":"ecommerce","full_name":"vkaracic/ecommerce","owner":{"login":"vkaracic","id":2808092,"avatar_url":"https://avatars.githubusercontent.com/u/2808092?v=3","gravatar_id":"","url":"https://api.github.com/users/vkaracic","html_url":"https://github.com/vkaracic","followers_url":"https://api.github.com/users/vkaracic/followers","following_url":"https://api.github.com/users/vkaracic/following{/other_user}","gists_url":"https://api.github.com/users/vkaracic/gists{/gist_id}","starred_url":"https://api.github.com/users/vkaracic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkaracic/subscriptions","organizations_url":"https://api.github.com/users/vkaracic/orgs","repos_url":"https://api.github.com/users/vkaracic/repos","events_url":"https://api.github.com/users/vkaracic/events{/privacy}","received_events_url":"https://api.github.com/users/vkaracic/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vkaracic/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products","fork":true,"url":"https://api.github.com/repos/vkaracic/ecommerce","forks_url":"https://api.github.com/repos/vkaracic/ecommerce/forks","keys_url":"https://api.github.com/repos/vkaracic/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vkaracic/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vkaracic/ecommerce/teams","hooks_url":"https://api.github.com/repos/vkaracic/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/vkaracic/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/vkaracic/ecommerce/events","assignees_url":"https://api.github.com/repos/vkaracic/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/vkaracic/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/vkaracic/ecommerce/tags","blobs_url":"https://api.github.com/repos/vkaracic/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vkaracic/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vkaracic/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/vkaracic/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vkaracic/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/vkaracic/ecommerce/languages","stargazers_url":"https://api.github.com/repos/vkaracic/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/vkaracic/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/vkaracic/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/vkaracic/ecommerce/subscription","commits_url":"https://api.github.com/repos/vkaracic/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/vkaracic/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/vkaracic/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/vkaracic/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/vkaracic/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/vkaracic/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vkaracic/ecommerce/merges","archive_url":"https://api.github.com/repos/vkaracic/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vkaracic/ecommerce/downloads","issues_url":"https://api.github.com/repos/vkaracic/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/vkaracic/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/vkaracic/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/vkaracic/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vkaracic/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/vkaracic/ecommerce/releases{/id}","created_at":"2015-10-12T14:37:27Z","updated_at":"2015-10-12T14:37:29Z","pushed_at":"2015-12-11T12:56:49Z","git_url":"git://github.com/vkaracic/ecommerce.git","ssh_url":"git@github.com:vkaracic/ecommerce.git","clone_url":"https://github.com/vkaracic/ecommerce.git","svn_url":"https://github.com/vkaracic/ecommerce","homepage":"","size":8424,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"5878a932c1a441e9e871cd417f36a432f17f5a90","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":30175039,"name":"ecommerce","full_name":"edx/ecommerce","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products","fork":false,"url":"https://api.github.com/repos/edx/ecommerce","forks_url":"https://api.github.com/repos/edx/ecommerce/forks","keys_url":"https://api.github.com/repos/edx/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce/events","assignees_url":"https://api.github.com/repos/edx/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce/merges","archive_url":"https://api.github.com/repos/edx/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce/releases{/id}","created_at":"2015-02-02T06:55:15Z","updated_at":"2015-12-02T03:06:44Z","pushed_at":"2015-12-11T12:56:50Z","git_url":"git://github.com/edx/ecommerce.git","ssh_url":"git@github.com:edx/ecommerce.git","clone_url":"https://github.com/edx/ecommerce.git","svn_url":"https://github.com/edx/ecommerce","homepage":"http://open-edx-ecommerce-guide.readthedocs.org","size":8576,"stargazers_count":18,"watchers_count":18,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":9,"forks":18,"open_issues":9,"watchers":18,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/453"},"html":{"href":"https://github.com/edx/ecommerce/pull/453"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce/issues/453"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce/issues/453/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/453/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/453/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce/statuses/15082d30be6b230da175b53f9494746317c28e0d"}}}}