예제 #1
0
 def setup_class(cls, mocked_auth):
     cls.port = free_port()
     start_server(cls.port, locations=cls.locations)
     cls.company = Company(
         name="Any company",
         code="Cpny",
         employees=[
             Employee(username="******",
                      password="******",
                      first_name="Richard",
                      last_name="Myers",
                      phone_number="112233",
                      user_status="U",
                      birth_date=datetime.datetime.utcnow(),
                      pin_code=4567,
                      email="*****@*****.**",
                      account_status="A",
                      registration_date=datetime.datetime(2019, 1, 1))
         ],
         locations=[
             Location(id=40,
                      name="Tapper",
                      code="T",
                      company_id=50,
                      poster_id=2,
                      country="United States",
                      region="Nay",
                      city="South",
                      type="L",
                      address="Delta Park, 145",
                      longitude=640,
                      latitude=480,
                      status="open",
                      synchronized_on=datetime.datetime(1983, 5, 10)),
             Location(id=150,
                      name="Hard Rock",
                      code="H",
                      company_id=50,
                      poster_id=10,
                      country="United States",
                      region="Manhattan",
                      city="New York",
                      type="C",
                      address="5th Avenue 145",
                      longitude=1024,
                      latitude=720,
                      status="open",
                      synchronized_on=datetime.datetime(1983, 5, 10))
         ])
     access_token = Authenticated(
         PosterAuthData(
             application_id="test_application_id",
             application_secret="test_application_secret",
             redirect_uri="test_redirect_uri",
             code="test_code",
         ))
     cls.poster_sync = PosterSync
     cls.poster = Poster(url="http://localhost:{port}".format(
         port=cls.port))
예제 #2
0
def test_cannot_access_tables_from_other_locations(app, db_session):
    """User with Location Admin role cannot access the tables
    from a Location which is not owned by the company they work at"""
    company = Company(id=1, name="Foo Inc.", code="code1", address="addr")
    other = Company(id=2, name="Other Foo Inc.", code="code2", address="addr2")
    location = Location(id=1,
                        name="name",
                        code="123",
                        company_id=other.id,
                        country="US",
                        region="region",
                        city="city",
                        address="address",
                        longitude="123",
                        latitude="123",
                        type="type",
                        status="status")
    floor = Floor(id=1, description="1st Floor", location_id=location.id)
    shape = TableShape(id=1,
                       description="Round Table",
                       picture="/path/to/file.jpg")
    table = Table(id=1,
                  name="some table",
                  floor_id=floor.id,
                  x=40,
                  y=50,
                  width=320,
                  height=150,
                  status=1,
                  max_capacity=12,
                  multiple=False,
                  playstation=False,
                  shape_id=1)
    db_session.add(company)
    db_session.add(other)
    db_session.add(location)
    db_session.add(floor)
    db_session.add(shape)
    db_session.commit()
    db_session.add(table)
    user = Employee(id=1,
                    first_name="Alice",
                    last_name="Cooper",
                    username="******",
                    phone_number="1",
                    birth_date=datetime.utcnow(),
                    pin_code=3333,
                    account_status="on",
                    user_status="on",
                    registration_date=datetime.utcnow(),
                    company_id=company.id,
                    email="*****@*****.**",
                    password="******")
    flask.g.user = user
    db_session.add(user)
    db_session.commit()
    assert not has_privilege(
        method=Method.READ, resource="tables", id=table.id)
def test_sync_location(db_session):
    port = free_port()
    start_server(port,
                 locations=[{
                     "id": 100,
                     "name": "Coco Bongo",
                     "code": "C",
                     "company_id": 50,
                     "country": "United States",
                     "region": "East Coast",
                     "city": "Edge City",
                     "address": "Blvd. Kukulcan Km 9.5 #30, Plaza Forum",
                     "longitude": 21.1326063,
                     "latitude": -86.7473191,
                     "type": "L",
                     "status": "open",
                     "comment": "Nightclub from a famous movie"
                 }])
    company = Company(id=50,
                      name="Company of Heroes",
                      code="Cpny",
                      address="Somewhere in the bermuda triangle")
    db_session.add(company)
    db_session.commit()
    location = Location(id=100,
                        name="Coconut Bongolive",
                        code="C",
                        company_id=50,
                        country="United States of America",
                        region="West Coast",
                        city="Another city",
                        address="Some address in Another City",
                        longitude=42.2642026,
                        latitude=-172.148146,
                        type="L",
                        status="closed",
                        comment="A location with ")
    db_session.add(location)
    db_session.commit()
    SyncedLocation(
        location=location,
        poster_sync=Poster(url="http://localhost:{port}".format(port=port)),
        db_session=db_session).sync()
    row = Location.query.filter_by(id=location.id).one()
    assert row.id == 100
    assert row.name == "Coco Bongo"
    assert row.code == "C"
    assert row.company_id == 50
    assert row.country == "United States"
    assert row.region == "East Coast"
    assert row.city == "Edge City"
    assert row.address == "Blvd. Kukulcan Km 9.5 #30, Plaza Forum"
    assert row.longitude == 21.1326063
    assert row.latitude == -86.7473191
    assert row.type == "L"
    assert row.status == "open"
    assert row.comment == "Nightclub from a famous movie"
예제 #4
0
def _create_test_location():
    return Location(name="Test location",
                    code="1",
                    country="USA",
                    region="West",
                    city="LA",
                    type="Type",
                    address="Address",
                    longitude="11223344",
                    latitude="44332211",
                    status="T")
