def test_create_plan_generated(self):
     data = test_plan_data.copy()
     data.update({'id': 'hash', 'doc_id': 'hash2', 'planID': 'hash3'})
     response = self.app.post_json('/plans', {'data': data})
     self.assertEqual(response.status, '201 Created')
     self.assertEqual(response.content_type, 'application/json')
     plan = response.json['data']
     self.assertEqual(set(plan), set([
         u'id', u'dateModified', u'datePublished', u'planID', u'budget', u'tender',
         u'classification', u'additionalClassifications', u'items', u'procuringEntity', u'owner'
     ]))
     self.assertNotEqual(data['id'], plan['id'])
     self.assertNotEqual(data['doc_id'], plan['id'])
     self.assertNotEqual(data['planID'], plan['planID'])
 def test_create_plan_generated(self):
     data = test_plan_data.copy()
     data.update({'id': 'hash', 'doc_id': 'hash2', 'planID': 'hash3'})
     response = self.app.post_json('/plans', {'data': data})
     self.assertEqual(response.status, '201 Created')
     self.assertEqual(response.content_type, 'application/json')
     plan = response.json['data']
     self.assertEqual(
         set(plan),
         set([
             u'id', u'dateModified', u'datePublished', u'planID', u'budget',
             u'tender', u'classification', u'additionalClassifications',
             u'items', u'procuringEntity', u'owner'
         ]))
     self.assertNotEqual(data['id'], plan['id'])
     self.assertNotEqual(data['doc_id'], plan['id'])
     self.assertNotEqual(data['planID'], plan['planID'])
    def test_listing_changes(self):
        response = self.app.get('/plans?feed=changes')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 0)

        plans = []

        for i in range(3):
            response = self.app.post_json('/plans', {'data': test_plan_data})
            self.assertEqual(response.status, '201 Created')
            self.assertEqual(response.content_type, 'application/json')
            plans.append(response.json['data'])

        ids = ','.join([i['id'] for i in plans])

        while True:
            response = self.app.get('/plans?feed=changes')
            self.assertEqual(response.status, '200 OK')
            self.assertTrue(
                ids.startswith(','.join(
                    [i['id'] for i in response.json['data']])))
            if len(response.json['data']) == 3:
                break

        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(','.join([i['id'] for i in response.json['data']]),
                         ids)
        self.assertEqual(set(response.json['data'][0]),
                         set([u'id', u'dateModified']))
        self.assertEqual(set([i['id'] for i in response.json['data']]),
                         set([i['id'] for i in plans]))
        self.assertEqual(
            set([i['dateModified'] for i in response.json['data']]),
            set([i['dateModified'] for i in plans]))
        self.assertEqual([i['dateModified'] for i in response.json['data']],
                         sorted([i['dateModified'] for i in plans]))

        response = self.app.get('/plans?feed=changes&limit=2')
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('prev_page', response.json)
        self.assertEqual(len(response.json['data']), 2)

        response = self.app.get(response.json['next_page']['path'].replace(
            ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get(response.json['next_page']['path'].replace(
            ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 0)

        response = self.app.get('/plans?feed=changes',
                                params=[('opt_fields', 'budget')])
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]),
                         set([u'id', u'dateModified', u'budget']))
        self.assertIn('opt_fields=budget', response.json['next_page']['uri'])

        response = self.app.get('/plans?feed=changes',
                                params=[('opt_fields', 'planID')])
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]),
                         set([u'id', u'dateModified', u'planID']))
        self.assertIn('opt_fields=planID', response.json['next_page']['uri'])

        response = self.app.get('/plans?feed=changes',
                                params=[('opt_fields',
                                         'budget,procuringEntity')])
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(
            set(response.json['data'][0]),
            set([u'id', u'dateModified', u'budget', u'procuringEntity']))
        self.assertIn('opt_fields=budget%2CprocuringEntity',
                      response.json['next_page']['uri'])

        response = self.app.get('/plans?feed=changes&descending=1')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]),
                         set([u'id', u'dateModified']))
        self.assertEqual(set([i['id'] for i in response.json['data']]),
                         set([i['id'] for i in plans]))
        self.assertEqual([i['dateModified'] for i in response.json['data']],
                         sorted([i['dateModified'] for i in plans],
                                reverse=True))

        response = self.app.get('/plans?feed=changes&descending=1&limit=2')
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 2)

        response = self.app.get(response.json['next_page']['path'].replace(
            ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get(response.json['next_page']['path'].replace(
            ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 0)

        test_plan_data2 = test_plan_data.copy()
        test_plan_data2['mode'] = 'test'
        response = self.app.post_json('/plans', {'data': test_plan_data2})
        self.assertEqual(response.status, '201 Created')
        self.assertEqual(response.content_type, 'application/json')

        while True:
            response = self.app.get('/plans?mode=test')
            self.assertEqual(response.status, '200 OK')
            if len(response.json['data']) == 1:
                break
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get('/plans?feed=changes&mode=_all_')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 4)
예제 #4
0
    create_plan_with_breakdown_other_title,
    fail_create_plan_with_breakdown_other_title,
    fail_create_plan_with_diff_breakdown_currencies,
    fail_create_plan_with_amounts_sum_greater,
    # PlanResourceBeforeBudgetPeriodTest
    create_plan_budget_year,
    patch_plan_budget_year,
    # Plan Buyers
    create_plan_without_buyers,
    fail_create_plan_without_buyers,
    create_plan_with_buyers,
    create_plan_with_two_buyers,
    create_plan_with_breakdown_required,
    create_plan_with_breakdown_not_required)

test_plan_data_mode_test = test_plan_data.copy()
test_plan_data_mode_test["mode"] = "test"

test_data_with_year = deepcopy(test_plan_data)
test_data_with_year["budget"]["year"] = 2018
del test_data_with_year["budget"]["period"]


class PlanTest(BasePlanTest):
    initial_data = test_plan_data

    test_simple_add_plan = snitch(simple_add_plan)


class AccreditationPlanTest(BasePlanTest):
    initial_data = test_plan_data
    def test_listing(self):
        response = self.app.get("/plans")
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 0)

        plans = []

        for i in range(3):
            offset = get_now().isoformat()
            response = self.app.post_json("/plans", {"data": test_plan_data})
            self.assertEqual(response.status, "201 Created")
            self.assertEqual(response.content_type, "application/json")
            plans.append(response.json["data"])

        response = self.app.get("/plans")
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 3)
        self.assertEqual(set(response.json["data"][0]), set([u"id", u"dateModified"]))
        self.assertEqual(set([i["id"] for i in response.json["data"]]), set([i["id"] for i in plans]))
        self.assertEqual(
            set([i["dateModified"] for i in response.json["data"]]), set([i["dateModified"] for i in plans])
        )
        self.assertEqual([i["dateModified"] for i in response.json["data"]], sorted([i["dateModified"] for i in plans]))

        response = self.app.get("/plans?offset={}".format(offset))
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 1)

        response = self.app.get("/plans?limit=2")
        self.assertEqual(response.status, "200 OK")
        self.assertNotIn("prev_page", response.json)
        self.assertEqual(len(response.json["data"]), 2)

        response = self.app.get(response.json["next_page"]["path"].replace(ROUTE_PREFIX, ""))
        self.assertEqual(response.status, "200 OK")
        self.assertIn("descending=1", response.json["prev_page"]["uri"])
        self.assertEqual(len(response.json["data"]), 1)

        response = self.app.get(response.json["next_page"]["path"].replace(ROUTE_PREFIX, ""))
        self.assertEqual(response.status, "200 OK")
        self.assertIn("descending=1", response.json["prev_page"]["uri"])
        self.assertEqual(len(response.json["data"]), 0)

        response = self.app.get("/plans", params=[("opt_fields", "budget")])
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 3)
        self.assertEqual(set(response.json["data"][0]), set([u"id", u"dateModified", u"budget"]))
        self.assertIn("opt_fields=budget", response.json["next_page"]["uri"])

        response = self.app.get("/plans", params=[("opt_fields", "budget,procuringEntity")])
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 3)
        self.assertEqual(set(response.json["data"][0]), set([u"id", u"dateModified", u"budget", u"procuringEntity"]))
        self.assertIn("opt_fields=budget%2CprocuringEntity", response.json["next_page"]["uri"])

        response = self.app.get("/plans?descending=1")
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(response.content_type, "application/json")
        self.assertEqual(len(response.json["data"]), 3)
        self.assertEqual(set(response.json["data"][0]), set([u"id", u"dateModified"]))
        self.assertEqual(set([i["id"] for i in response.json["data"]]), set([i["id"] for i in plans]))
        self.assertEqual(
            [i["dateModified"] for i in response.json["data"]], sorted([i["dateModified"] for i in plans], reverse=True)
        )

        response = self.app.get("/plans?descending=1&limit=2")
        self.assertEqual(response.status, "200 OK")
        self.assertNotIn("descending=1", response.json["prev_page"]["uri"])
        self.assertEqual(len(response.json["data"]), 2)

        response = self.app.get(response.json["next_page"]["path"].replace(ROUTE_PREFIX, ""))
        self.assertEqual(response.status, "200 OK")
        self.assertNotIn("descending=1", response.json["prev_page"]["uri"])
        self.assertEqual(len(response.json["data"]), 1)

        response = self.app.get(response.json["next_page"]["path"].replace(ROUTE_PREFIX, ""))
        self.assertEqual(response.status, "200 OK")
        self.assertNotIn("descending=1", response.json["prev_page"]["uri"])
        self.assertEqual(len(response.json["data"]), 0)

        test_plan_data2 = test_plan_data.copy()
        test_plan_data2["mode"] = "test"
        response = self.app.post_json("/plans", {"data": test_plan_data2})
        self.assertEqual(response.status, "201 Created")
        self.assertEqual(response.content_type, "application/json")

        response = self.app.get("/plans?mode=test")
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 1)

        response = self.app.get("/plans?mode=_all_")
        self.assertEqual(response.status, "200 OK")
        self.assertEqual(len(response.json["data"]), 4)
