Пример #1
0
 def test_geocode_accounts_valid(self, test_verify_address):
     test_verify_address.return_value = {
         "address_1": DUMMY_ACCT_INFO_1['address']['street'],
         "address_2": "",
         "city": DUMMY_ACCT_INFO_1['address']['city'],
         "state": DUMMY_ACCT_INFO_1['address']['state'],
         "postal": DUMMY_ACCT_INFO_1['address']['post_code'],
         "country": DUMMY_ACCT_INFO_1['address']['country_code'],
         "latitude": RESULT_LAT,
         "longitude": RESULT_LONG,
         "valid": True
     }
     with Transaction() as t:
         ar = AccountRepo(t)
         acct_1 = Account.from_dict(DUMMY_ACCT_INFO_1,
                                    ACCT_MOCK_ISS_1,
                                    ACCT_MOCK_SUB_1)
         ar.create_account(acct_1)
         ar.geocode_accounts()
         with t.dict_cursor() as cur:
             cur.execute("SELECT latitude, longitude, address_verified, "
                         "cannot_geocode FROM ag.account "
                         "WHERE id = %s",
                         (ACCT_ID_1,))
             r = cur.fetchone()
             self.assertAlmostEqual(r['latitude'], RESULT_LAT, 9)
             self.assertAlmostEqual(r['longitude'], RESULT_LONG, 9)
             self.assertTrue(r['address_verified'])
             self.assertFalse(r['cannot_geocode'])
def setup_test_data():
    teardown_test_data()

    with Transaction() as t:
        acct_repo = AccountRepo(t)

        acc = Account(ACCT_ID_1,
                      "*****@*****.**",
                      "admin",
                      ACCT_MOCK_ISS,
                      ACCT_MOCK_SUB,
                      "Dan",
                      "H",
                      Address(
                          "456 Dan Lane",
                          "Danville",
                          "CA",
                          12345,
                          "US"
                      ),
                      "fakekit",
                      "en_US")
        acct_repo.create_account(acc)

        with t.cursor() as cur:
            cur.execute("UPDATE barcodes.project"
                        " SET is_active = FALSE"
                        " WHERE project_id = 2")
        t.commit()
Пример #3
0
def make_dummies(include_fedex_refs=False):
    dummy_acct_dict = deepcopy(DUMMY_ACCT_INFO_2)
    dummy_acct_dict['id'] = 'dummy_acct_id'
    dummy_acct = Account.from_dict(dummy_acct_dict, "an_iss", "a_sub")
    submitter_name = f"{dummy_acct.first_name} {dummy_acct.last_name}"

    dummy_order_struct = {
        'orderId': DUMMY_DAK_ORDER_ID,
        'articles': [
            {
                'articleCode': '350102',
                'addresses': [
                    {
                        'firstName': 'Jane',
                        'lastName': 'Doe',
                        'address1': '123 Main St',
                        'insertion': 'Apt 2',
                        'address2': '',
                        'postalCode': '92210',
                        'city': 'San Diego',
                        'state': 'CA',
                        'country': 'USA',
                        'countryCode': 'us',
                        'phone': '(858) 555-1212',
                        'companyName': submitter_name
                    },
                    {
                        'firstName': 'Tom',
                        'lastName': 'Thumb',
                        'address1': '29 Side St',
                        'insertion': '',
                        'address2': 'Kew Gardens',
                        'postalCode': 'KG7-448',
                        'city': 'Gananoque',
                        'state': 'Ontario',
                        'country': 'Canada',
                        'countryCode': 'ca',
                        'phone': '(858) 555-1212',
                        'companyName': submitter_name
                    }
                ]
            }
        ],
        'shippingProvider': 'FedEx',
        'shippingType': 'FEDEX_2_DAY',
        'shippingProviderMetadata': []
    }

    if include_fedex_refs:
        dummy_order_struct['shippingProviderMetadata'] = [
            {'key': 'Reference 1',
             'value': 'Bill Ted'},
            {'key': 'Reference 2',
             'value': 'Mine'},
            {'key': 'Reference 3',
             'value': 'Yours'}
        ]

    return dummy_order_struct, dummy_acct
def setup_test_data():
    teardown_test_data()

    with Transaction() as t:
        acct_repo = AccountRepo(t)

        acc = Account(ACCT_ID_1, "*****@*****.**", "admin", ACCT_MOCK_ISS,
                      ACCT_MOCK_SUB, "Dan", "H",
                      Address("456 Dan Lane", "Danville", "CA", 12345,
                              "US"), "fakekit")
        acct_repo.create_account(acc)
        t.commit()
Пример #5
0
    def setup_test_data():
        AdminTests.teardown_test_data()

        with Transaction() as t:
            acct_repo = AccountRepo(t)

            acc = Account(STANDARD_ACCT_ID,
                          "*****@*****.**",
                          "standard",
                          "https://MOCKUNITTEST.com",
                          "1234ThisIsNotARealSub",
                          "NotDan",
                          "NotH",
                          Address(
                              "123 Dan Lane",
                              "NotDanville",
                              "CA",
                              12345,
                              "US"
                          ),
                          "fakekit")
            acct_repo.create_account(acc)

            acc = Account(ADMIN_ACCT_ID,
                          "*****@*****.**",
                          "admin",
                          "https://MOCKUNITTEST.com",
                          "5678ThisIsNotARealAdminSub",
                          "Dan",
                          "H",
                          Address(
                              "456 Dan Lane",
                              "Danville",
                              "CA",
                              12345,
                              "US"
                          ),
                          "fakekit")
            acct_repo.create_account(acc)
            t.commit()