예제 #5
0
 def setup_class(cls, mocked_auth):
     cls.port = free_port()
     start_server(cls.port, locations=cls.locations)
     cls.company = Company(
         name="Any company",
         code="Cpny",
         employees=[
             Employee(username="******",
                      password="******",
                      first_name="Richard",
                      last_name="Myers",
                      phone_number="112233",
                      birth_date=datetime.datetime.utcnow(),
                      pin_code=4567,
                      email="*****@*****.**")
         ],
         locations=[
             Location(id=40,
                      name="Tapper",
                      code="T",
                      company_id=50,
                      poster_id=2,
                      synchronized_on=datetime.datetime(1983, 5, 10)),
             Location(id=150,
                      name="Hard Rock",
                      code="H",
                      company_id=50,
                      poster_id=10,
                      synchronized_on=datetime.datetime(1983, 5, 10))
         ])
     access_token = Authenticated(
         PosterAuthData(
             application_id="test_application_id",
             application_secret="test_application_secret",
             redirect_uri="test_redirect_uri",
             code="test_code",
         ))
     cls.poster_sync = PosterSync
     cls.poster = Poster(url="http://localhost:{port}".format(
         port=cls.port))
예제 #6
0
def test_can_not_manage_locations_from_different_company(
        clean_app, db_session):
    my_company = Company(id=1, name="Foo Inc.", code="code1", address="addr")
    db_session.add(my_company)
    me = Employee(id=1,
                  first_name="Bob",
                  last_name="Cooper",
                  username="******",
                  phone_number="1",
                  birth_date=datetime.utcnow(),
                  pin_code=1111,
                  account_status="on",
                  user_status="on",
                  registration_date=datetime.utcnow(),
                  company_id=my_company.id,
                  email="*****@*****.**",
                  password="******")
    db_session.add(me)
    flask.g.user = me
    other_company = Company(id=2,
                            name="Bar Inc.",
                            code="code2",
                            address="addr")
    db_session.add(other_company)
    location = Location(name="name",
                        code="123",
                        company_id=other_company.id,
                        country="US",
                        region="region",
                        city="city",
                        address="address",
                        longitude="123",
                        latitude="123",
                        type="type",
                        status="status")
    db_session.add(location)
    db_session.commit()
    assert not has_privilege(
        method=Method.READ, resource="location", id=location.id)
    assert not has_privilege(
        method=Method.CREATE, resource="location", id=location.id)
    assert not has_privilege(
        method=Method.UPDATE, resource="location", id=location.id)
    assert not has_privilege(
        method=Method.DELETE, resource="location", id=location.id)
예제 #7
0
def test_new_location():
    name = "Test location"
    code = "L"
    country = "Country"
    region = "Region"
    city = "City"
    type = "Type"
    address = "Address"
    longitude = "11223344"
    latitude = "44332211"
    status = "T"
    company_id = 123
    poster_id = 100
    synchronized_on = datetime.utcnow
    working_hours = 1
    closed_days = 2
    new_location = Location(name=name,
                            code=code,
                            company_id=company_id,
                            poster_id=poster_id,
                            country=country,
                            region=region,
                            city=city,
                            type=type,
                            address=address,
                            longitude=longitude,
                            latitude=latitude,
                            status=status,
                            synchronized_on=synchronized_on,
                            working_hours=working_hours,
                            closed_days=closed_days)
    assert (new_location.name == name and new_location.code == code
            and new_location.company_id == company_id
            and new_location.poster_id == 100
            and new_location.synchronized_on == synchronized_on
            and new_location.working_hours == working_hours
            and new_location.closed_days == closed_days
            and new_location.country == country
            and new_location.region == region and new_location.city == city
            and new_location.type == type and new_location.address == address
            and new_location.longitude == longitude
            and new_location.latitude == latitude
            and new_location.status == status)
예제 #8
0
 def sync_location(poster, company):
     synced = []
     for location in company.locations:
         for poster_location in poster.locations():
             if location.id == poster_location["id"]:
                 synced.append(
                     Location(id=location.id,
                              name=poster_location["name"],
                              code=poster_location["code"],
                              company_id=location.company_id,
                              country=poster_location["country"],
                              region=poster_location["region"],
                              city=poster_location["city"],
                              address=poster_location["address"],
                              longitude=poster_location["longitude"],
                              latitude=poster_location["latitude"],
                              type=poster_location["type"],
                              status=poster_location["status"],
                              comment=poster_location["comment"]))
     company.locations = synced
예제 #9
0
def test_new_location():
    name = "Test location"
    code = "L"
    company_id = 123
    poster_id = 100
    synchronized_on = datetime.utcnow
    working_hours = SchemeType()
    closed_days = SchemeType()

    new_location = Location(name=name,
                            code=code,
                            company_id=company_id,
                            poster_id=poster_id,
                            synchronized_on=synchronized_on,
                            working_hours=working_hours.id,
                            closed_days=closed_days.id)
    assert (new_location.name == name and new_location.code == code
            and new_location.company_id == company_id
            and new_location.poster_id == 100
            and new_location.synchronized_on == synchronized_on
            and new_location.working_hours == working_hours.id
            and new_location.closed_days == closed_days.id)
예제 #10
0
def create_location(db_session):
    company = Company(
        name="Krusty Inc.",
        code="KI",
        address="Springfield Lane,12"
    )
    location =  Location(
        name="Krusty Burger",
        code="KB",
        company_id=company.id,
        country="United States",
        region="Middle East",
        city="Springfield",
        address="Jebediah Street, NN",
        longitude=23,
        latitude=25,
        type="B",
        status="open",
        comment="Fast food restaurant from a famous animated sitcom."
    )
    db_session.add(company)
    db_session.add(location)
    db_session.commit()
    return location