예제 #6
0
    def test_listing(self):
        response = self.app.get('/plans')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 0)

        plans = []

        for i in range(3):
            offset = get_now().isoformat()
            response = self.app.post_json('/plans', {'data': test_plan_data})
            self.assertEqual(response.status, '201 Created')
            self.assertEqual(response.content_type, 'application/json')
            plans.append(response.json['data'])

        response = self.app.get('/plans')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified']))
        self.assertEqual(set([i['id'] for i in response.json['data']]), set([i['id'] for i in plans]))
        self.assertEqual(set([i['dateModified'] for i in response.json['data']]), set([i['dateModified'] for i in plans]))
        self.assertEqual([i['dateModified'] for i in response.json['data']], sorted([i['dateModified'] for i in plans]))

        response = self.app.get('/plans?offset={}'.format(offset))
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get('/plans?limit=2')
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('prev_page', response.json)
        self.assertEqual(len(response.json['data']), 2)

        response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 0)

        response = self.app.get('/plans', params=[('opt_fields', 'budget')])
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified', u'budget']))
        self.assertIn('opt_fields=budget', response.json['next_page']['uri'])

        response = self.app.get('/plans', params=[('opt_fields', 'budget,procuringEntity')])
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified', u'budget', u'procuringEntity']))
        self.assertIn('opt_fields=budget%2CprocuringEntity', response.json['next_page']['uri'])

        response = self.app.get('/plans?descending=1')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(len(response.json['data']), 3)
        self.assertEqual(set(response.json['data'][0]), set([u'id', u'dateModified']))
        self.assertEqual(set([i['id'] for i in response.json['data']]), set([i['id'] for i in plans]))
        self.assertEqual([i['dateModified'] for i in response.json['data']], sorted([i['dateModified'] for i in plans], reverse=True))

        response = self.app.get('/plans?descending=1&limit=2')
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 2)

        response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get(response.json['next_page']['path'].replace(ROUTE_PREFIX, ''))
        self.assertEqual(response.status, '200 OK')
        self.assertNotIn('descending=1', response.json['prev_page']['uri'])
        self.assertEqual(len(response.json['data']), 0)

        test_plan_data2 = test_plan_data.copy()
        test_plan_data2['mode'] = 'test'
        response = self.app.post_json('/plans', {'data': test_plan_data2})
        self.assertEqual(response.status, '201 Created')
        self.assertEqual(response.content_type, 'application/json')

        response = self.app.get('/plans?mode=test')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 1)

        response = self.app.get('/plans?mode=_all_')
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(len(response.json['data']), 4)