def test_get_a_contacts_collection_and_page_to_last_page_items_are_different(self): valid_filters = {u"organisation": self.org_name_token} col = collection.get_collection_instance("contact") col.set_filters(valid_filters) col.set_per_page(10) col.load() page_1_url = col._last_query_str #see setup self.assertTrue(col.get_total_entries()>=21) self.assertTrue(len(col.get_items()) == col.get_per_page()) self.assertTrue(col.get_total_pages() > 2) first_page_ids = [] items = col.get_items() for x in xrange(0, len(items)): obj = items[x].id first_page_ids.append(obj) self.assertEquals(len(first_page_ids), 10) col.clear_items() col.load(page = col.get_total_pages()) page_2_url = col._last_query_str msg = u"%s\n%s\n should not be equal" % (page_1_url, page_2_url) self.assertNotEquals(page_1_url, page_2_url, msg) last_item = col.get_items()[0] last_number = last_item.id self.assertTrue(len(last_number) > 0) self.assertTrue(last_number not in first_page_ids)
def test_initialize_all_json_schemes_as_collections(self): all_file_names = self._load_all_filenames_from_disk() all_files_cnt = len(all_file_names) no_collection_endpoint = [ 'address', 'line_item', 'divider_item', 'sub_total_item', 'user', ] needs_fix = [ 'company', # //he? 'credit_note', # currently broken 'document', # currently broken 'invoice', # currently broken 'sub', # currently broken ] no_collection_endpoint.extend(needs_fix) ok = True for afile in all_file_names: schema_name = afile.split(".") col = None is_loadable = (schema_name[0] not in no_collection_endpoint) if is_loadable: col = collection.get_collection_instance(schema_name[0]) col.set_per_page(10) col.load() self.assertTrue(ok)
def setUp(self): """ this test is slow as it gets over the air creates 201 resources of client named fb-counter if they do not exist """ super(LiveCollectionBaseTestCase,self).setUp() self.api_client = api.APIClient() # check if we need to setup 21 sk-clients valid_filters = {"organisation": self.org_name_token} col = collection.get_collection_instance("contact") col.set_filters(valid_filters) # executes the query col.load() items_per_page_cnt = col.get_per_page() self.total_pages = col.get_total_pages() total_entries = col.get_total_entries() current_page = col.get_current_page() msg = u"filters:%s,\nper page cnt %s, total pages %s, total entries %s, current_page %s" % ( valid_filters, items_per_page_cnt, self.total_pages, total_entries, current_page) #print msg if total_entries <= 21: # create 21 clients model = resources.get_model_class("contact", api=self.api_client) for x in xrange(total_entries, 21): self.valid_data["organisation"] = "%s%s" % (self.org_name_token, x) client = model(self.valid_data) client = client.save()
def test_initialise_collection(self): col=collection.get_collection_instance("contact", self.api_mock) col.load(page=1) self.assertTrue(len(col.get_items()) == 5) self.assertEquals(col.get_items()[0].number, u"K-2012-001") self.assertEquals(col.get_items()[1].organisation, u"king") self.assertEquals(col.get_items()[3].organisation, u"Werbeagentur Gl\u00fcck")
def test_get_invoice_collection(self): valid_filters = {u"q": self.org_name_token} col = collection.get_collection_instance("invoice") col.set_filters(valid_filters) col.set_per_page(10) col.load() page_1_url = col._last_query_str items = col.get_items() #see setup self.assertTrue(col.get_total_pages() > 0)
def test_validate_filters(self): col=collection.get_collection_instance("client",self.api_mock) #date-time germany #self.assertTrue(col.validate_filter("created_at_from","2012-12-19T00:39:49+01:00")); self.assertTrue(col.validate_filter("number","string")) self.assertFalse(col.validate_filter("notexisting","string")) self.assertTrue(col.validate_filter("birthday_to","2012-01-01")); self.assertFalse(col.validate_filter("birthday_to","string")); self.assertFalse(col.validate_filter("birthday_to","1999-01-32")); self.assertFalse(col.validate_filter("birthday_to","1999-13-01")); self.assertTrue(col.validate_filter("birthday_to","1999-01-01"));
def test_contact_collection_to_valid_items_success(self): """ Assumes there is already a Client created manually """ valid_filters = {"organisation": "salesking", "type": "Client"} col = collection.get_collection_instance("contact") col.set_filters(valid_filters) col.load() msg = "query:%s" % col._last_query_str self.assertTrue(col._last_query_str is not None, msg) items = col.get_items() self.assertTrue(len(items) > 0) self.assertTrue(col.total_pages >= 1) self.assertTrue(col.total_entries > 0)
def test_other_then_startpage(self): valid_filters = {u"organisation": self.org_name_token} col = collection.get_collection_instance("contact") col.set_filters(valid_filters) col.set_per_page(10) col.load(page=self.total_pages) page_1_url = col._last_query_str #see setup self.assertTrue(col.get_total_entries() >= 21) self.assertTrue(len(col.get_items()) == col.get_per_page()) self.assertTrue(col.get_total_pages() > 2) first_page_ids = [] items = col.get_items() for x in range(0, len(items)): obj = items[x].id first_page_ids.append(obj) self.assertEquals(len(first_page_ids), 10)
def test_client_collection_lookup_and_delete_all_organisations_named_sk_success(self): valid_filters = {"q":"salesking"} col=collection.get_collection_instance("client") col.set_filters(valid_filters) col.load() msg = "query:%s" % col._last_query_str self.assertTrue(col._last_query_str is not None, msg) self.assertTrue(len(col.items) > 0) self.assertEquals(col.total_pages,1) for x in col.items: print "numbers %s" % x.number x.delete() col.load() msg = "query:%s" % col._last_query_str self.assertTrue(col._last_query_str is not None, msg) self.assertEquals(col.total_pages,1) self.assertEquals(col.total_entries,0) self.assertTrue(len(col.items)==0)
def test_add_filters(self): col = collection.get_collection_instance("contact", self.api_mock) self.assertTrue(col.add_filter("number", "astrstring")) self.assertRaises(SalesKingException, col.add_filter, "notexisting", "string")
def test_set_filters(self): valid_filters = {"q": "salesking", "number": "K-123-0001"} col = collection.get_collection_instance("contact", self.api_mock) col.set_filters(valid_filters) self.assertEquals(valid_filters, col.get_filters())