from django.test import Client, TestCase

from .utils import create_admin_account, make_request


class VendorApiTest(TestCase):
    """Test for Vendor API."""

    def setUp(self):
        self.client = Client()
        create_admin_account()
        self.vendors = (
            ('vendor1', 'info1'),
            ('vendor2', 'info2')
        )

    def create_vendor(self, name, info):
        query = '''
                mutation{
                    createVendor(input: {name: "%s", info: "%s"}){
                        vendor{
                            id,
                            originalId,
                            name,
                            info
                        }
                    }
                }
                ''' % (name, info)
        return make_request(self.client, query, 'POST')

    def retrieve_vendor(self, vendor_id):
        query = 'query {vendor(id: "%s") {name}}' % (vendor_id)

        return make_request(self.client, query)

    def create_multiple_vendors(self):
        return [self.create_vendor(name, info) for name, info in self.vendors]

    def test_creation_of_vendor_object(self):
        # For new vendor record
        response = self.create_vendor('vendor4', 'info4')
        created_vendor = response['vendor']
        expected = {
            'vendor': {
                'id': created_vendor['id'],
                'originalId': created_vendor['originalId'],
                'name': 'vendor4',
                'info': 'info4'
            }
        }
        self.assertEqual(expected, response)

@@ -233,24 +233,101 @@
 n_account()%0A
+        self.first_vendor = self.create_vendor('vendor1', 'info1')%5B'vendor'%5D%0A
         self
@@ -359,25 +359,25 @@
 ('vendor
-1
+2
 ', 'info
 1'),%0A   
@@ -368,17 +368,17 @@
 ', 'info
-1
+2
 '),%0A    
@@ -393,25 +393,25 @@
 ('vendor
-2
+3
 ', 'info
 2')%0A    
@@ -402,17 +402,17 @@
 ', 'info
-2
+3
 ')%0A     
@@ -1640,8 +1640,566 @@
 sponse)%0A
+%0A        # For existing vendor record%0A        self.assertEqual(%7B'vendor': None%7D,%0A                         self.create_vendor('vendor1', 'info1'))%0A%0A    def test_retrieve_vendor_object(self):%0A        # Retrieve with valid id%0A        response = self.retrieve_vendor(self.first_vendor%5B'id'%5D)%0A        expected = %7B%0A            'vendor': %7B%0A                'name': self.first_vendor%5B'name'%5D%0A            %7D%0A        %7D%0A        self.assertEqual(expected, response)%0A%0A        # Retrieve with invalid id%0A        self.assertEqual(%7B'vendor': None%7D, self.retrieve_vendor(100))%0A

Add test to retrieve vendor object and for existing vendor