def make_dummies(include_fedex_refs=False, include_planned_send_date=False):
    dummy_acct_dict = deepcopy(DUMMY_ACCT_INFO_2)
    dummy_acct_dict['id'] = 'dummy_acct_id'
    dummy_acct = Account.from_dict(dummy_acct_dict, "an_iss", "a_sub")
    submitter_name = f"{dummy_acct.first_name} {dummy_acct.last_name}"

    dummy_order_struct = {
        'orderId': DUMMY_DAK_ORDER_ID,
        'articles': [{
            'articleCode': '350102',
            'quantity': '2'
        }],
        'address': {
            'firstName': 'Jane',
            'lastName': 'Doe',
            'address1': '123 Main St',
            'insertion': 'Apt 2',
            'address2': '',
            'postalCode': '92210',
            'city': 'San Diego',
            'state': 'CA',
            'country': 'USA',
            'countryCode': 'us',
            'phone': '(858) 555-1212',
            'companyName': submitter_name
        },
        "plannedSendDate": "",
        'shippingProvider': DUMMY_SHIPPING_PROVIDER,
        'shippingType': DUMMY_SHIPPING_TYPE,
        'shippingProviderMetadata': []
    }

    if include_fedex_refs:
        dummy_order_struct['shippingProviderMetadata'] = [{
            'key': 'Reference 1',
            'value': 'Bill Ted'
        }, {
            'key': 'Reference 2',
            'value': 'Mine'
        }, {
            'key': 'Reference 3',
            'value': 'Yours'
        }]

    if include_planned_send_date:
        dummy_order_struct['plannedSendDate'] = DUMMY_PLANNED_SEND_DATE

    return dummy_order_struct, dummy_acct
Пример #7
0
def _create_dummy_acct_from_t(t,
                              create_dummy_1=True,
                              iss=ACCT_MOCK_ISS,
                              sub=ACCT_MOCK_SUB):
    if create_dummy_1:
        dummy_acct_id = ACCT_ID_1
        dict_to_copy = DUMMY_ACCT_INFO
    else:
        dummy_acct_id = ACCT_ID_2
        dict_to_copy = DUMMY_ACCT_INFO_2

    input_obj = copy.deepcopy(dict_to_copy)
    input_obj["id"] = dummy_acct_id
    acct_repo = AccountRepo(t)
    acct_repo.create_account(Account.from_dict(input_obj, iss, sub))

    return dummy_acct_id
Пример #8
0
def register_account(body, token_info):
    # First register with AuthRocket, then come here to make the account
    new_acct_id = str(uuid.uuid4())
    body["id"] = new_acct_id
    # Account.from_dict requires a kit_name, even if blank
    kit_name = body.get("kit_name", "")
    body["kit_name"] = kit_name
    code = body.get("code", "")
    body["code"] = code

    account_obj = Account.from_dict(body, token_info[JWT_ISS_CLAIM_KEY],
                                    token_info[JWT_SUB_CLAIM_KEY])

    if kit_name == "" and code == "":
        return jsonify(code=400,
                       message="Account registration requires "
                       "valid kit ID or activation code"), 400

    with Transaction() as t:
        activation_repo = ActivationRepo(t)
        if code != "":
            can_activate, cause = activation_repo.can_activate_with_cause(
                body["email"], code)
            if not can_activate:
                return jsonify(code=404, message=cause), 404
            else:
                activation_repo.use_activation_code(body["email"], code)

        if kit_name != "":
            kit_repo = KitRepo(t)
            kit = kit_repo.get_kit_all_samples(kit_name)
            if kit is None:
                return jsonify(code=404, message="Kit name not found"), 404

        acct_repo = AccountRepo(t)
        acct_repo.create_account(account_obj)
        new_acct = acct_repo.get_account(new_acct_id)
        t.commit()

    response = jsonify(new_acct.to_api())
    response.status_code = 201
    response.headers['Location'] = '/api/accounts/%s' % new_acct_id
    return response
Пример #9
0
def register_account(body, token_info):
    # First register with AuthRocket, then come here to make the account
    new_acct_id = str(uuid.uuid4())
    body["id"] = new_acct_id
    account_obj = Account.from_dict(body, token_info[JWT_ISS_CLAIM_KEY],
                                    token_info[JWT_SUB_CLAIM_KEY])

    with Transaction() as t:
        kit_repo = KitRepo(t)
        kit = kit_repo.get_kit_all_samples(body['kit_name'])
        if kit is None:
            return jsonify(code=404, message="Kit name not found"), 404

        acct_repo = AccountRepo(t)
        acct_repo.create_account(account_obj)
        new_acct = acct_repo.get_account(new_acct_id)
        t.commit()

    response = jsonify(new_acct.to_api())
    response.status_code = 201
    response.headers['Location'] = '/api/accounts/%s' % new_acct_id
    return response
Пример #10
0
 def _row_to_account(r):
     return Account(r['id'], r['email'], r['account_type'],
                    r['auth_issuer'], r['auth_sub'],
                    r['first_name'], r['last_name'],
                    AccountRepo._row_to_addr(r), r['created_with_kit_id'],
                    r['creation_time'], r['update_time'])